1 22 23 package org.jboss.cache.passivation; 24 25 import junit.framework.TestCase; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.jboss.cache.AbstractCacheListener; 29 import org.jboss.cache.CacheImpl; 30 import org.jboss.cache.Fqn; 31 import org.jboss.cache.factories.XmlConfigurationParser; 32 import org.jboss.cache.misc.TestingUtil; 33 34 import java.util.Map ; 35 36 39 public class ReplicatedPassivationIntegrationTest extends TestCase 40 { 41 CacheImpl cache_; 42 CacheImpl cache1_; 43 protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class); 44 int wakeupIntervalMillis_ = 0; 45 ReplicatedPassivationIntegrationTest.PassivationListener listener_; 46 47 public ReplicatedPassivationIntegrationTest(String s) 48 { 49 super(s); 50 listener_ = new ReplicatedPassivationIntegrationTest.PassivationListener(); 51 } 52 53 public void setUp() throws Exception 54 { 55 super.setUp(); 56 cache_ = new CacheImpl(); 57 initCaches(cache_); 58 cache_.getConfiguration().setUseRegionBasedMarshalling(true); 59 cache_.start(); 60 61 cache1_ = new CacheImpl(); 62 initCaches(cache1_); 63 cache1_.getConfiguration().setUseRegionBasedMarshalling(true); 64 65 cache1_.start(); 66 cache1_.getNotifier().addCacheListener(listener_); 67 listener_.resetCounter(); 68 69 wakeupIntervalMillis_ = cache1_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000; 70 log("wakeupInterval is " + wakeupIntervalMillis_); 71 if (wakeupIntervalMillis_ <= 0) 72 { 73 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_); 74 } 75 } 76 77 void initCaches(CacheImpl cache) throws Exception 78 { 79 cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-passivation-service.xml")); cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 81 } 82 83 public void tearDown() throws Exception 84 { 85 super.tearDown(); 86 cache_.stop(); 87 cache1_.stop(); 88 } 89 90 92 public void testActivationEvent() throws Exception 93 { 94 String rootStr = "/org/jboss/test/data/"; 95 String rootStr1 = "/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2"; 96 String str = rootStr + "0"; 97 cache_.remove("/"); 98 listener_.resetCounter(); 99 100 cache_.put(str, str, str); 101 cache_.put(rootStr1, str, str); 102 103 TestingUtil.sleepThread(11000); 104 assertFalse("UnversionedNode should not exist", cache1_.exists(str, str)); 105 String val; 106 val = (String ) cache1_.get(str, str); 107 val = (String ) cache1_.get(rootStr1, str); 108 assertNotNull("DataNode should be activated ", val); 109 assertEquals("Eviction counter ", 2, listener_.getCounter()); 110 } 111 112 void log(String msg) 113 { 114 System.out.println("-- " + msg); 115 } 116 117 class PassivationListener extends AbstractCacheListener 118 { 119 int counter = 0; 120 int loadedCounter = 0; 121 122 public int getCounter() 123 { 124 return counter; 125 } 126 127 public void resetCounter() 128 { 129 counter = 0; 130 loadedCounter = 0; 131 } 132 133 public void nodeActivated(Fqn fqn, boolean pre) 134 { 135 if (!pre) 136 { 137 counter++; 138 System.out.println("nodeActivate(): counter: " + counter); 139 System.out.println("nodeActivate(): " + fqn); 140 } 141 } 142 143 public void nodePassivated(Fqn fqn, boolean pre) 144 { 145 if (pre) 146 { 147 System.out.println("nodePassivate(): " + fqn); 148 } 149 } 150 151 public void nodeLoaded(Fqn f, boolean pre, Map data) 152 { 153 if (!pre) 154 { 155 loadedCounter++; 156 } 157 } 158 159 } 160 } 161 | Popular Tags |