apache / incubator-hugegraph-commons

HugeGraph Commons - include common library & RPC module
https://hugegraph.apache.org/
Apache License 2.0
29 stars 45 forks source link

[Bug] PerfUtilTest fail using mvn clean package #142

Open sheli00 opened 4 months ago

sheli00 commented 4 months ago

Bug Type (问题类型)

exception / error (异常报错)

Before submit

Environment (环境信息)

Expected & Actual behavior (期望与实际表现)

mvn test -Dtest=UnitTestSuite pass all tests, however PerfUtilTest fail using mvn clean package.

[INFO] Running org.apache.hugegraph.unit.perf.PerfUtilTest
[ERROR] Tests run: 9, Failures: 0, Errors: 6, Skipped: 0, Time elapsed: 0.148 s <<< FAILURE! - in org.apache.hugegraph.unit.perf.PerfUtilTest
[ERROR] testPerfUtilPerf4LightStopwatch(org.apache.hugegraph.unit.perf.PerfUtilTest)  Time elapsed: 0.081 s  <<< ERROR!
javassist.CannotCompileException: by java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilPerf4LightStopwatch(PerfUtilTest.java:395)
Caused by: java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilPerf4LightStopwatch(PerfUtilTest.java:395)
Caused by: java.lang.LinkageError: loader 'app' attempted duplicate class definition for org.apache.hugegraph.unit.perf.testclass.TestPerfLightClass. (org.apache.hugegraph.unit.perf.testclass.TestPerfLightClass is in unnamed module of loader 'app')
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilPerf4LightStopwatch(PerfUtilTest.java:395)

[ERROR] testPerfUtilWithProfileParentClass(org.apache.hugegraph.unit.perf.PerfUtilTest)  Time elapsed: 0.001 s  <<< ERROR!
javassist.CannotCompileException: by java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithProfileParentClass(PerfUtilTest.java:288)
Caused by: java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithProfileParentClass(PerfUtilTest.java:288)
Caused by: java.lang.LinkageError: loader 'app' attempted duplicate class definition for org.apache.hugegraph.unit.perf.testclass.TestClass$Base. (org.apache.hugegraph.unit.perf.testclass.TestClass$Base is in unnamed module of loader 'app')
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithProfileParentClass(PerfUtilTest.java:288)

[ERROR] testPerfUtil(org.apache.hugegraph.unit.perf.PerfUtilTest)  Time elapsed: 0.001 s  <<< ERROR!
javassist.CannotCompileException: by java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtil(PerfUtilTest.java:49)
Caused by: java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtil(PerfUtilTest.java:49)
Caused by: java.lang.LinkageError: loader 'app' attempted duplicate class definition for org.apache.hugegraph.unit.perf.testclass.TestClass$Foo. (org.apache.hugegraph.unit.perf.testclass.TestClass$Foo is in unnamed module of loader 'app')
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtil(PerfUtilTest.java:49)

[ERROR] testPerfUtilWithSingleThread(org.apache.hugegraph.unit.perf.PerfUtilTest)  Time elapsed: 0.002 s  <<< ERROR!
javassist.CannotCompileException: by java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithSingleThread(PerfUtilTest.java:215)
Caused by: java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithSingleThread(PerfUtilTest.java:215)
Caused by: java.lang.LinkageError: loader 'app' attempted duplicate class definition for org.apache.hugegraph.unit.perf.testclass.TestClass$Bar. (org.apache.hugegraph.unit.perf.testclass.TestClass$Bar is in unnamed module of loader 'app')
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithSingleThread(PerfUtilTest.java:215)

[ERROR] testPerfUtilPerf(org.apache.hugegraph.unit.perf.PerfUtilTest)  Time elapsed: 0.003 s  <<< ERROR!
javassist.CannotCompileException: by java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilPerf(PerfUtilTest.java:352)
Caused by: java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilPerf(PerfUtilTest.java:352)
Caused by: java.lang.LinkageError: loader 'app' attempted duplicate class definition for org.apache.hugegraph.unit.perf.testclass.TestPerfClass. (org.apache.hugegraph.unit.perf.testclass.TestPerfClass is in unnamed module of loader 'app')
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilPerf(PerfUtilTest.java:352)

