1 7 8 package org.jboss.cache.passivation; 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.config.CacheLoaderConfig; 16 import org.jboss.cache.config.Configuration; 17 import org.jboss.cache.factories.XmlConfigurationParser; 18 import org.jboss.cache.misc.TestingUtil; 19 20 26 public class ConcurrentPassivationTest extends TestCase 27 { 28 private CacheImpl cache_; 29 private int wakeupIntervalMillis_ = 0; 30 31 public ConcurrentPassivationTest(String s) 32 { 33 super(s); 34 } 35 36 public void setUp() throws Exception 37 { 38 super.setUp(); 39 initCaches(); 40 wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000; 41 if (wakeupIntervalMillis_ < 0) 42 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_); 43 44 } 45 46 void initCaches() throws Exception 47 { 48 TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader"); 49 cache_ = new CacheImpl(); 50 cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml")); cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 52 53 injectCacheLoaderLocation(cache_.getConfiguration(), "/tmp/JBossCacheFileCacheLoader"); 55 cache_.start(); 56 } 57 58 private void injectCacheLoaderLocation(Configuration configuration, String location) 59 { 60 for (CacheLoaderConfig.IndividualCacheLoaderConfig iclc : configuration.getCacheLoaderConfig().getIndividualCacheLoaderConfigs()) 61 { 62 iclc.getProperties().put("location", location); 63 } 64 } 65 66 67 public void tearDown() throws Exception 68 { 69 super.tearDown(); 70 TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader"); 71 cache_.stop(); 72 cache_ = null; 73 } 74 75 public void testConcurrentPassivation() throws Exception 76 { 77 Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/passivation"); 78 79 for (int i = 0; i < 35000; i++) 82 { 83 cache_.put(new Fqn(base, i / 100), new Integer (i), "value"); 84 } 85 86 long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_); 88 while (System.currentTimeMillis() < loopDone) 89 { 90 for (int i = 0; i < 35000; i++) 92 { 93 Fqn fqn = new Fqn(base, i / 100); 94 Integer key = i; 95 assertNotNull("found value under Fqn " + fqn + " and key " + key, 96 cache_.get(fqn, key)); 97 } 98 } 99 } 100 101 public static Test suite() 102 { 103 return new TestSuite(org.jboss.cache.passivation.ConcurrentPassivationTest.class); 104 } 105 106 public static void main(String [] args) 107 { 108 junit.textui.TestRunner.run(org.jboss.cache.passivation.ConcurrentPassivationTest.suite()); 109 } 110 } 111
| Popular Tags
|