private AsyncInterceptorChain newInterceptorChain(AsyncInterceptor... interceptors) { ComponentMetadataRepo componentMetadataRepo = new ComponentMetadataRepo(); componentMetadataRepo.initialize(Collections.emptyList(), InterceptorChainTest.class.getClassLoader()); AsyncInterceptorChain chain = new AsyncInterceptorChainImpl(componentMetadataRepo); for (AsyncInterceptor i : interceptors) { chain.appendInterceptor(i, false); } return chain; } }
@BeforeMethod(alwaysRun = true) public void setup() { metadataRepo = new ComponentMetadataRepo(); ClassLoader classLoader = this.getClass().getClassLoader(); metadataRepo.initialize(ModuleProperties.getModuleMetadataFiles(classLoader), classLoader); globalRegistry = new BasicComponentRegistryImpl(classLoader, metadataRepo, Scopes.GLOBAL, null); cacheRegistry = new BasicComponentRegistryImpl(classLoader, metadataRepo, Scopes.NAMED_CACHE, globalRegistry); }
public void testConcurrentAddRemove() throws Exception { ComponentMetadataRepo componentMetadataRepo = new ComponentMetadataRepo(); componentMetadataRepo.initialize(Collections.emptyList(), AsyncInterceptorChainTest.class.getClassLoader()); AsyncInterceptorChainImpl ic = new AsyncInterceptorChainImpl(componentMetadataRepo); ic.addInterceptor(new DummyCallInterceptor(), 0);
public void testConcurrentAddRemove() throws Exception { ComponentMetadataRepo componentMetadataRepo = new ComponentMetadataRepo(); componentMetadataRepo.initialize(Collections.emptyList(), InterceptorChainTest.class.getClassLoader()); AsyncInterceptorChainImpl asyncInterceptorChain = new AsyncInterceptorChainImpl(componentMetadataRepo); GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder().build(); InterceptorChain ic = new InterceptorChain(); TestingUtil.inject(ic, asyncInterceptorChain); ic.setFirstInChain(new DummyCallInterceptor()); ic.addInterceptor(new DummyActivationInterceptor(), 1); CyclicBarrier barrier = new CyclicBarrier(4); List<Future<Void>> futures = new ArrayList<Future<Void>>(2); // We do test concurrent add/remove of different types per thread, // so that the final result is predictable (testable) and that we // can not possibly fail because of the InterceptorChain checking // that no interceptor is ever added twice. futures.add(fork(new InterceptorChainUpdater(ic, barrier, new DummyCacheMgmtInterceptor()))); futures.add(fork(new InterceptorChainUpdater(ic, barrier, new DummyDistCacheWriterInterceptor()))); futures.add(fork(new InterceptorChainUpdater(ic, barrier, new DummyInvalidationInterceptor()))); barrier.await(); // wait for all threads to be ready barrier.await(); // wait for all threads to finish log.debug("All threads finished, let's shutdown the executor and check whether any exceptions were reported"); for (Future<Void> future : futures) future.get(); assert ic.containsInterceptorType(DummyCallInterceptor.class); assert ic.containsInterceptorType(DummyActivationInterceptor.class); assert ic.containsInterceptorType(DummyCacheMgmtInterceptor.class); assert ic.containsInterceptorType(DummyDistCacheWriterInterceptor.class); assert ic.containsInterceptorType(DummyInvalidationInterceptor.class); assert ic.asList().size() == 5 : "Resulting interceptor chain was actually " + ic.asList(); }