diff options
author | aclement <aclement> | 2006-08-08 11:26:28 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-08-08 11:26:28 +0000 |
commit | 387c3ac6f23a39aebbc4044093c793009dfea8f6 (patch) | |
tree | d1e7d5bfb3796df01bc28fbf6678e70a8026c284 /bcel-builder/testsrc | |
parent | 4f3c86ded09ce6407d51ab6ca98fac6ed16f8e59 (diff) | |
download | aspectj-387c3ac6f23a39aebbc4044093c793009dfea8f6.tar.gz aspectj-387c3ac6f23a39aebbc4044093c793009dfea8f6.zip |
152979: shared cache in the repositorypre_pr_153572
Diffstat (limited to 'bcel-builder/testsrc')
-rw-r--r-- | bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java | 1 | ||||
-rw-r--r-- | bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassloaderRepositoryTest.java | 67 |
2 files changed, 68 insertions, 0 deletions
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java index 87ed85774..da406e725 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java @@ -38,6 +38,7 @@ public class AllTests { suite.addTestSuite(EnclosingMethodAttributeTest.class); suite.addTestSuite(MethodAnnotationsTest.class); suite.addTestSuite(RuntimeVisibleAnnotationAttributeTest.class); + suite.addTestSuite(ClassloaderRepositoryTest.class); suite.addTestSuite(EnumAccessFlagTest.class); suite.addTestSuite(LocalVariableTypeTableTest.class); suite.addTestSuite(VarargsTest.class); diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassloaderRepositoryTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassloaderRepositoryTest.java new file mode 100644 index 000000000..d9e0d6d58 --- /dev/null +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassloaderRepositoryTest.java @@ -0,0 +1,67 @@ +package org.aspectj.apache.bcel.classfile.tests; + +import java.net.URL; +import java.net.URLClassLoader; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.util.ClassLoaderRepository; + +import junit.framework.TestCase; + +/* + * Tests create a simple classloader repository configuration and check sharing of information. + */ +public class ClassloaderRepositoryTest extends TestCase { + + private ClassLoaderRepository rep1,rep2; + + public void setUp() throws Exception { + super.setUp(); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + ClassLoader cl1 = new URLClassLoader(new URL[]{},cl); + ClassLoader cl2 = new URLClassLoader(new URL[]{},cl); + rep1 = new ClassLoaderRepository(cl1); + rep2 = new ClassLoaderRepository(cl2); + } + + // Retrieve string 5 times from same repository, 4 hits should be from local cache + public void testLocalCacheWorks() throws ClassNotFoundException { + JavaClass jc = rep1.loadClass("java.lang.String"); + jc = rep1.loadClass("java.lang.String"); + jc = rep1.loadClass("java.lang.String"); + jc = rep1.loadClass("java.lang.String"); + jc = rep1.loadClass("java.lang.String"); + assertTrue("Should have used local cache 4 times: "+rep1.reportLocalCacheHits(),rep1.reportLocalCacheHits()==4); + } + + // Retrieve String through one repository then load again through another, should be shared cache hit + public void testSharedCacheWorks() throws ClassNotFoundException { + JavaClass jc = rep1.loadClass("java.lang.String"); + jc = rep2.loadClass("java.lang.String"); + assertTrue("Should have retrieved String from shared cache: "+ClassLoaderRepository.reportSharedCacheHits(), + ClassLoaderRepository.reportSharedCacheHits()==1); + } + + // Shared cache OFF, shouldn't get a shared cache hit + public void testSharedCacheCanBeDeactivated() throws ClassNotFoundException { + try { + ClassLoaderRepository.useSharedCache=false; + JavaClass jc = rep1.loadClass("java.lang.String"); + jc = rep2.loadClass("java.lang.String"); + assertTrue("Should not have retrieved String from shared cache: "+ + ClassLoaderRepository.reportSharedCacheHits(), + ClassLoaderRepository.reportSharedCacheHits()==0); + } finally { + ClassLoaderRepository.useSharedCache=true; + } + } + + public void tearDown() throws Exception { + super.tearDown(); + System.err.println("Rep1: "+rep1.reportAllStatistics()); + System.err.println("Rep2: "+rep2.reportAllStatistics()); + rep1.reset(); + rep2.reset(); + } + +} |