1 7 8 package org.jboss.cache.passivation; 9 10 import junit.framework.TestCase; 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 import org.jboss.cache.AbstractCacheListener; 14 import org.jboss.cache.CacheImpl; 15 import org.jboss.cache.Fqn; 16 import org.jboss.cache.config.CacheLoaderConfig; 17 import org.jboss.cache.config.Configuration; 18 import org.jboss.cache.factories.XmlConfigurationParser; 19 import org.jboss.cache.misc.TestingUtil; 20 21 import java.util.Map ; 22 23 26 public class LocalPassivationIntegrationTest extends TestCase 27 { 28 CacheImpl cache_; 29 protected final static Log log = LogFactory.getLog(LocalPassivationIntegrationTest.class); 30 int wakeupIntervalMillis_ = 0; 31 PassivationListener listener_; 32 33 public LocalPassivationIntegrationTest(String s) 34 { 35 super(s); 36 listener_ = new PassivationListener(); 37 } 38 39 public void setUp() throws Exception 40 { 41 super.setUp(); 42 TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader"); cache_ = new CacheImpl(); 44 initCaches(cache_); 45 cache_.getConfiguration().setUseRegionBasedMarshalling(true); 46 47 cache_.start(); 48 49 cache_.getNotifier().addCacheListener(listener_); 50 listener_.resetCounter(); 51 52 wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000; 53 log("wakeupInterval is " + wakeupIntervalMillis_); 54 if (wakeupIntervalMillis_ <= 0) 55 { 56 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_); 57 } 58 } 59 60 void initCaches(CacheImpl cache) throws Exception 61 { 62 cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml")); cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 64 injectCacheLoaderLocation(cache.getConfiguration(), "/tmp/JBossCacheFileCacheLoader"); 66 67 } 68 69 private void injectCacheLoaderLocation(Configuration configuration, String location) 70 { 71 for (CacheLoaderConfig.IndividualCacheLoaderConfig iclc : configuration.getCacheLoaderConfig().getIndividualCacheLoaderConfigs()) 72 { 73 iclc.getProperties().put("location", location); 74 } 75 } 76 77 78 public void tearDown() throws Exception 79 { 80 super.tearDown(); 81 cache_.stop(); 82 } 83 84 86 public void testActivationEvent() throws Exception 87 { 88 String rootStr = "/org/jboss/test/data/"; 89 String str = rootStr + "0"; 90 cache_.remove("/"); 91 listener_.resetCounter(); 92 93 cache_.put(str, str, str); 94 95 TestingUtil.sleepThread(20000); 96 assertFalse("UnversionedNode should not exist", cache_.exists(str, str)); 97 String val = (String ) cache_.get(str, str); 98 assertNotNull("DataNode should be activated ", val); 99 assertEquals("Eviction counter ", 1, listener_.getCounter()); 100 } 101 102 void log(String msg) 103 { 104 System.out.println("-- " + msg); 105 } 106 107 class PassivationListener extends AbstractCacheListener 108 { 109 int counter = 0; 110 int loadedCounter = 0; 111 112 public int getCounter() 113 { 114 return counter; 115 } 116 117 public void resetCounter() 118 { 119 counter = 0; 120 loadedCounter = 0; 121 } 122 123 public void nodeActivated(Fqn fqn, boolean pre) 124 { 125 if (!pre) 126 { 127 counter++; 128 System.out.println("nodeActivate(): counter: " + counter); 129 } 130 } 131 132 public void nodePassivated(Fqn fqn, boolean pre) 133 { 134 if (pre) 135 { 136 System.out.println("nodePassivate(): " + fqn); 137 } 138 } 139 140 public void nodeLoaded(Fqn f, boolean pre, Map data) 141 { 142 if (!pre) 143 { 144 loadedCounter++; 145 } 146 } 147 148 } 149 } 150
| Popular Tags
|