[jbosscache-commits] JBoss Cache SVN: r4877 - core/trunk/src/test/java/org/jboss/cache/api/pfer.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Wed Dec 19 07:57:49 EST 2007
Author: manik.surtani at jboss.com
Date: 2007-12-19 07:57:49 -0500 (Wed, 19 Dec 2007)
New Revision: 4877
Modified:
core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java
Log:
Added test for JBCACHE-1246
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-12-19 12:52:53 UTC (rev 4876)
+++ core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java 2007-12-19 12:57:49 UTC (rev 4877)
@@ -33,7 +33,7 @@
@Test(groups = {"functional", "jgroups", "transaction"})
public abstract class PutForExternalReadTestBase
{
- protected Cache<String, String> cache1, cache2;
+ protected CacheSPI<String, String> cache1, cache2;
protected TransactionManager tm1, tm2;
@@ -50,7 +50,7 @@
{
CacheFactory<String, String> cf = DefaultCacheFactory.getInstance();
- cache1 = cf.createCache(UnitTestCacheConfigurationFactory.createConfiguration(cacheMode), false);
+ cache1 = (CacheSPI<String, String>) cf.createCache(UnitTestCacheConfigurationFactory.createConfiguration(cacheMode), false);
cache1.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache1.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
cache1.getConfiguration().setSyncCommitPhase(optimistic);
@@ -59,7 +59,7 @@
cache1.start();
tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
- cache2 = cf.createCache(UnitTestCacheConfigurationFactory.createConfiguration(cacheMode), false);
+ cache2 = (CacheSPI<String, String>) cf.createCache(UnitTestCacheConfigurationFactory.createConfiguration(cacheMode), false);
cache2.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache2.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
cache2.getConfiguration().setSyncCommitPhase(optimistic);
@@ -148,9 +148,9 @@
asyncWait();
assertEquals("Parent node write should have succeeded", value2, cache1.get(parentFqn, key));
- if (isUsingInvalidation())
+ if (isUsingInvalidation())
assertNull("Parent node write should have invalidated", cache2.get(parentFqn, key));
- else
+ else
assertEquals("Parent node write should have replicated", value2, cache2.get(parentFqn, key));
if (!optimistic)
@@ -167,9 +167,9 @@
asyncWait();
assertEquals("PFER should have succeeded", value, cache1.get(fqn, key));
- if (isUsingInvalidation())
+ if (isUsingInvalidation())
assertNull("PFER should not have effected cache2", cache2.get(fqn, key));
- else
+ else
assertEquals("PFER should have replicated", value, cache2.get(fqn, key));
// reset
@@ -186,9 +186,9 @@
cache1.putForExternalRead(fqn, key, value2);
assertEquals("PFER should have been a no-op", value, cache1.get(fqn, key));
- if (isUsingInvalidation())
+ if (isUsingInvalidation())
assertNull("PFER should have been a no-op", cache2.get(fqn, key));
- else
+ else
assertEquals("PFER should have been a no-op", value, cache2.get(fqn, key));
}
@@ -212,7 +212,7 @@
// specify what we expect called on the mock Rpc Manager. For params we don't care about, just use ANYTHING.
// setting the mock object to expect the "sync" param to be false.
expect(rpcManager.getReplicationQueue()).andReturn(null);
- expect(rpcManager.callRemoteMethods(anyAddresses(), (Method)anyObject(), (Object[]) anyObject(), eq(false), anyBoolean(), anyInt())).andReturn(null);
+ expect(rpcManager.callRemoteMethods(anyAddresses(), (Method) anyObject(), (Object[]) anyObject(), eq(false), anyBoolean(), anyInt())).andReturn(null);
}
replay(rpcManager);
@@ -248,7 +248,7 @@
assertLocked(parentFqn, parentNode, workspace, false);
assertEquals("PFER should have completed", value, cache1.get(fqn, key));
- if (isUsingInvalidation())
+ if (isUsingInvalidation())
assertNull("PFER should not have effected cache2", cache2.get(fqn, key));
else
assertEquals("PFER should have completed", value, cache2.get(fqn, key));
@@ -259,7 +259,7 @@
asyncWait();
assertEquals("parent fqn tx should have completed", value, cache1.get(parentFqn, key));
- if (isUsingInvalidation())
+ 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));
@@ -311,73 +311,94 @@
// should not barf
cache1.putForExternalRead(fqn, key, value);
}
-
- public void testBasicPropagation() throws Exception {
-
+
+ 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
+ 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
+ public void testCacheModeLocalInTx() throws Exception
{
cacheModeLocalTest(true);
}
-
+
/**
+ * Tests that suspended transactions do not leak. See JBCACHE-1246.
+ *
+ * @throws Exception
+ */
+ public void testMemLeakOnSuspendedTransactions() throws Exception
+ {
+ tm1.begin();
+ cache1.putForExternalRead(fqn, key, value);
+ tm1.commit();
+
+ asyncWait();
+
+ assert cache1.getTransactionTable().getNumGlobalTransactions() == 0 : "Cache 1 should have no stale global TXs";
+ assert cache1.getTransactionTable().getNumLocalTransactions() == 0 : "Cache 1 should have no stale local TXs";
+ assert cache2.getTransactionTable().getNumGlobalTransactions() == 0 : "Cache 2 should have no stale global TXs";
+ assert cache2.getTransactionTable().getNumLocalTransactions() == 0 : "Cache 2 should have no stale local TXs";
+ }
+
+ /**
* Tests that setting a cacheModeLocal=true Option prevents propagation
* of the putForExternalRead().
+ *
* @throws Exception
*/
- private void cacheModeLocalTest(boolean transactional) 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);
@@ -428,10 +449,10 @@
{
TestingUtil.sleepThread(500);
}
-
- protected boolean isUsingInvalidation()
+
+ protected boolean isUsingInvalidation()
{
- return cacheMode == CacheMode.INVALIDATION_ASYNC
- || cacheMode == CacheMode.INVALIDATION_SYNC;
+ return cacheMode == CacheMode.INVALIDATION_ASYNC
+ || cacheMode == CacheMode.INVALIDATION_SYNC;
}
}
More information about the jbosscache-commits
mailing list