package org.infinispan.eviction; import org.infinispan.config.Configuration; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.test.SingleCacheManagerTest; import org.infinispan.test.TestingUtil; import org.infinispan.test.fwk.TestCacheManagerFactory; import org.testng.annotations.Test; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; /** * // TODO: Document this * * @author Galder ZamarreƱo * @since // TODO */ @Test(groups = "functional", testName = "eviction.MultiEvictionCacheTest") public class MultiEvictionCacheTest extends SingleCacheManagerTest { @Override protected EmbeddedCacheManager createCacheManager() throws Exception { return TestCacheManagerFactory.createLocalCacheManager(); } public void testDefineMultipleCachesWithEviction() { for (int i = 0; i < 50; i++) { Configuration cfg = new Configuration(); cfg.setEvictionStrategy(EvictionStrategy.LIRS); cfg.setEvictionWakeUpInterval(100); cfg.setEvictionMaxEntries(128); // 128 max entries cfg.setUseLockStriping(false); // to minimize chances of deadlock in the unit test String cacheName = Integer.toString(i); cacheManager.defineConfiguration(cacheName, cfg); cacheManager.getCache(cacheName); } ThreadMXBean threadMBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threadInfos = threadMBean.dumpAllThreads(false, false); String pattern = "Scheduled-eviction-thread-"; int evictionThreadCount = 0; for (ThreadInfo threadInfo : threadInfos) { if (threadInfo.getThreadName().startsWith(pattern)) evictionThreadCount++; } assert evictionThreadCount == 1 : "Thread should only be one eviction thread, instead there were " + evictionThreadCount; } }