1 7 8 package org.jboss.cache.eviction; 9 10 import junit.framework.Test; 11 import junit.framework.TestCase; 12 import junit.framework.TestSuite; 13 import org.jboss.cache.CacheImpl; 14 import org.jboss.cache.Fqn; 15 import org.jboss.cache.factories.XmlConfigurationParser; 16 import org.jboss.cache.misc.TestingUtil; 17 18 24 public class ConcurrentEvictionTest extends TestCase 25 { 26 private CacheImpl cache_; 27 private int wakeupIntervalMillis_ = 0; 28 29 public ConcurrentEvictionTest(String s) 30 { 31 super(s); 32 } 33 34 protected void setUp() throws Exception 35 { 36 super.setUp(); 37 initCaches(); 38 wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000; 39 if (wakeupIntervalMillis_ < 0) 40 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_); 41 42 } 43 44 void initCaches() throws Exception 45 { 46 TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader"); 47 cache_ = new CacheImpl(); 48 cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-eviction-cacheloader-service.xml")); cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 50 cache_.start(); 51 } 52 53 public void tearDown() throws Exception 54 { 55 super.tearDown(); 56 TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader"); 57 cache_.stop(); 58 cache_ = null; 59 } 60 61 public void testConcurrentEviction() throws Exception 62 { 63 Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/eviction"); 64 65 for (int i = 0; i < 1000; i++) 68 { 69 cache_.put(new Fqn(base, i / 100), new Integer (i), "value"); 70 } 71 72 long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_); 74 while (System.currentTimeMillis() < loopDone) 75 { 76 for (int i = 0; i < 1000; i++) 78 { 79 Fqn fqn = new Fqn(base, i / 100); 80 Integer key = i; 81 assertNotNull("found value under Fqn " + fqn + " and key " + key, 82 cache_.get(fqn, key)); 83 } 84 } 85 } 86 87 public static Test suite() 88 { 89 return new TestSuite(ConcurrentEvictionTest.class); 90 } 91 } 92 | Popular Tags |