1 package org.jboss.cache.eviction; 2 3 import junit.framework.TestCase; 4 import org.jboss.cache.CacheImpl; 5 import org.jboss.cache.DummyTransactionManagerLookup; 6 import org.jboss.cache.Fqn; 7 import org.jboss.cache.factories.XmlConfigurationParser; 8 import org.jboss.cache.interceptors.EvictionInterceptor; 9 import org.jboss.cache.misc.TestingUtil; 10 11 import javax.transaction.TransactionManager ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 15 23 public class OptimisticEvictionTest extends TestCase 24 { 25 26 private static final int NUMBER_OF_RUNS = 1 << 20; 28 private static final int NUMBER_NODES = 256; 30 31 private Fqn region = Fqn.fromString("testingRegion"); 32 private TransactionManager txManager; 33 private CacheImpl cache; 34 35 protected void setUp() throws Exception 36 { 37 super.setUp(); 38 39 txManager = new DummyTransactionManagerLookup().getTransactionManager(); 40 cache = new CacheImpl(); 41 cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/optimistic-eviction.xml")); 42 cache.start(); 43 } 44 45 protected void tearDown() throws Exception 46 { 47 if (cache != null) 48 { 49 cache.stop(); 50 cache = null; 51 } 52 super.tearDown(); 53 } 54 55 56 public void testEvictionError() throws Exception 57 { 58 for (int i = 0; i < NUMBER_NODES; i++) 60 { 61 cache.put(new Fqn(region, i), i, i); 62 } 63 64 for (int i = 0; i < NUMBER_OF_RUNS; i++) 65 { 66 txManager.begin(); 67 cache.get(region, i % NUMBER_NODES); 68 txManager.commit(); 69 } 70 } 71 72 73 public void testEvictionOccurence() throws Exception 74 { 75 cache.put("/timeBased/test", "key", "value"); 76 assertTrue(cache.exists("/timeBased/test")); 77 78 TestingUtil.sleepThread(3000); 80 assertTrue(!cache.exists("/timeBased/test")); 81 } 82 83 public void testInterceptorChain() throws Exception 84 { 85 List interceptors = cache.getInterceptors(); 86 System.out.println(interceptors); 87 Iterator i = interceptors.iterator(); 88 boolean found = false; 89 90 while (i.hasNext()) 91 { 92 Object o = i.next(); 93 if (o instanceof EvictionInterceptor) 94 { 95 found = true; 96 } 97 } 98 99 assertTrue("Eviction interceptor should be in interceptor chain.", found); 100 } 101 102 } 103 | Popular Tags |