package org.infinispan; import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.test.SingleCacheManagerTest; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; /** * // TODO: Document this * * @author Galder Zamarre–o * @since // TODO */ @Test(groups = "functional", testName = "ConcurrentCacheStartupTest") public class ConcurrentCacheStartupTest extends SingleCacheManagerTest { @Override protected EmbeddedCacheManager createCacheManager() throws Exception { return new DefaultCacheManager(); } public void test000() throws Exception { int numThreads = 25; final CyclicBarrier barrier = new CyclicBarrier(numThreads +1); List> futures = new ArrayList>(numThreads); ExecutorService executorService = Executors.newCachedThreadPool(); for (int i = 0; i < numThreads; i++) { log.debug("Schedule execution"); Future future = executorService.submit(new Callable(){ @Override public Void call() throws Exception { try { barrier.await(); cacheManager.getCache("blahblah").put("a", "b"); return null; } finally { log.debug("Wait for all execution paths to finish"); barrier.await(); } } }); futures.add(future); } 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 future : futures) future.get(); } }