[ERROR] testPerfUtilWithProfilePackage(org.apache.hugegraph.unit.perf.PerfUtilTest)  Time elapsed: 0.029 s  <<< ERROR!
javassist.CannotCompileException: by java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithProfilePackage(PerfUtilTest.java:253)
Caused by: java.lang.reflect.InvocationTargetException
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithProfilePackage(PerfUtilTest.java:253)
Caused by: java.lang.LinkageError: loader 'app' attempted duplicate class definition for org.apache.hugegraph.unit.perf.testclass2.TestClass4Package. (org.apache.hugegraph.unit.perf.testclass2.TestClass4Package is in unnamed module of loader 'app')
        at org.apache.hugegraph.unit.perf.PerfUtilTest.testPerfUtilWithProfilePackage(PerfUtilTest.java:253)

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

dosubot[bot] commented 4 months ago

To resolve the PerfUtilTest failure caused by javassist.CannotCompileException errors due to a java.lang.LinkageError indicating a duplicate class definition issue when running the mvn clean package command, you should consider the following steps:

  1. Check for Duplicate Dependencies: The error suggests there might be duplicate class definitions, which often occur due to conflicting versions of the same dependency included in the project. Review your pom.xml for any duplicate dependencies or versions that might lead to this issue. In your provided pom.xml, ensure that dependencies like javassist are not indirectly included by another dependency at a different version.

  2. Examine Class Loaders: If your project involves custom class loaders, ensure they are correctly handling class definitions. The javassist.CannotCompileException can occur if a class is loaded by more than one class loader in an incompatible manner.

  3. Isolate the Test: Since the issue occurs during a specific test (PerfUtilTest), isolate this test and run it independently to confirm if the issue is localized to this test. This can help in narrowing down the scope of the problem.

  4. Review javassist Usage: Given that the error is related to javassist, review how javassist is used within your tests or application. Ensure that you are not accidentally creating duplicate class definitions through javassist's APIs.

  5. Update Dependencies: Ensure all your dependencies are up to date, especially javassist. Sometimes, such issues are resolved in newer versions of libraries. Your pom.xml uses property placeholders for versions (like ${javassist.version}), so make sure these properties are defined with the latest stable versions.

  6. Maven Dependency Tree: Use mvn dependency:tree to analyze your project's dependency tree. Look for any instances of multiple versions of the same dependency or any other anomalies that could lead to classpath issues.

  7. Classpath Scanning: Tools or frameworks that scan the classpath at runtime (for example, for annotations) might inadvertently load classes in a manner that leads to this error. If you're using such tools, review their configurations.

  8. Maven Clean Verify: Before running mvn clean package, try running mvn clean verify to see if the issue persists. This can sometimes give more detailed output about what's going wrong.

If after these steps the issue still persists, consider providing more specific details about how javassist is used in your project and any relevant configurations or code snippets related to PerfUtilTest. This additional information could be crucial in pinpointing the exact cause of the issue.

The PerfUtilTest class in the incubator-hugegraph-commons codebase is designed to test the performance utility functionalities provided by PerfUtil. It includes tests for profiling classes and methods, handling performance data, and ensuring the correct behavior of performance tracking under various conditions such as using light stopwatches, profiling single threads, profiling packages, manually profiling specific methods, and handling nested method calls. The tests validate that PerfUtil correctly records the number of times methods are called, their execution hierarchy, and performance metrics like total cost, min cost, max cost, and wasted time. This ensures that PerfUtil can be reliably used for performance analysis in the HugeGraph project.

The javassist library in the incubator-hugegraph-commons codebase is used for bytecode manipulation, specifically for profiling classes and methods at runtime without modifying the source code. It allows the dynamic insertion of profiling code into methods to measure execution time.

In the provided context, javassist is utilized in the PerfUtil class to profile methods annotated with @Watched. The profileClass method uses javassist to load classes and iterate over their methods. If a method is annotated with @Watched, it modifies the method's bytecode to insert calls to PerfUtil.instance().start("<method_name>") at the beginning of the method and PerfUtil.instance().end("<method_name>") at the end. This allows measuring the execution time of the method.

The profile method specifically manipulates the bytecode of methods using javassist by calling insertBefore and insertAfter on CtMethod objects, which represent the methods of the classes being profiled. This manipulation includes inserting profiling code that calls start and end methods of PerfUtil with the method name or a custom name provided via the @Watched annotation.

This code snippet demonstrates how javassist is used to dynamically insert profiling code into methods, enabling runtime performance analysis without altering the original method implementations.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.