Skip to content

Commit c398a21

Browse files
committed
Add ClasspathManagerTestCase::testUnfoundClassPerformance
Performance regression test for #306, failing before the enhancement and passing afterward. Signed-off-by: Alexander Kriegisch <[email protected]>
1 parent 7d19004 commit c398a21

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

weaver/src/test/java/org/aspectj/weaver/bcel/ClasspathManagerTestCase.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.aspectj.bridge.IMessage.Kind;
2424
import org.aspectj.bridge.IMessageHandler;
2525
import org.aspectj.util.LangUtil;
26+
import org.aspectj.weaver.TypeFactory;
2627
import org.aspectj.weaver.UnresolvedType;
2728
import org.aspectj.weaver.bcel.ClassPathManager.ClassFile;
2829

@@ -76,7 +77,33 @@ private static File walk(File dir, String jar) {
7677
}
7778

7879
public void testInstructions() {
79-
System.out.println("This test is really only for standalone usage as it need executing on multiple JDK levels");
80+
System.out.println(
81+
"This test is mostly for stand-alone usage (rename 'xtest*' to 'test*'), " +
82+
"as it needs execution on multiple JDK levels"
83+
);
84+
}
85+
86+
/**
87+
* See <a href="https://github.com/eclipse-aspectj/aspectj/issues/306">GitHub issue 306</a>
88+
*/
89+
public void testUnfoundClassPerformance() {
90+
final int ROUNDS = 10_000;
91+
final int MAX_TIME = 500;
92+
93+
List<String> classPath = Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator));
94+
//System.out.println(classPath);
95+
ClassPathManager classPathManager = new ClassPathManager(classPath, null);
96+
UnresolvedType unresolvedType = TypeFactory.createTypeFromSignature("Ljava/lang/String;");
97+
98+
long startTime = System.currentTimeMillis();
99+
for (int i = 0; i < ROUNDS; i++)
100+
classPathManager.find(unresolvedType);
101+
long duration = System.currentTimeMillis() - startTime;
102+
103+
assertTrue(
104+
String.format("Duration for %d rounds should be < %d ms, but was %d ms", ROUNDS, MAX_TIME, duration),
105+
duration < MAX_TIME
106+
);
80107
}
81108

82109
public void xtestSanity18accessing18RTJAR() throws IOException {

0 commit comments

Comments
 (0)