JBoss Cache SVN: r5693 - core/trunk/src/test/java/org/jboss/cache/invalidation.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-04-25 09:34:09 -0400 (Fri, 25 Apr 2008)
New Revision: 5693
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
Log:
JBCACHE-1222 - fixed eviction test
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2008-04-25 12:51:05 UTC (rev 5692)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2008-04-25 13:34:09 UTC (rev 5693)
@@ -12,6 +12,8 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.ArrayList;
import java.util.Collections;
@@ -29,11 +31,12 @@
private CacheSPI c1, c2;
private Fqn fqn = Fqn.fromString("/data/test");
private Fqn dummy = Fqn.fromString("/data/dummy");
- private long evictionWaitTime = 2100;
+ private long evictionWaitTime = 4100;
@BeforeMethod
public void setUp() throws Exception
{
+ log.trace("**** setup called");
c1 = (CacheSPI) new DefaultCacheFactory().createCache(false);
// the FIFO policy cfg
@@ -53,7 +56,7 @@
EvictionConfig ec = new EvictionConfig();
- ec.setWakeupIntervalSeconds(1);
+ ec.setWakeupIntervalSeconds(2);
ec.setEvictionRegionConfigs(evictionRegionConfigs);
c1.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
@@ -75,15 +78,22 @@
TestingUtil.killCaches(c1, c2);
}
+ private static final Log log = LogFactory.getLog(TombstoneEvictionTest.class);
+
public void testControl()
{
+ log.trace("***** entered testControl()");
c1.put(fqn, "k", "v");
c1.put(dummy, "k", "v");
+ log.trace("***** nodes were added testControl()");
+
assert c1.peek(fqn, false, true) != null : "Node should exist";
assert c1.peek(dummy, false, true) != null : "Node should exist";
+ log.trace("***** testControl() right before sleeping");
TestingUtil.sleepThread(evictionWaitTime);
+ log.trace("***** testControl() right after sleeping");
assert c1.peek(fqn, false, true) == null : "Should have evicted";
assert c1.peek(dummy, false, true) != null : "Node should exist";
@@ -91,8 +101,10 @@
public void testWithInvalidationMarkers()
{
+ log.trace(" **** testWithInvalidationMarkers() before put");
c1.put(fqn, "k", "v");
c1.put(dummy, "k", "v");
+ log.trace(" **** testWithInvalidationMarkers() after put");
assert c1.peek(fqn, false, true) != null : "Node should exist";
assert c1.peek(dummy, false, true) != null : "Node should exist";
16 years, 2 months
JBoss Cache SVN: r5692 - in core/tags/2.1.1.GA/src: main/java/org/jboss/cache/transaction and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 08:51:05 -0400 (Fri, 25 Apr 2008)
New Revision: 5692
Modified:
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
core/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
Modified: core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 12:45:29 UTC (rev 5691)
+++ core/tags/2.1.1.GA/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 12:51:05 UTC (rev 5692)
@@ -1299,10 +1299,11 @@
*/
private void cleanupInternalState()
{
- this.tx = null;
- this.gtx = null;
- this.modifications = null;
- this.entry = null;
+ tx = null;
+ gtx = null;
+ modifications = null;
+ if (entry != null) entry.reset();
+ entry = null;
}
public String toString()
Modified: core/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25 12:45:29 UTC (rev 5691)
+++ core/tags/2.1.1.GA/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25 12:51:05 UTC (rev 5692)
@@ -438,6 +438,20 @@
*/
public boolean existModifications()
{
- return !modification_list.isEmpty() || !cl_mod_list.isEmpty();
+ return !modification_list.isEmpty() || !cl_mod_list.isEmpty();
}
+
+ /**
+ * Cleans up internal state
+ */
+ public void reset()
+ {
+ orderedSynchronizationHandler = null;
+ modification_list.clear();
+ cl_mod_list.clear();
+ option = null;
+ locks.clear();
+ if (dummyNodesCreatedByCacheLoader != null) dummyNodesCreatedByCacheLoader.clear();
+ removedNodes.clear();
+ }
}
Modified: core/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 12:45:29 UTC (rev 5691)
+++ core/tags/2.1.1.GA/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 12:51:05 UTC (rev 5692)
@@ -4,12 +4,14 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
-
+import org.jboss.cache.transaction.TransactionEntry;
+import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Map;
@@ -90,7 +92,7 @@
public void testScrubbingAfterOnePhaseCommit() throws Exception
{
setUpOnePhaseCache();
-
+
doScrubbingTest(true);
}
@@ -102,7 +104,7 @@
public void testScrubbingAfterOnePhaseRollback() throws Exception
{
setUpOnePhaseCache();
-
+
doScrubbingTest(true);
}
@@ -110,13 +112,17 @@
{
// Start clean
cache.getInvocationContext().reset();
-
+
tm.begin();
+ TransactionTable tt = cache.getTransactionTable();
cache.getRoot().put("key", "value");
assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+ Transaction tx = tm.getTransaction();
+ TransactionEntry entry = tt.get(tt.get(tx));
+
if (commit)
{
tm.commit();
@@ -129,6 +135,11 @@
assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
assertEquals("MethodCall should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
+
+ // check that the transaction entry hasn't leaked stuff.
+ assert entry.getModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+ assert entry.getCacheLoaderModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+ assert entry.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
}
private void setUpOnePhaseCache()
@@ -138,7 +149,7 @@
cache.stop();
cache = null;
}
-
+
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache("META-INF/conf-test/replSync-service.xml", false);
cache.getConfiguration().setCacheMode(CacheMode.REPL_ASYNC);
cache.start();
16 years, 2 months
JBoss Cache SVN: r5691 - in core/branches/2.1.X/src: main/java/org/jboss/cache/transaction and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 08:45:29 -0400 (Fri, 25 Apr 2008)
New Revision: 5691
Modified:
core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
JBCACHE-1326: Check that the transaction entry doesn't leak stuff after a transaction completes
Modified: core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 12:43:32 UTC (rev 5690)
+++ core/branches/2.1.X/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 12:45:29 UTC (rev 5691)
@@ -1299,10 +1299,11 @@
*/
private void cleanupInternalState()
{
- this.tx = null;
- this.gtx = null;
- this.modifications = null;
- this.entry = null;
+ tx = null;
+ gtx = null;
+ modifications = null;
+ if (entry != null) entry.reset();
+ entry = null;
}
public String toString()
Modified: core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25 12:43:32 UTC (rev 5690)
+++ core/branches/2.1.X/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25 12:45:29 UTC (rev 5691)
@@ -438,6 +438,20 @@
*/
public boolean existModifications()
{
- return !modification_list.isEmpty() || !cl_mod_list.isEmpty();
+ return !modification_list.isEmpty() || !cl_mod_list.isEmpty();
}
+
+ /**
+ * Cleans up internal state
+ */
+ public void reset()
+ {
+ orderedSynchronizationHandler = null;
+ modification_list.clear();
+ cl_mod_list.clear();
+ option = null;
+ locks.clear();
+ if (dummyNodesCreatedByCacheLoader != null) dummyNodesCreatedByCacheLoader.clear();
+ removedNodes.clear();
+ }
}
Modified: core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 12:43:32 UTC (rev 5690)
+++ core/branches/2.1.X/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 12:45:29 UTC (rev 5691)
@@ -4,12 +4,14 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
-
+import org.jboss.cache.transaction.TransactionEntry;
+import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Map;
@@ -90,7 +92,7 @@
public void testScrubbingAfterOnePhaseCommit() throws Exception
{
setUpOnePhaseCache();
-
+
doScrubbingTest(true);
}
@@ -102,7 +104,7 @@
public void testScrubbingAfterOnePhaseRollback() throws Exception
{
setUpOnePhaseCache();
-
+
doScrubbingTest(true);
}
@@ -110,13 +112,17 @@
{
// Start clean
cache.getInvocationContext().reset();
-
+
tm.begin();
+ TransactionTable tt = cache.getTransactionTable();
cache.getRoot().put("key", "value");
assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+ Transaction tx = tm.getTransaction();
+ TransactionEntry entry = tt.get(tt.get(tx));
+
if (commit)
{
tm.commit();
@@ -129,6 +135,11 @@
assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
assertEquals("MethodCall should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
+
+ // check that the transaction entry hasn't leaked stuff.
+ assert entry.getModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+ assert entry.getCacheLoaderModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+ assert entry.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
}
private void setUpOnePhaseCache()
@@ -138,7 +149,7 @@
cache.stop();
cache = null;
}
-
+
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache("META-INF/conf-test/replSync-service.xml", false);
cache.getConfiguration().setCacheMode(CacheMode.REPL_ASYNC);
cache.start();
16 years, 2 months
JBoss Cache SVN: r5690 - in core/trunk/src: main/java/org/jboss/cache/transaction and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 08:43:32 -0400 (Fri, 25 Apr 2008)
New Revision: 5690
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
JBCACHE-1327 - prevent leakage of MethodCall and CacheCommand in InvocationContexts
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 12:22:40 UTC (rev 5689)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 12:43:32 UTC (rev 5690)
@@ -1204,10 +1204,11 @@
*/
private void cleanupInternalState()
{
- this.tx = null;
- this.gtx = null;
- this.modifications = null;
- this.entry = null;
+ tx = null;
+ gtx = null;
+ modifications = null;
+ if (entry != null) entry.reset();
+ entry = null;
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25 12:22:40 UTC (rev 5689)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-25 12:43:32 UTC (rev 5690)
@@ -408,4 +408,18 @@
}
return false;
}
+
+ /**
+ * Cleans up internal state
+ */
+ public void reset()
+ {
+ orderedSynchronizationHandler = null;
+ modificationList.clear();
+ classLoadeModList.clear();
+ option = null;
+ locks.clear();
+ if (dummyNodesCreatedByCacheLoader != null) dummyNodesCreatedByCacheLoader.clear();
+ removedNodes.clear();
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 12:22:40 UTC (rev 5689)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 12:43:32 UTC (rev 5690)
@@ -4,11 +4,14 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.transaction.TransactionEntry;
+import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Map;
@@ -112,11 +115,16 @@
cache.getInvocationContext().reset();
tm.begin();
+ TransactionTable tt = cache.getTransactionTable();
cache.getRoot().put("key", "value");
+
assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+ Transaction tx = tm.getTransaction();
+ TransactionEntry entry = tt.get(tt.get(tx));
+
if (commit)
{
tm.commit();
@@ -130,6 +138,11 @@
assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
assertEquals("Method call should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
assertEquals("Cache command should have been scrubbed", null, cache.getInvocationContext().getExecutingCommand());
+
+ // check that the transaction entry hasn't leaked stuff.
+ assert entry.getModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+ assert entry.getCacheLoaderModifications().isEmpty() : "Should have scrubbed modifications in transaction entry";
+ assert entry.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
}
private void setUpOnePhaseCache()
16 years, 2 months
JBoss Cache SVN: r5689 - in core/trunk/src: test/java/org/jboss/cache/buddyreplication and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-04-25 08:22:40 -0400 (Fri, 25 Apr 2008)
New Revision: 5689
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
Log:
JBCACHE-1222 - fixed FIFO eviction test
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-04-25 12:11:55 UTC (rev 5688)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-04-25 12:22:40 UTC (rev 5689)
@@ -335,6 +335,7 @@
InvocationContext ctx = invocationContextContainer.get();
cacheStatusCheck(ctx);
List<Fqn> nodesToEvict = cacheData.getNodesForEviction(fqn, recursive);
+ //todo optimize this so that it performs only one call disregarding
for (Fqn aFqn : nodesToEvict)
{
invoker.invoke(ctx, commandsFactory.buildEvictFqnCommand(aFqn));
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2008-04-25 12:11:55 UTC (rev 5688)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2008-04-25 12:22:40 UTC (rev 5689)
@@ -204,7 +204,7 @@
List<CacheSPI<Object, Object>> dump = new ArrayList<CacheSPI<Object, Object>>(caches);
dump.add(cache2);
- dumpCacheContents(dump);
+ TestingUtil.dumpCacheContents(dump);
// now caches.get(1)'s buddy should be cache2, not cache[0]
assertIsBuddy(caches.get(1), cache2, true);
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java 2008-04-25 12:11:55 UTC (rev 5688)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java 2008-04-25 12:22:40 UTC (rev 5689)
@@ -43,15 +43,15 @@
Fqn fqn = Fqn.fromString("/test");
Fqn backupFqn = BuddyFqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), fqn);
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
caches.get(0).put(fqn, key, value);
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
assertEquals("Value should exist", value, caches.get(0).get(fqn, key));
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
// use exists instead of get() to prevent going up the interceptor stack
assertTrue("Should be false", !caches.get(1).exists(fqn));
@@ -68,7 +68,7 @@
killChannel(caches.get(0), caches.get(1), 2);
System.out.println("Killed. Testing backup roots.");
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
// assert that the remaining caches have picked new buddies. Cache 1 should have cache 2's backup data.
assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(2).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
assert caches.get(1).peek(BuddyFqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
@@ -88,7 +88,7 @@
delay(); // cleanup commands are async
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
// now lets test the eviction part of gravitation
Fqn newBackupFqn = BuddyFqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn);
@@ -152,7 +152,7 @@
Fqn backupFqn = BuddyFqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), fqn);
caches.get(0).put(fqn, key, value);
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
assertEquals("value", caches.get(0).get(fqn, key));
assertFalse(caches.get(0).exists(backupFqn));
@@ -171,7 +171,7 @@
assertEquals("value", caches.get(1).get(fqn, key));
delay(); // cleanup commands are async
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
assertFalse(caches.get(1).exists(backupFqn));
assertEquals("value", caches.get(2).get(backupFqn, key));
@@ -231,7 +231,7 @@
assertTrue(!caches.get(1).exists(newBackupFqn));
assertTrue(!caches.get(1).exists(newBackupFqn2));
- dumpCacheContents(caches);
+ TestingUtil.dumpCacheContents(caches);
for (CacheSPI<Object, Object> cache : caches)
{
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-04-25 12:11:55 UTC (rev 5688)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-04-25 12:22:40 UTC (rev 5689)
@@ -320,24 +320,6 @@
assertTrue(buddyLocalAddress + " should be a buddy to " + group.getGroupName(), group.getBuddies().contains(buddyLocalAddress));
}
- protected void dumpCacheContents(List<CacheSPI<Object, Object>> caches)
- {
- System.out.println("**** START: Cache Contents ****");
- for (int i = 0; i < caches.size(); i++)
- {
- if (caches.get(i) == null)
- {
- System.out.println(" ** Cache " + i + " is null!");
- }
- else
- {
- System.out.println(" ** Cache " + i + " is " + caches.get(i).getLocalAddress());
- System.out.println(" " + CachePrinter.printCacheLockingInfo(caches.get(i)));
- }
- }
- System.out.println("**** END: Cache Contents ****");
- }
-
protected void assertNoLocks(List<CacheSPI<Object, Object>> caches)
{
for (Cache cache : caches)
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2008-04-25 12:11:55 UTC (rev 5688)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2008-04-25 12:22:40 UTC (rev 5689)
@@ -19,6 +19,8 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.List;
import java.util.ArrayList;
@@ -136,7 +138,7 @@
cache.put(fqn, str, str);
}
- TestingUtil.sleepThread(wakeupIntervalMillis + 500);
+ TestingUtil.sleepThread(wakeupIntervalMillis + 10000);
assertEquals("Number of nodes", maxNodes + 2, cache.getNumberOfNodes());
for (int i = 0; i < maxNodes; i++)
{
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-04-25 12:11:55 UTC (rev 5688)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-04-25 12:22:40 UTC (rev 5689)
@@ -11,6 +11,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
+import org.jboss.cache.util.CachePrinter;
import org.jboss.cache.commands.CacheCommand;
import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.factories.ComponentRegistry;
@@ -26,6 +27,7 @@
import java.lang.reflect.Field;
import java.util.List;
import java.util.Random;
+import java.util.ArrayList;
/**
* Utilities for unit testing JBossCache.
@@ -586,4 +588,31 @@
}
return null;
}
+
+ public static void dumpCacheContents(List<CacheSPI> caches)
+ {
+ System.out.println("**** START: Cache Contents ****");
+ for (int i = 0; i < caches.size(); i++)
+ {
+ if (caches.get(i) == null)
+ {
+ System.out.println(" ** Cache " + i + " is null!");
+ }
+ else
+ {
+ System.out.println(" ** Cache " + i + " is " + caches.get(i).getLocalAddress());
+ System.out.println(" " + CachePrinter.printCacheLockingInfo(caches.get(i)));
+ }
+ }
+ System.out.println("**** END: Cache Contents ****");
+ }
+ public static void dumpCacheContents(Object... caches)
+ {
+ List<CacheSPI> result = new ArrayList<CacheSPI>();
+ for (Object cache: caches)
+ {
+ result.add((CacheSPI<Object, Object>) cache);
+ }
+ dumpCacheContents(result);
+ }
}
16 years, 2 months
JBoss Cache SVN: r5688 - in core/trunk/src: main/java/org/jboss/cache/commands and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 08:11:55 -0400 (Fri, 25 Apr 2008)
New Revision: 5688
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/commands/CacheCommand.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
JBCACHE-1327 - prevent leakage of MethodCall and CacheCommand in InvocationContexts
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-04-25 11:19:47 UTC (rev 5687)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-04-25 12:11:55 UTC (rev 5688)
@@ -38,6 +38,7 @@
private boolean txHasMods;
private boolean cacheLoaderHasMods;
private boolean localRollbackOnly;
+ @Deprecated
private MethodCall methodCall;
@Deprecated
private CacheCommand executingCommand;
@@ -292,6 +293,8 @@
originLocal = true;
txHasMods = false;
invocationLocks = null;
+ methodCall = null;
+ executingCommand = null;
}
@Override
@@ -375,9 +378,10 @@
return methodCall;
}
- @SuppressWarnings("deprecated")
+ @SuppressWarnings("deprecation")
private MethodCall createMethodCall(MarshallableCommand command)
{
+ if (command == null) return null;
MethodCall call = new MethodCall();
call.setMethodId(command.getCommandId());
call.setArgs(command.getParameters());
Modified: core/trunk/src/main/java/org/jboss/cache/commands/CacheCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/CacheCommand.java 2008-04-25 11:19:47 UTC (rev 5687)
+++ core/trunk/src/main/java/org/jboss/cache/commands/CacheCommand.java 2008-04-25 12:11:55 UTC (rev 5688)
@@ -6,7 +6,6 @@
* @author Mircea.Markus(a)jboss.com
* @since 2.2
* todo - reduce dependencies from CacheSPI many commands depend on CacheSPI only for invoceation ctxt. inject ctxt rather than entire CacheSPI
- * todo - add toString to all commands
*/
public interface CacheCommand extends Cloneable
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-04-25 11:19:47 UTC (rev 5687)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-04-25 12:11:55 UTC (rev 5688)
@@ -111,6 +111,7 @@
return handleAll(ctx, command, null);
}
+ @SuppressWarnings("deprecation")
public Object handleAll(InvocationContext ctx, CacheCommand command, GlobalTransaction gtx) throws Throwable
{
Option optionOverride = ctx.getOptionOverrides();
@@ -186,6 +187,10 @@
copyInvocationScopeOptionsToTxScope(ctx);
}
}
+
+ // reset the context to prevent leakage of internals
+ ctx.setExecutingCommand(null);
+ ctx.setMethodCall(null);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 11:19:47 UTC (rev 5687)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-25 12:11:55 UTC (rev 5688)
@@ -738,12 +738,22 @@
* @return
* @throws Throwable
*/
- private Object handleCommitRollback(InvocationContext ctx) throws Throwable
+ @SuppressWarnings("deprecation")
+ private Object handleCommitRollback(InvocationContext ctx, CacheCommand command) throws Throwable
{
- //GlobalTransaction globalTransaction = findGlobalTransaction(m.getArgs());
GlobalTransaction gtx = ctx.getGlobalTransaction();
Object result;
- result = invokeNextInterceptor(ctx, ctx.getExecutingCommand());
+ CacheCommand originalCommand = ctx.getExecutingCommand();
+ ctx.setExecutingCommand(command);
+ try
+ {
+ result = invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ ctx.setExecutingCommand(originalCommand);
+ ctx.setMethodCall(null);
+ }
if (log.isDebugEnabled()) log.debug("Finished local commit/rollback method for " + gtx);
return result;
}
@@ -784,8 +794,8 @@
{
log.trace(" running commit for " + gtx);
}
- ctx.setExecutingCommand(commitCommand);
- handleCommitRollback(ctx);
+
+ handleCommitRollback(ctx, commitCommand);
}
catch (Throwable e)
{
@@ -845,8 +855,7 @@
//ltx = getLocalTxForGlobalTx(globalTransaction);
rollbackTransactions.put(tx, gtx);
- ctx.setExecutingCommand(rollbackCommand);
- handleCommitRollback(ctx);
+ handleCommitRollback(ctx, rollbackCommand);
}
catch (Throwable e)
{
@@ -884,6 +893,7 @@
* @return
* @throws Throwable
*/
+ @SuppressWarnings("deprecation")
public Object runPreparePhase(InvocationContext ctx, GlobalTransaction gtx, List<TxCacheCommand> modifications) throws Throwable
{
// build the method call
@@ -919,10 +929,19 @@
//if ltx is not null and it is already running
if (txManager.getTransaction() != null && ltx != null && txManager.getTransaction().equals(ltx))
{
+ CacheCommand originalCommand = ctx.getExecutingCommand();
ctx.setExecutingCommand(prepareCommand);
// set the hasMods flag in the invocation ctx. This should not be replicated, just used locally by the interceptors.
ctx.setTxHasMods(modifications != null && modifications.size() > 0);
- result = invokeNextInterceptor(ctx, prepareCommand);
+ try
+ {
+ result = invokeNextInterceptor(ctx, prepareCommand);
+ }
+ finally
+ {
+ ctx.setExecutingCommand(originalCommand);
+ ctx.setMethodCall(null);
+ }
}
else
{
Modified: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 11:19:47 UTC (rev 5687)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-25 12:11:55 UTC (rev 5688)
@@ -4,7 +4,6 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
-
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -90,7 +89,7 @@
public void testScrubbingAfterOnePhaseCommit() throws Exception
{
setUpOnePhaseCache();
-
+
doScrubbingTest(true);
}
@@ -102,15 +101,16 @@
public void testScrubbingAfterOnePhaseRollback() throws Exception
{
setUpOnePhaseCache();
-
+
doScrubbingTest(true);
}
+ @SuppressWarnings("deprecation")
private void doScrubbingTest(boolean commit) throws Exception
{
// Start clean
cache.getInvocationContext().reset();
-
+
tm.begin();
cache.getRoot().put("key", "value");
assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
@@ -128,6 +128,8 @@
assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
+ assertEquals("Method call should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
+ assertEquals("Cache command should have been scrubbed", null, cache.getInvocationContext().getExecutingCommand());
}
private void setUpOnePhaseCache()
@@ -137,7 +139,7 @@
cache.stop();
cache = null;
}
-
+
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache("META-INF/conf-test/replSync-service.xml", false);
cache.getConfiguration().setCacheMode(CacheMode.REPL_ASYNC);
cache.start();
16 years, 2 months
JBoss Cache SVN: r5687 - core/trunk/src/test/java/org/jboss/cache/cluster.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 07:19:47 -0400 (Fri, 25 Apr 2008)
New Revision: 5687
Modified:
core/trunk/src/test/java/org/jboss/cache/cluster/ReplicationQueueTest.java
Log:
Added delay
Modified: core/trunk/src/test/java/org/jboss/cache/cluster/ReplicationQueueTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/cluster/ReplicationQueueTest.java 2008-04-25 11:05:20 UTC (rev 5686)
+++ core/trunk/src/test/java/org/jboss/cache/cluster/ReplicationQueueTest.java 2008-04-25 11:19:47 UTC (rev 5687)
@@ -148,6 +148,8 @@
// now test results
verify(mockRpcManager);
+ TestingUtil.sleepThread(250); // make sure the queue flushes
+
assert replQ.elements.size() == 0;
}
16 years, 2 months
JBoss Cache SVN: r5686 - in core/tags/2.1.1.GA/src: test/java/org/jboss/cache/buddyreplication and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 07:05:20 -0400 (Fri, 25 Apr 2008)
New Revision: 5686
Added:
core/tags/2.1.1.GA/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
Modified:
core/tags/2.1.1.GA/src/main/java/org/jboss/cache/RPCManagerImpl.java
Log:
Modified: core/tags/2.1.1.GA/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/tags/2.1.1.GA/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-04-25 11:01:33 UTC (rev 5685)
+++ core/tags/2.1.1.GA/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-04-25 11:05:20 UTC (rev 5686)
@@ -124,6 +124,7 @@
case INVALIDATION_ASYNC:
case INVALIDATION_SYNC:
isInLocalMode = false;
+ isUsingBuddyReplication = configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled();
if (log.isDebugEnabled()) log.debug("Cache mode is " + configuration.getCacheMode());
initialiseChannelAndRpcDispatcher();
Added: core/tags/2.1.1.GA/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
===================================================================
--- core/tags/2.1.1.GA/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java (rev 0)
+++ core/tags/2.1.1.GA/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java 2008-04-25 11:05:20 UTC (rev 5686)
@@ -0,0 +1,235 @@
+package org.jboss.cache.buddyreplication;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests fail over scenario when using buddy replication.
+ * <p/>
+ * What we are looking for is the last log output 'RECOVERED DATA', if all counter values
+ * are zero then we have failed to recover the work done on the buddy node.
+ * <p/>
+ * Change the LATE_START_BUDDY_CACHE flag to trigger different startup behavior at the initial
+ * object creation. It does not seem to have an impact on the outcome though.
+ *
+ * @author Fredrik Johansson, Cubeia Ltd
+ */
+@Test
+public class BuddyReplicationRejoinTest extends BuddyReplicationTestsBase
+{
+ private static Log log = LogFactory.getLog(BuddyReplicationRejoinTest.class);
+
+ /**
+ * How many object we should insert to the cache.
+ */
+ private final static int OBJECT_COUNT = 10;
+
+ private Cache<String, Integer> cache1;
+ private Cache<String, Integer> cache2;
+
+ @BeforeTest
+ public void setUp() throws Exception
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setEnabled(true);
+ brc.setBuddyCommunicationTimeout(1000);
+ brc.setAutoDataGravitation(true);
+ brc.setDataGravitationRemoveOnFind(true);
+ brc.setDataGravitationSearchBackupTrees(true);
+ Configuration c = new Configuration();
+ c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ c.setBuddyReplicationConfig(brc);
+
+ // Cache1 will be used only for recovery.
+ // Cache2 will perform some updates on the objects and then fail.
+
+ cache1 = new DefaultCacheFactory().createCache(c, false);
+ cache2 = new DefaultCacheFactory().createCache(c.clone(), false);
+ }
+
+ @AfterTest
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache1, cache2);
+ }
+
+ /**
+ * Executes the test scenario which goes like this:
+ * <p/>
+ * 1. Start primary cache (cache1)
+ * <p/>
+ * 2. Add initial data to primary cache1. All counters are now 0.
+ * <p/>
+ * 3. Start secondary cache (cache2)
+ * <p/>
+ * 4. Let the secondary change data in half of the objects. The cache
+ * will simply update a counter value. The values should now be 1
+ * for those objects.
+ * <p/>
+ * This will trigger a data-gravitation to the secondary cache and
+ * the objects should be removed from the primary cache's real data
+ * <p/>
+ * 5. Fail the secondary cache (cache.stop()). The primary cache should hold
+ * valid values for the objects updated by the secondary cache (values
+ * should be 2).
+ * <p/>
+ * 6. Print out all data in the primary cache. This will cause all objects
+ * gravitate to the primary cache. We should have the the same state as
+ * after #1 in list except that object 0-4 should have counter = 1.
+ * <p/>
+ * 7. Startup a secondary cache again.
+ * <p/>
+ * 8. Run the same update procedure. The secondary cache should gravitate objects
+ * 0-4 and update the counters with +1, making the counters = 2.
+ * <p/>
+ * 9. Fail the secondary cache.
+ * <p/>
+ * 10. Print out all data in the primary cache. This will cause all objects
+ * gravitate to the primary cache. We should have the the same state as
+ * after #1 in list except that object 0-4 should have counter = 2 this time
+ * since the second secondary cache should have update the values again.
+ * <p/>
+ * <p/>
+ * FAIL.
+ * <p/>
+ * The recovered values in the end are 1, not 2.
+ * It seems like the first buddy cache works fine, but he second time around it
+ * fails to remove the local objects on then primary cache on the remote gravitation.
+ * <p/>
+ * The log printout in the end *should* look like:
+ * <p/>
+ * *********** RECOVERED DATA ***********
+ * /0 counter = 2
+ * /1 counter = 2
+ * /2 counter = 2
+ * /3 counter = 2
+ * /4 counter = 2
+ * /5 counter = 0
+ * /6 counter = 0
+ * /7 counter = 0
+ * /8 counter = 0
+ * /9 counter = 0
+ * *********************************
+ * <p/>
+ * But we get 1's instead of 2's, which means that the recovery failed.
+ */
+ @SuppressWarnings("unchecked")
+ public void testGravitationAndFailover() throws CloneNotSupportedException
+ {
+ Configuration cfg = cache2.getConfiguration().clone();
+ cache1.start();
+ TestingUtil.sleepThread(100);
+
+ addInitial(cache1);
+ printCacheDetails("INITIAL STATES");
+
+ cache2.start();
+ printCacheDetails("CACHE2 STARTED");
+
+ runBuddyUpdatesAndFail();
+
+ checkRecoveredData(cache1, 1);
+ printCacheDetails("DATA GRAVITATED BACK TO CACHE1");
+
+ cache2 = new DefaultCacheFactory().createCache(cfg);
+ printCacheDetails("BUDDY BACK");
+
+ runBuddyUpdatesAndFail();
+
+ checkRecoveredData(cache1, 2);
+ printCacheDetails("DATA GRAVITATED BACK TO CACHE1 (AGAIN)");
+ }
+
+
+ private void runBuddyUpdatesAndFail()
+ {
+ executeBuddy(cache2);
+ printCacheDetails("BUDDY UPDATED");
+
+ cache2.stop();
+ printCacheDetails("BUDDY FAILED");
+ }
+
+
+ /**
+ * Change some data for a select number of objects on the given cache.
+ *
+ * @param cache
+ */
+ private void executeBuddy(Cache<String, Integer> cache)
+ {
+ for (int i = 0; i < OBJECT_COUNT / 2; i++)
+ {
+ Integer integer = cache.get(Fqn.fromString(String.valueOf(i)), "counter");
+ cache.put(Fqn.fromString(String.valueOf(i)), "counter", integer.intValue() + 1);
+ }
+ }
+
+
+ /**
+ * Add inital state to a cache
+ *
+ * @param cache
+ */
+ private void addInitial(Cache<String, Integer> cache)
+ {
+ for (int i = 0; i < OBJECT_COUNT; i++)
+ {
+ cache.put(new Fqn<String>(String.valueOf(i)), "counter", new Integer(0));
+ }
+ }
+
+
+ /**
+ * Print all data to the log
+ *
+ * @param cache
+ */
+ private void checkRecoveredData(Cache<String, Integer> cache, int expectedValue)
+ {
+ log.info("*********** RECOVERED DATA ***********");
+ for (int i = 0; i < OBJECT_COUNT; i++)
+ {
+ Integer counter = cache.get(Fqn.fromString(String.valueOf(i)), "counter");
+ log.info("/" + i + " counter = " + counter);
+ assert i < 5 ? counter == expectedValue : counter == 0;
+ }
+ log.info("*********************************");
+ }
+
+
+ private void printCacheDetails(String state)
+ {
+ log.info("*********** " + state + " ***********");
+ if (cache1.getCacheStatus() == CacheStatus.STARTED)
+ {
+ log.info("--------- CACHE 1 (" + cache1.getLocalAddress() + ") ---------");
+ log.info(CachePrinter.printCacheDetails(cache1));
+ }
+ else
+ {
+ log.info("--------- CACHE 1 STOPPED");
+ }
+
+ if (cache2.getCacheStatus() == CacheStatus.STARTED)
+ {
+ log.info("--------- CACHE 2 (" + cache2.getLocalAddress() + ") ---------");
+ log.info(CachePrinter.printCacheDetails(cache2) + "\n\n");
+ }
+ else
+ {
+ log.info("--------- CACHE 2 STOPPED");
+ }
+ }
+}
16 years, 2 months
JBoss Cache SVN: r5685 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 07:01:33 -0400 (Fri, 25 Apr 2008)
New Revision: 5685
Added:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
Log:
JBCACHE-1330 - added test
Added: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java 2008-04-25 11:01:33 UTC (rev 5685)
@@ -0,0 +1,235 @@
+package org.jboss.cache.buddyreplication;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests fail over scenario when using buddy replication.
+ * <p/>
+ * What we are looking for is the last log output 'RECOVERED DATA', if all counter values
+ * are zero then we have failed to recover the work done on the buddy node.
+ * <p/>
+ * Change the LATE_START_BUDDY_CACHE flag to trigger different startup behavior at the initial
+ * object creation. It does not seem to have an impact on the outcome though.
+ *
+ * @author Fredrik Johansson, Cubeia Ltd
+ */
+@Test
+public class BuddyReplicationRejoinTest extends BuddyReplicationTestsBase
+{
+ private static Log log = LogFactory.getLog(BuddyReplicationRejoinTest.class);
+
+ /**
+ * How many object we should insert to the cache.
+ */
+ private final static int OBJECT_COUNT = 10;
+
+ private Cache<String, Integer> cache1;
+ private Cache<String, Integer> cache2;
+
+ @BeforeTest
+ public void setUp() throws Exception
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setEnabled(true);
+ brc.setBuddyCommunicationTimeout(1000);
+ brc.setAutoDataGravitation(true);
+ brc.setDataGravitationRemoveOnFind(true);
+ brc.setDataGravitationSearchBackupTrees(true);
+ Configuration c = new Configuration();
+ c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ c.setBuddyReplicationConfig(brc);
+
+ // Cache1 will be used only for recovery.
+ // Cache2 will perform some updates on the objects and then fail.
+
+ cache1 = new DefaultCacheFactory().createCache(c, false);
+ cache2 = new DefaultCacheFactory().createCache(c.clone(), false);
+ }
+
+ @AfterTest
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache1, cache2);
+ }
+
+ /**
+ * Executes the test scenario which goes like this:
+ * <p/>
+ * 1. Start primary cache (cache1)
+ * <p/>
+ * 2. Add initial data to primary cache1. All counters are now 0.
+ * <p/>
+ * 3. Start secondary cache (cache2)
+ * <p/>
+ * 4. Let the secondary change data in half of the objects. The cache
+ * will simply update a counter value. The values should now be 1
+ * for those objects.
+ * <p/>
+ * This will trigger a data-gravitation to the secondary cache and
+ * the objects should be removed from the primary cache's real data
+ * <p/>
+ * 5. Fail the secondary cache (cache.stop()). The primary cache should hold
+ * valid values for the objects updated by the secondary cache (values
+ * should be 2).
+ * <p/>
+ * 6. Print out all data in the primary cache. This will cause all objects
+ * gravitate to the primary cache. We should have the the same state as
+ * after #1 in list except that object 0-4 should have counter = 1.
+ * <p/>
+ * 7. Startup a secondary cache again.
+ * <p/>
+ * 8. Run the same update procedure. The secondary cache should gravitate objects
+ * 0-4 and update the counters with +1, making the counters = 2.
+ * <p/>
+ * 9. Fail the secondary cache.
+ * <p/>
+ * 10. Print out all data in the primary cache. This will cause all objects
+ * gravitate to the primary cache. We should have the the same state as
+ * after #1 in list except that object 0-4 should have counter = 2 this time
+ * since the second secondary cache should have update the values again.
+ * <p/>
+ * <p/>
+ * FAIL.
+ * <p/>
+ * The recovered values in the end are 1, not 2.
+ * It seems like the first buddy cache works fine, but he second time around it
+ * fails to remove the local objects on then primary cache on the remote gravitation.
+ * <p/>
+ * The log printout in the end *should* look like:
+ * <p/>
+ * *********** RECOVERED DATA ***********
+ * /0 counter = 2
+ * /1 counter = 2
+ * /2 counter = 2
+ * /3 counter = 2
+ * /4 counter = 2
+ * /5 counter = 0
+ * /6 counter = 0
+ * /7 counter = 0
+ * /8 counter = 0
+ * /9 counter = 0
+ * *********************************
+ * <p/>
+ * But we get 1's instead of 2's, which means that the recovery failed.
+ */
+ @SuppressWarnings("unchecked")
+ public void testGravitationAndFailover() throws CloneNotSupportedException
+ {
+ Configuration cfg = cache2.getConfiguration().clone();
+ cache1.start();
+ TestingUtil.sleepThread(100);
+
+ addInitial(cache1);
+ printCacheDetails("INITIAL STATES");
+
+ cache2.start();
+ printCacheDetails("CACHE2 STARTED");
+
+ runBuddyUpdatesAndFail();
+
+ checkRecoveredData(cache1, 1);
+ printCacheDetails("DATA GRAVITATED BACK TO CACHE1");
+
+ cache2 = new DefaultCacheFactory().createCache(cfg);
+ printCacheDetails("BUDDY BACK");
+
+ runBuddyUpdatesAndFail();
+
+ checkRecoveredData(cache1, 2);
+ printCacheDetails("DATA GRAVITATED BACK TO CACHE1 (AGAIN)");
+ }
+
+
+ private void runBuddyUpdatesAndFail()
+ {
+ executeBuddy(cache2);
+ printCacheDetails("BUDDY UPDATED");
+
+ cache2.stop();
+ printCacheDetails("BUDDY FAILED");
+ }
+
+
+ /**
+ * Change some data for a select number of objects on the given cache.
+ *
+ * @param cache
+ */
+ private void executeBuddy(Cache<String, Integer> cache)
+ {
+ for (int i = 0; i < OBJECT_COUNT / 2; i++)
+ {
+ Integer integer = cache.get(Fqn.fromString(String.valueOf(i)), "counter");
+ cache.put(Fqn.fromString(String.valueOf(i)), "counter", integer.intValue() + 1);
+ }
+ }
+
+
+ /**
+ * Add inital state to a cache
+ *
+ * @param cache
+ */
+ private void addInitial(Cache<String, Integer> cache)
+ {
+ for (int i = 0; i < OBJECT_COUNT; i++)
+ {
+ cache.put(new Fqn<String>(String.valueOf(i)), "counter", new Integer(0));
+ }
+ }
+
+
+ /**
+ * Print all data to the log
+ *
+ * @param cache
+ */
+ private void checkRecoveredData(Cache<String, Integer> cache, int expectedValue)
+ {
+ log.info("*********** RECOVERED DATA ***********");
+ for (int i = 0; i < OBJECT_COUNT; i++)
+ {
+ Integer counter = cache.get(Fqn.fromString(String.valueOf(i)), "counter");
+ log.info("/" + i + " counter = " + counter);
+ assert i < 5 ? counter == expectedValue : counter == 0;
+ }
+ log.info("*********************************");
+ }
+
+
+ private void printCacheDetails(String state)
+ {
+ log.info("*********** " + state + " ***********");
+ if (cache1.getCacheStatus() == CacheStatus.STARTED)
+ {
+ log.info("--------- CACHE 1 (" + cache1.getLocalAddress() + ") ---------");
+ log.info(CachePrinter.printCacheDetails(cache1));
+ }
+ else
+ {
+ log.info("--------- CACHE 1 STOPPED");
+ }
+
+ if (cache2.getCacheStatus() == CacheStatus.STARTED)
+ {
+ log.info("--------- CACHE 2 (" + cache2.getLocalAddress() + ") ---------");
+ log.info(CachePrinter.printCacheDetails(cache2) + "\n\n");
+ }
+ else
+ {
+ log.info("--------- CACHE 2 STOPPED");
+ }
+ }
+}
16 years, 2 months
JBoss Cache SVN: r5684 - core/branches/2.1.X/src/test/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-25 06:59:52 -0400 (Fri, 25 Apr 2008)
New Revision: 5684
Added:
core/branches/2.1.X/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
Log:
JBCACHE-1330: Incorrect setting of isUsingBuddyReplication
Added: core/branches/2.1.X/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
===================================================================
--- core/branches/2.1.X/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java (rev 0)
+++ core/branches/2.1.X/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java 2008-04-25 10:59:52 UTC (rev 5684)
@@ -0,0 +1,235 @@
+package org.jboss.cache.buddyreplication;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests fail over scenario when using buddy replication.
+ * <p/>
+ * What we are looking for is the last log output 'RECOVERED DATA', if all counter values
+ * are zero then we have failed to recover the work done on the buddy node.
+ * <p/>
+ * Change the LATE_START_BUDDY_CACHE flag to trigger different startup behavior at the initial
+ * object creation. It does not seem to have an impact on the outcome though.
+ *
+ * @author Fredrik Johansson, Cubeia Ltd
+ */
+@Test
+public class BuddyReplicationRejoinTest extends BuddyReplicationTestsBase
+{
+ private static Log log = LogFactory.getLog(BuddyReplicationRejoinTest.class);
+
+ /**
+ * How many object we should insert to the cache.
+ */
+ private final static int OBJECT_COUNT = 10;
+
+ private Cache<String, Integer> cache1;
+ private Cache<String, Integer> cache2;
+
+ @BeforeTest
+ public void setUp() throws Exception
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setEnabled(true);
+ brc.setBuddyCommunicationTimeout(1000);
+ brc.setAutoDataGravitation(true);
+ brc.setDataGravitationRemoveOnFind(true);
+ brc.setDataGravitationSearchBackupTrees(true);
+ Configuration c = new Configuration();
+ c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ c.setBuddyReplicationConfig(brc);
+
+ // Cache1 will be used only for recovery.
+ // Cache2 will perform some updates on the objects and then fail.
+
+ cache1 = new DefaultCacheFactory().createCache(c, false);
+ cache2 = new DefaultCacheFactory().createCache(c.clone(), false);
+ }
+
+ @AfterTest
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache1, cache2);
+ }
+
+ /**
+ * Executes the test scenario which goes like this:
+ * <p/>
+ * 1. Start primary cache (cache1)
+ * <p/>
+ * 2. Add initial data to primary cache1. All counters are now 0.
+ * <p/>
+ * 3. Start secondary cache (cache2)
+ * <p/>
+ * 4. Let the secondary change data in half of the objects. The cache
+ * will simply update a counter value. The values should now be 1
+ * for those objects.
+ * <p/>
+ * This will trigger a data-gravitation to the secondary cache and
+ * the objects should be removed from the primary cache's real data
+ * <p/>
+ * 5. Fail the secondary cache (cache.stop()). The primary cache should hold
+ * valid values for the objects updated by the secondary cache (values
+ * should be 2).
+ * <p/>
+ * 6. Print out all data in the primary cache. This will cause all objects
+ * gravitate to the primary cache. We should have the the same state as
+ * after #1 in list except that object 0-4 should have counter = 1.
+ * <p/>
+ * 7. Startup a secondary cache again.
+ * <p/>
+ * 8. Run the same update procedure. The secondary cache should gravitate objects
+ * 0-4 and update the counters with +1, making the counters = 2.
+ * <p/>
+ * 9. Fail the secondary cache.
+ * <p/>
+ * 10. Print out all data in the primary cache. This will cause all objects
+ * gravitate to the primary cache. We should have the the same state as
+ * after #1 in list except that object 0-4 should have counter = 2 this time
+ * since the second secondary cache should have update the values again.
+ * <p/>
+ * <p/>
+ * FAIL.
+ * <p/>
+ * The recovered values in the end are 1, not 2.
+ * It seems like the first buddy cache works fine, but he second time around it
+ * fails to remove the local objects on then primary cache on the remote gravitation.
+ * <p/>
+ * The log printout in the end *should* look like:
+ * <p/>
+ * *********** RECOVERED DATA ***********
+ * /0 counter = 2
+ * /1 counter = 2
+ * /2 counter = 2
+ * /3 counter = 2
+ * /4 counter = 2
+ * /5 counter = 0
+ * /6 counter = 0
+ * /7 counter = 0
+ * /8 counter = 0
+ * /9 counter = 0
+ * *********************************
+ * <p/>
+ * But we get 1's instead of 2's, which means that the recovery failed.
+ */
+ @SuppressWarnings("unchecked")
+ public void testGravitationAndFailover() throws CloneNotSupportedException
+ {
+ Configuration cfg = cache2.getConfiguration().clone();
+ cache1.start();
+ TestingUtil.sleepThread(100);
+
+ addInitial(cache1);
+ printCacheDetails("INITIAL STATES");
+
+ cache2.start();
+ printCacheDetails("CACHE2 STARTED");
+
+ runBuddyUpdatesAndFail();
+
+ checkRecoveredData(cache1, 1);
+ printCacheDetails("DATA GRAVITATED BACK TO CACHE1");
+
+ cache2 = new DefaultCacheFactory().createCache(cfg);
+ printCacheDetails("BUDDY BACK");
+
+ runBuddyUpdatesAndFail();
+
+ checkRecoveredData(cache1, 2);
+ printCacheDetails("DATA GRAVITATED BACK TO CACHE1 (AGAIN)");
+ }
+
+
+ private void runBuddyUpdatesAndFail()
+ {
+ executeBuddy(cache2);
+ printCacheDetails("BUDDY UPDATED");
+
+ cache2.stop();
+ printCacheDetails("BUDDY FAILED");
+ }
+
+
+ /**
+ * Change some data for a select number of objects on the given cache.
+ *
+ * @param cache
+ */
+ private void executeBuddy(Cache<String, Integer> cache)
+ {
+ for (int i = 0; i < OBJECT_COUNT / 2; i++)
+ {
+ Integer integer = cache.get(Fqn.fromString(String.valueOf(i)), "counter");
+ cache.put(Fqn.fromString(String.valueOf(i)), "counter", integer.intValue() + 1);
+ }
+ }
+
+
+ /**
+ * Add inital state to a cache
+ *
+ * @param cache
+ */
+ private void addInitial(Cache<String, Integer> cache)
+ {
+ for (int i = 0; i < OBJECT_COUNT; i++)
+ {
+ cache.put(new Fqn<String>(String.valueOf(i)), "counter", new Integer(0));
+ }
+ }
+
+
+ /**
+ * Print all data to the log
+ *
+ * @param cache
+ */
+ private void checkRecoveredData(Cache<String, Integer> cache, int expectedValue)
+ {
+ log.info("*********** RECOVERED DATA ***********");
+ for (int i = 0; i < OBJECT_COUNT; i++)
+ {
+ Integer counter = cache.get(Fqn.fromString(String.valueOf(i)), "counter");
+ log.info("/" + i + " counter = " + counter);
+ assert i < 5 ? counter == expectedValue : counter == 0;
+ }
+ log.info("*********************************");
+ }
+
+
+ private void printCacheDetails(String state)
+ {
+ log.info("*********** " + state + " ***********");
+ if (cache1.getCacheStatus() == CacheStatus.STARTED)
+ {
+ log.info("--------- CACHE 1 (" + cache1.getLocalAddress() + ") ---------");
+ log.info(CachePrinter.printCacheDetails(cache1));
+ }
+ else
+ {
+ log.info("--------- CACHE 1 STOPPED");
+ }
+
+ if (cache2.getCacheStatus() == CacheStatus.STARTED)
+ {
+ log.info("--------- CACHE 2 (" + cache2.getLocalAddress() + ") ---------");
+ log.info(CachePrinter.printCacheDetails(cache2) + "\n\n");
+ }
+ else
+ {
+ log.info("--------- CACHE 2 STOPPED");
+ }
+ }
+}
16 years, 2 months