[jbosscache-commits] JBoss Cache SVN: r7114 - core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Tue Nov 11 15:37:22 EST 2008
Author: mircea.markus
Date: 2008-11-11 15:37:22 -0500 (Tue, 11 Nov 2008)
New Revision: 7114
Modified:
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationOptLocksTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplOptLocksTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplPessLocksTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationOptLocksTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationPessLocksTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplOptLocksTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplPessLocksTest.java
Log:
added replication listeners for async replication to fix intermittent test failures
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationOptLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationOptLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationOptLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -8,6 +8,8 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.CacheSPI;
import org.testng.annotations.Test;
@Test (groups = "functional", testName = "cachemodelocal.AsyncInvalidationOptLocksTest")
@@ -20,7 +22,12 @@
isInvalidation = true;
}
- protected void delay()
+ protected void registerReplicationCommand(CacheSPI<String, String> cache2, Class<? extends ReplicableCommand> what)
+ {
+ //do nothing
+ }
+
+ protected void verifyReplication()
{
TestingUtil.sleepThread(500);
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -8,6 +8,8 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.CacheSPI;
import org.testng.annotations.Test;
@Test(groups = "functional", testName = "options.cachemodelocal.AsyncInvalidationPessLocksTest")
@@ -20,8 +22,13 @@
isInvalidation = true;
}
- protected void delay()
+ protected void registerReplicationCommand(CacheSPI<String, String> cache2, Class<? extends ReplicableCommand> what)
{
+ //do nothing
+ }
+
+ protected void verifyReplication()
+ {
TestingUtil.sleepThread(500);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplOptLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplOptLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplOptLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -8,13 +8,12 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.CacheSPI;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
-import javax.transaction.TransactionManager;
-
@Test(groups = {"functional", "jgroups"}, testName = "options.cachemodelocal.AsyncReplOptLocksTest")
public class AsyncReplOptLocksTest extends CacheModeLocalTestBase
{
@@ -24,7 +23,7 @@
nodeLockingScheme = "OPTIMISTIC";
}
- protected void delay()
+ protected void verifyReplication()
{
TestingUtil.sleepThread(500);
}
@@ -89,4 +88,9 @@
super.testAddChild();
}
+ protected void registerReplicationCommand(CacheSPI<String, String> cache2, Class<? extends ReplicableCommand> what)
+ {
+ //do nothing
+ }
+
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplPessLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplPessLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncReplPessLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -7,20 +7,59 @@
package org.jboss.cache.options.cachemodelocal;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.ReplicationListener;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.commands.legacy.write.PessPutDataMapCommand;
+import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
+import org.jboss.cache.commands.legacy.write.PessRemoveKeyCommand;
+import org.jboss.cache.commands.legacy.write.PessRemoveNodeCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Cache;
import org.testng.annotations.Test;
+import java.util.Map;
+import java.util.HashMap;
+
@Test(groups = {"functional", "jgroups"}, testName = "options.cachemodelocal.AsyncReplPessLocksTest")
public class AsyncReplPessLocksTest extends CacheModeLocalTestBase
{
- public AsyncReplPessLocksTest()
- {
- cacheMode = Configuration.CacheMode.REPL_ASYNC;
- nodeLockingScheme = "PESSIMISTIC";
- }
- protected void delay()
- {
- TestingUtil.sleepThread(500);
- }
+ ReplicationListener current;
+
+ Map<Cache, ReplicationListener> cache2Listener = new HashMap<Cache, ReplicationListener>(2);
+
+ public AsyncReplPessLocksTest()
+ {
+ cacheMode = Configuration.CacheMode.REPL_ASYNC;
+ nodeLockingScheme = "PESSIMISTIC";
+ }
+
+ protected void registerReplicationCommand(CacheSPI<String, String> cache, Class<? extends ReplicableCommand> what)
+ {
+ if (what == PutDataMapCommand.class) what = PessPutDataMapCommand.class;
+ if (what == PutKeyValueCommand.class) what = PessPutKeyValueCommand.class;
+ if (what == RemoveKeyCommand.class) what = PessRemoveKeyCommand.class;
+ if (what == RemoveNodeCommand.class) what = PessRemoveNodeCommand.class;
+ getCacheListener(cache).expect(what);
+ }
+
+ protected void verifyReplication()
+ {
+ current.waitForReplicationToOccur(2000);
+ }
+
+ public ReplicationListener getCacheListener(Cache cache)
+ {
+ current = cache2Listener.get(cache);
+ if (current == null)
+ {
+ current = new ReplicationListener(cache);
+ cache2Listener.put(cache, current);
+ }
+ return current;
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -12,6 +12,11 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
@@ -52,23 +57,23 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
-
+
CacheSPI<String, String> cache1 = cache1TL.get();
CacheSPI<String, String> cache2 = cache2TL.get();
-
+
// force a tear down if the test runner didn't run one before (happens in IDEA)
if (cache1 != null || cache2 != null)
tearDown();
CacheFactory<String, String> instance = new UnitTestCacheFactory<String, String>();
-
+
Configuration c = new Configuration();
c.setClusterName("test");
c.setStateRetrievalTimeout(1000);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
c.setNodeLockingScheme(nodeLockingScheme);
c.setCacheMode(cacheMode);
-
+
cache1 = (CacheSPI<String, String>) instance.createCache(c, false);
cache1.start();
@@ -78,13 +83,13 @@
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
c.setNodeLockingScheme(nodeLockingScheme);
c.setCacheMode(cacheMode);
-
+
cache2 = (CacheSPI<String, String>) instance.createCache(c, false);
cache2.start();
cache1TL.set(cache1);
cache2TL.set(cache2);
-
+
root1TL.set(cache1.getRoot());
root2TL.set(cache2.getRoot());
}
@@ -107,7 +112,8 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.put(fqn, key, "value");
- delay();
+ Thread.sleep(500);
+
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
@@ -115,9 +121,10 @@
assertNull("Should be null", cache2.get(fqn, key));
// now try again with passing the default options
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
cache1.getInvocationContext().getOptionOverrides().reset();
cache1.put(fqn, key, "value");
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
@@ -134,13 +141,14 @@
// now cache2
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache2.put(fqn, key, "value2");
- delay();
+ Thread.sleep(500);
assertEquals("value2", cache2.get(fqn, key));
assertEquals("value", cache1.get(fqn, key));
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
cache2.getInvocationContext().getOptionOverrides().reset();
cache2.put(fqn, key, "value2");
- delay();
+ verifyReplication();
assertEquals("value2", cache2.get(fqn, key));
if (!isInvalidation)
{
@@ -158,11 +166,11 @@
CacheSPI<String, String> cache2 = cache2TL.get();
NodeSPI<String, String> root1 = root1TL.get();
NodeSPI<String, String> root2 = root2TL.get();
-
+
Node node1 = root1.addChild(fqn);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node1.put(key, "value");
- delay();
+ Thread.sleep(500);
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
@@ -170,9 +178,10 @@
assertNull("Should be null", cache2.get(fqn, key));
// now try again with passing the default options
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
cache1.getInvocationContext().getOptionOverrides().reset();
node1.put(key, "value");
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
@@ -191,13 +200,15 @@
Node node2 = root2.addChild(fqn);
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node2.put(key, "value2");
- delay();
+ Thread.sleep(500);
+
assertEquals("value2", cache2.get(fqn, key));
assertEquals("value", cache1.get(fqn, key));
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
cache2.getInvocationContext().getOptionOverrides().reset();
node2.put(key, "value2");
- delay();
+ verifyReplication();
assertEquals("value2", cache2.get(fqn, key));
if (!isInvalidation)
{
@@ -219,16 +230,17 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.put(fqn, map);
- delay();
+ Thread.sleep(500);
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
// cache 2 should not
assertNull("Should be null", cache2.get(fqn, key));
// now try again with passing the default options
+ registerReplicationCommand(cache2, PutDataMapCommand.class);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
cache1.put(fqn, map);
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
// cache 2 should as well
@@ -245,13 +257,15 @@
map.put(key, "value2");
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache2.put(fqn, map);
- delay();
+ Thread.sleep(500);
+
assertEquals("value2", cache2.get(fqn, key));
assertEquals("value", cache1.get(fqn, key));
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
cache2.getInvocationContext().getOptionOverrides().reset();
cache2.put(fqn, key, "value2");
- delay();
+ verifyReplication();
assertEquals("value2", cache2.get(fqn, key));
if (!isInvalidation)
{
@@ -276,16 +290,17 @@
Node node1 = root1.addChild(fqn);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node1.putAll(map);
- delay();
+ Thread.sleep(500);
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
// cache 2 should not
assertNull("Should be null", cache2.get(fqn, key));
// now try again with passing the default options
+ registerReplicationCommand(cache2, PutDataMapCommand.class);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
node1.putAll(map);
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
// cache 2 should as well
@@ -304,13 +319,15 @@
map.put(key, "value2");
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node2.putAll(map);
- delay();
+ Thread.sleep(500);
+
assertEquals("value2", cache2.get(fqn, key));
assertEquals("value", cache1.get(fqn, key));
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
cache2.getInvocationContext().getOptionOverrides().reset();
node2.put(key, "value2");
- delay();
+ verifyReplication();
assertEquals("value2", cache2.get(fqn, key));
if (!isInvalidation)
{
@@ -329,9 +346,10 @@
// put some stuff in the cache first
// make sure we cleanup thread local vars.
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
cache1.getInvocationContext().setOptionOverrides(null);
cache1.put(fqn, key, "value");
- delay();
+ verifyReplication();
assertEquals("value", cache1.get(fqn, key));
if (isInvalidation)
{
@@ -344,7 +362,7 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.removeNode(fqn);
- delay();
+ Thread.sleep(500);
// should be removed in cache1
assertNull("should be null", cache1.get(fqn, key));
@@ -359,8 +377,9 @@
}
// replace cache entries
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
cache1.put(fqn, key, "value");
- delay();
+ verifyReplication();
assertEquals("value", cache1.get(fqn, key));
if (isInvalidation)
{
@@ -372,9 +391,10 @@
}
// now try again with passing the default options
+ registerReplicationCommand(cache2, RemoveNodeCommand.class);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
cache1.removeNode(fqn);
- delay();
+ verifyReplication();
// both should be null
assertNull("should be null", cache1.get(fqn, key));
@@ -390,10 +410,11 @@
// put some stuff in the cache first
// make sure we cleanup thread local vars.
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
cache1.getInvocationContext().setOptionOverrides(null);
cache1.put(fqn, key, "value");
- delay();
assertEquals("value", cache1.get(fqn, key));
+ verifyReplication();
if (isInvalidation)
{
assertNull("Should be null", cache2.get(fqn, key));
@@ -405,7 +426,7 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
root1.removeChild(fqn);
- delay();
+ Thread.sleep(500);
// should be removed in cache1
assertNull("should be null", cache1.get(fqn, key));
@@ -420,8 +441,9 @@
}
// replace cache entries
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
cache1.put(fqn, key, "value");
- delay();
+ verifyReplication();
assertEquals("value", cache1.get(fqn, key));
if (isInvalidation)
{
@@ -432,10 +454,11 @@
assertEquals("value", cache2.get(fqn, key));
}
+ registerReplicationCommand(cache2, RemoveNodeCommand.class);
// now try again with passing the default options
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
root1.removeChild(fqn);
- delay();
+ verifyReplication();
// both should be null
assertNull("should be null", cache1.get(fqn, key));
@@ -447,10 +470,11 @@
CacheSPI<String, String> cache1 = cache1TL.get();
CacheSPI<String, String> cache2 = cache2TL.get();
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
// put some stuff in the cache first
cache1.getInvocationContext().setOptionOverrides(null);
cache1.put(fqn, key, "value");
- delay();
+ verifyReplication();
assertEquals("value", cache1.get(fqn, key));
if (isInvalidation)
{
@@ -463,7 +487,7 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.remove(fqn, key);
- delay();
+ Thread.sleep(500);
// should be removed in cache1
assertNull("should be null", cache1.get(fqn, key));
@@ -477,9 +501,10 @@
assertEquals("value", cache2.get(fqn, key));
}
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
// replace cache entries
cache1.put(fqn, key, "value");
- delay();
+ verifyReplication();
assertEquals("value", cache1.get(fqn, key));
if (isInvalidation)
{
@@ -490,10 +515,11 @@
assertEquals("value", cache2.get(fqn, key));
}
+ registerReplicationCommand(cache2, RemoveKeyCommand.class);
// now try again with passing the default options
cache1.getInvocationContext().getOptionOverrides().reset();
cache1.remove(fqn, key);
- delay();
+ verifyReplication();
// both should be null
assertNull("should be null", cache1.get(fqn, key));
@@ -508,10 +534,11 @@
NodeSPI<String, String> root2 = root2TL.get();
// put some stuff in the cache first
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
Node node1 = root1.addChild(fqn);
cache1.getInvocationContext().setOptionOverrides(null);
node1.put(key, "value");
- delay();
+ verifyReplication();
assertEquals("value", cache1.get(fqn, key));
if (isInvalidation)
{
@@ -524,7 +551,7 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node1.remove(key);
- delay();
+ Thread.sleep(500);
// should be removed in cache1
assertNull("should be null", cache1.get(fqn, key));
@@ -539,8 +566,9 @@
}
// replace cache entries
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
node1.put(key, "value");
- delay();
+ verifyReplication();
assertEquals("value", cache1.get(fqn, key));
if (isInvalidation)
{
@@ -552,9 +580,10 @@
}
// now try again with passing the default options
+ registerReplicationCommand(cache2, RemoveKeyCommand.class);
cache1.getInvocationContext().getOptionOverrides().reset();
node1.remove(key);
- delay();
+ verifyReplication();
// both should be null
assertNull("should be null", cache1.get(fqn, key));
@@ -567,13 +596,14 @@
CacheSPI<String, String> cache2 = cache2TL.get();
TransactionManager mgr = cache1.getTransactionManager();
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
mgr.begin();
cache1.getInvocationContext().getOptionOverrides().reset();
cache1.put(fqn, key, "value1");
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.put(fqn, key, "value2");
mgr.commit();
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value2", cache1.get(fqn, key));
@@ -586,6 +616,7 @@
assertNull(cache2.get(fqn, key));
}
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
// now try again with passing the default options
mgr.begin();
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
@@ -593,7 +624,7 @@
cache1.getInvocationContext().getOptionOverrides().reset();
cache1.put(fqn, key, "value");
mgr.commit();
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
@@ -608,6 +639,7 @@
}
// now cache2
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
mgr = cache2.getTransactionManager();
mgr.begin();
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
@@ -615,7 +647,7 @@
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache2.put(fqn, key, "value2");
mgr.commit();
- delay();
+ verifyReplication();
assertEquals("value2", cache2.get(fqn, key));
@@ -628,13 +660,14 @@
assertNull(cache1.get(fqn, key));
}
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
mgr.begin();
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache2.put(fqn, key, "value2");
cache2.getInvocationContext().getOptionOverrides().reset();
cache2.put(fqn, key, "value4");
mgr.commit();
- delay();
+ verifyReplication();
assertEquals("value4", cache2.get(fqn, key));
if (!isInvalidation)
{
@@ -657,14 +690,16 @@
// create these first ...
cache1.put("/a", key, "old");
cache1.put("/b", key, "old");
- delay();
+ Thread.sleep(500);
+
+
mgr.begin();
cache1.getInvocationContext().getOptionOverrides().reset();
cache1.put("/a", key, "value1");
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.put("/b", key, "value2");
mgr.rollback();
- delay();
+ Thread.sleep(500);
// cache1 should NOT have this
assert cache1.get("/a", key).equals("old");
assert cache1.get("/b", key).equals("old");
@@ -689,6 +724,7 @@
NodeSPI<String, String> root2 = root2TL.get();
Node node1 = root1.addChild(fqn);
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
TransactionManager mgr = cache1.getTransactionManager();
mgr.begin();
cache1.getInvocationContext().getOptionOverrides().reset();
@@ -696,7 +732,7 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node1.put(key, "value2");
mgr.commit();
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value2", cache1.get(fqn, key));
@@ -710,13 +746,14 @@
}
// now try again with passing the default options
+ registerReplicationCommand(cache2, PutKeyValueCommand.class);
mgr.begin();
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node1.put(key, "value3");
cache1.getInvocationContext().getOptionOverrides().reset();
node1.put(key, "value");
mgr.commit();
- delay();
+ verifyReplication();
// cache1 should still have this
assertEquals("value", cache1.get(fqn, key));
@@ -733,13 +770,14 @@
// now cache2
Node node2 = root2.addChild(fqn);
mgr = cache2.getTransactionManager();
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
mgr.begin();
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
node2.put(key, "value3");
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node2.put(key, "value2");
mgr.commit();
- delay();
+ verifyReplication();
assertEquals("value2", cache2.get(fqn, key));
@@ -752,13 +790,14 @@
assertNull(cache1.get(fqn, key));
}
+ registerReplicationCommand(cache1, PutKeyValueCommand.class);
mgr.begin();
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node2.put(key, "value2");
cache2.getInvocationContext().getOptionOverrides().reset();
node2.put(key, "value4");
mgr.commit();
- delay();
+ verifyReplication();
assertEquals("value4", cache2.get(fqn, key));
if (!isInvalidation)
{
@@ -780,7 +819,7 @@
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
root1.addChild(fqn);
- delay();
+ Thread.sleep(1000);
// cache1 should still have this
assertTrue(root1.hasChild(fqn));
// cache 2 should not
@@ -790,8 +829,11 @@
// now try again with passing the default options
root1.removeChild(fqn);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+
+ registerReplicationCommand(cache2, PutDataMapCommand.class);
root1.addChild(fqn);
- delay();
+ verifyReplication();
+
// cache1 should still have this
assertTrue(root1.hasChild(fqn));
// cache 2 should as well
@@ -805,6 +847,18 @@
}
}
- protected abstract void delay();
+ /**
+ * Register a command that should be received by the specified cache as the result of a replication taking place.
+ * @param cache the cache on which the given command should be replicated.
+ * @param what the command that should be replicated
+ * @see org.jboss.cache.options.cachemodelocal.AsyncReplPessLocksTest#registerReplicationCommand(org.jboss.cache.CacheSPI, Class)
+ */
+ protected abstract void registerReplicationCommand(CacheSPI<String, String> cache, Class<? extends ReplicableCommand> what);
+
+ /**
+ * Wait a while until the give command gets replicated.
+ * @see AsyncReplPessLocksTest#verifyReplication()
+ */
+ protected abstract void verifyReplication();
}
\ No newline at end of file
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationOptLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationOptLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationOptLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -7,6 +7,8 @@
package org.jboss.cache.options.cachemodelocal;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.CacheSPI;
import org.testng.annotations.Test;
@Test(groups = {"functional", "jgroups"}, testName = "options.cachemodelocal.SyncInvalidationOptLocksTest")
@@ -19,7 +21,12 @@
isInvalidation = true;
}
- protected void delay()
+ protected void registerReplicationCommand(CacheSPI<String, String> cache2, Class<? extends ReplicableCommand> what)
+ {
+ //do nothing
+ }
+
+ protected void verifyReplication()
{
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationPessLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationPessLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncInvalidationPessLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -7,6 +7,8 @@
package org.jboss.cache.options.cachemodelocal;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.CacheSPI;
import org.testng.annotations.Test;
@Test(groups = {"functional", "jgroups"}, testName = "options.cachemodelocal.SyncInvalidationPessLocksTest")
@@ -19,7 +21,12 @@
isInvalidation = true;
}
- protected void delay()
+ protected void registerReplicationCommand(CacheSPI<String, String> cache2, Class<? extends ReplicableCommand> what)
+ {
+ //do nothing
+ }
+
+ protected void verifyReplication()
{
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplOptLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplOptLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplOptLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -8,6 +8,8 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.CacheSPI;
import org.testng.annotations.Test;
@Test(groups = {"functional", "jgroups"}, testName = "options.cachemodelocal.SyncReplOptLocksTest")
@@ -19,7 +21,12 @@
nodeLockingScheme = "OPTIMISTIC";
}
- protected void delay()
+ protected void registerReplicationCommand(CacheSPI<String, String> cache2, Class<? extends ReplicableCommand> what)
+ {
+ //do nothing
+ }
+
+ protected void verifyReplication()
{
TestingUtil.sleepThread(250);
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplPessLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplPessLocksTest.java 2008-11-11 17:19:39 UTC (rev 7113)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/SyncReplPessLocksTest.java 2008-11-11 20:37:22 UTC (rev 7114)
@@ -7,6 +7,8 @@
package org.jboss.cache.options.cachemodelocal;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.CacheSPI;
import org.testng.annotations.Test;
@Test(groups = {"functional", "jgroups"}, testName = "options.cachemodelocal.SyncReplPessLocksTest")
@@ -18,7 +20,12 @@
nodeLockingScheme = "PESSIMISTIC";
}
- protected void delay()
+ protected void registerReplicationCommand(CacheSPI<String, String> cache2, Class<? extends ReplicableCommand> what)
+ {
+ //do nothing
+ }
+
+ protected void verifyReplication()
{
}
}
More information about the jbosscache-commits
mailing list