Author: bstansberry(a)jboss.com
Date: 2007-10-16 10:27:56 -0400 (Tue, 16 Oct 2007)
New Revision: 4624
Modified:
core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java
Log:
[JBCACHE-1027] Add tests with invalidation
Add tests of cacheModeLocal
Modified:
core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java 2007-10-16
14:19:21 UTC (rev 4623)
+++
core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java 2007-10-16
14:27:56 UTC (rev 4624)
@@ -31,6 +31,7 @@
import org.jboss.cache.RPCManager;
import org.jboss.cache.RPCManagerImpl;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.misc.TestingUtil;
@@ -156,7 +157,10 @@
asyncWait();
assertEquals("Parent node write should have succeeded", value2,
cache1.get(parentFqn, key));
- assertEquals("Parent node write should have replicated", value2,
cache2.get(parentFqn, key));
+ if (isUsingInvalidation())
+ assertNull("Parent node write should have invalidated",
cache2.get(parentFqn, key));
+ else
+ assertEquals("Parent node write should have replicated", value2,
cache2.get(parentFqn, key));
if (!optimistic)
{
@@ -172,7 +176,10 @@
asyncWait();
assertEquals("PFER should have succeeded", value, cache1.get(fqn, key));
- assertEquals("PFER should have replicated", value, cache2.get(fqn,
key));
+ if (isUsingInvalidation())
+ assertNull("PFER should not have effected cache2", cache2.get(fqn,
key));
+ else
+ assertEquals("PFER should have replicated", value, cache2.get(fqn,
key));
// reset
cache1.removeNode(fqn);
@@ -188,7 +195,10 @@
cache1.putForExternalRead(fqn, key, value2);
assertEquals("PFER should have been a no-op", value, cache1.get(fqn,
key));
- assertEquals("PFER should have been a no-op", value, cache2.get(fqn,
key));
+ if (isUsingInvalidation())
+ assertNull("PFER should have been a no-op", cache2.get(fqn, key));
+ else
+ assertEquals("PFER should have been a no-op", value, cache2.get(fqn,
key));
}
private List<Address> anyAddresses()
@@ -242,7 +252,10 @@
assertLocked(parentFqn, parentNode, workspace, false);
assertEquals("PFER should have completed", value, cache1.get(fqn, key));
- assertEquals("PFER should have completed", value, cache2.get(fqn, key));
+ if (isUsingInvalidation())
+ assertNull("PFER should not have effected cache2", cache2.get(fqn,
key));
+ else
+ assertEquals("PFER should have completed", value, cache2.get(fqn,
key));
tm1.resume(t);
tm1.commit();
@@ -250,7 +263,10 @@
asyncWait();
assertEquals("parent fqn tx should have completed", value,
cache1.get(parentFqn, key));
- assertEquals("parent fqn tx should have completed", value,
cache2.get(parentFqn, key));
+ if (isUsingInvalidation())
+ assertNull("parent fqn tx should have invalidated cache2",
cache2.get(parentFqn, key));
+ else
+ assertEquals("parent fqn tx should have completed", value,
cache2.get(parentFqn, key));
}
public void testExceptionSuppression()
@@ -298,7 +314,79 @@
// should not barf
cache1.putForExternalRead(fqn, key, value);
}
+
+ public void testBasicPropagation() throws Exception {
+
+ cache1.putForExternalRead(fqn, key, value);
+
+ asyncWait();
+
+ assertEquals("PFER updated cache1", value, cache1.get(fqn, key));
+ Object expected = isUsingInvalidation() ? null : value;
+ assertEquals("PFER propagated to cache2 as expected", expected,
cache2.get(fqn, key));
+ cache2.putForExternalRead(fqn, key, value);
+
+ asyncWait();
+
+ assertEquals("PFER updated cache2", value, cache2.get(fqn, key));
+ assertEquals("PFER propagated to cache1 as expected", value,
cache1.get(fqn, key));
+ }
+
+ /**
+ * Tests that setting a cacheModeLocal=true Option prevents propagation
+ * of the putForExternalRead().
+ *
+ * @throws Exception
+ */
+ public void testSimpleCacheModeLocal() throws Exception
+ {
+ cacheModeLocalTest(false);
+ }
+
+ /**
+ * Tests that setting a cacheModeLocal=true Option prevents propagation
+ * of the putForExternalRead() when the call occurs inside a transaction.
+ *
+ * @throws Exception
+ */
+ public void testCacheModeLocalInTx() throws Exception
+ {
+ cacheModeLocalTest(true);
+ }
+
+ /**
+ * Tests that setting a cacheModeLocal=true Option prevents propagation
+ * of the putForExternalRead().
+ * @throws Exception
+ */
+ private void cacheModeLocalTest(boolean transactional) throws Exception
+ {
+ RPCManager rpcManager = EasyMock.createMock(RPCManager.class);
+ RPCManager originalRpcManager =
cache1.getConfiguration().getRuntimeConfig().getRPCManager();
+
+ // inject a mock RPC manager so that we can test whether calls made are sync or
async.
+ cache1.getConfiguration().getRuntimeConfig().setRPCManager(rpcManager);
+
+ // specify that we expect nothing will be called on the mock Rpc Manager.
+ replay(rpcManager);
+
+ // now try a simple replication. Since the RPCManager is a mock object it will not
actually replicate anything.
+ if (transactional)
+ tm1.begin();
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.putForExternalRead(fqn, key, value);
+
+ if (transactional)
+ tm1.commit();
+
+ verify(rpcManager);
+ // cleanup
+ cache1.getConfiguration().getRuntimeConfig().setRPCManager(originalRpcManager);
+ cache1.removeNode(fqn);
+ }
+
protected void assertLocked(Fqn fqn, NodeSPI n, TransactionWorkspace workspace,
boolean write_locked) throws Exception
{
// this needs to cater for "optimistically locked" nodes as well.
@@ -343,4 +431,10 @@
{
TestingUtil.sleepThread(500);
}
+
+ protected boolean isUsingInvalidation()
+ {
+ return cacheMode == CacheMode.INVALIDATION_ASYNC
+ || cacheMode == CacheMode.INVALIDATION_SYNC;
+ }
}