public void testCache() throws Exception
{
ClassLoaderSystem system = createBlockingClassLoaderSystem();
NoMatchClassFilter filter = new NoMatchClassFilter(ClassLoaderDomain.class);
ParentPolicy parentPolicy = new ParentPolicy(ClassFilterUtils.JAVA_ONLY, filter);
BlockingClassLoaderDomain domain = (BlockingClassLoaderDomain) system.createAndRegisterDomain("test", parentPolicy, null);
MockClassLoaderPolicy policy = createMockClassLoaderPolicy();
policy.setPathsAndPackageNames(ClassLoaderDomain.class);
final ClassLoader classLoader = system.registerClassLoaderPolicy(domain, policy);
int numThreads = 2;
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
Future<?>[] results = new Future[numThreads];
for(int i = 0; i < results.length; i++)
{
results[i] = executor.submit(new Callable<Void>() {
public Void call() throws Exception
{
assertLoadClass(ClassLoaderDomain.class, classLoader);
return null;
}
});
}
executor.shutdown();
domain.unblock();
executor.awaitTermination(5, TimeUnit.SECONDS);
// no exceptions means a job well done
for(int i = 0; i < results.length; i++)
{
results[i].get(1, TimeUnit.SECONDS);