Author: manik.surtani(a)jboss.com
Date: 2008-01-09 11:30:05 -0500 (Wed, 09 Jan 2008)
New Revision: 5106
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
Log:
Modified test to verify JBCACHE-1226
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java 2008-01-09
16:16:24 UTC (rev 5105)
+++
core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java 2008-01-09
16:30:05 UTC (rev 5106)
@@ -45,7 +45,8 @@
* @author Brian Stansberry
* @version $Revision$
*/
-@Test(groups = {"functional"}, enabled = false) // this has always been
disabled since 1.4.x. See JBCACHE-315
+@Test(groups = {"functional"}, enabled = false)
+// this has always been disabled since 1.4.x. See JBCACHE-315
public class ForcedStateTransferTest extends StateTransferTestBase
{
/**
@@ -378,7 +379,7 @@
// Start threads that will do operations on the cache and then hang
TxRunner[] runners =
- initializeTransactionRunners(values, sender, "/LOCK", rollback);
+ initializeTransactionRunners(values, sender, "/LOCK", rollback);
// Create and start the cache that requests a state transfer
CacheSPI<Object, Object> receiver = startReceiver(isolationLevel, false,
false);
@@ -455,11 +456,11 @@
while (!(runner.isAsleep()))
{
assertTrue(runner.getClass().getName() + " " + runner.value +
- " is alive", runner.isAlive());
+ " is alive", runner.isAlive());
// Avoid hanging test fixture by only waiting 1 sec before failing
assertFalse(runner.getClass().getName() + " " + runner.value +
- " has not timed out",
- (System.currentTimeMillis() - start) > 1000);
+ " has not timed out",
+ (System.currentTimeMillis() - start) > 1000);
}
}
@@ -496,12 +497,12 @@
if (allowValues)
{
assertEquals("Correct value in " + runners[i].fqn,
- runners[i].value, receiver.get(runners[i].fqn, "KEY"));
+ runners[i].value, receiver.get(runners[i].fqn, "KEY"));
}
else
{
assertNull("No value in " + runners[i].fqn,
- receiver.get(runners[i].fqn, "KEY"));
+ receiver.get(runners[i].fqn, "KEY"));
}
}
}
@@ -595,7 +596,7 @@
String[] values = {"A", "B", "C"};
SynchronizationTxRunner[] runners =
- initializeSynchronizationTxRunners(values, sender, "/LOCK",
hangBefore);
+ initializeSynchronizationTxRunners(values, sender, "/LOCK",
hangBefore);
CacheSPI<Object, Object> receiver =
startReceiver("REPEATABLE_READ", false, false);
@@ -624,7 +625,7 @@
boolean
hangBefore)
{
SynchronizationTxRunner[] runners =
- new SynchronizationTxRunner[values.length];
+ new SynchronizationTxRunner[values.length];
for (int i = 0; i < values.length; i++)
{
runners[i] = new SynchronizationTxRunner(sender, rootFqn, values[i],
hangBefore);
@@ -704,23 +705,23 @@
// to catch; will create a separate locking test that shows it
String[] val1 = {"A", "B", "C"};
SynchronizationTxRunner[] after =
- initializeSynchronizationTxRunners(val1, sender, rootFqn, false);
+ initializeSynchronizationTxRunners(val1, sender, rootFqn, false);
String[] val2 = {"D", "E", "F"};
SynchronizationTxRunner[] before =
- initializeSynchronizationTxRunners(val2, sender, rootFqn, true);
+ initializeSynchronizationTxRunners(val2, sender, rootFqn, true);
String[] val3 = {"G", "H", "I"};
TxRunner[] active =
- initializeTransactionRunners(val3, sender, rootFqn, false);
+ initializeTransactionRunners(val3, sender, rootFqn, false);
String[] val4 = {"J", "K", "L"};
TxRunner[] rollback =
- initializeTransactionRunners(val4, sender, rootFqn, true);
+ initializeTransactionRunners(val4, sender, rootFqn, true);
String[] val5 = {"M", "N", "O"};
HangThreadRunner[] threads =
- initializeHangThreadRunners(val5, sender, rootFqn);
+ initializeHangThreadRunners(val5, sender, rootFqn);
CacheSPI<Object, Object> receiver = startReceiver(isolationLevel, replSync,
useMarshalling);
@@ -779,10 +780,10 @@
boolean replSync,
boolean useMarshalling,
boolean startCache)
- throws Exception
+ throws Exception
{
CacheSPI<Object, Object> result = super.createCache(cacheID, replSync,
- useMarshalling, false, false, false);
+ useMarshalling, false, false, false, true);
result.getConfiguration().setStateRetrievalTimeout(0);
result.getConfiguration().setLockAcquisitionTimeout(1000);
result.getConfiguration().setIsolationLevel(isolationLevel);
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java 2008-01-09
16:16:24 UTC (rev 5105)
+++
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java 2008-01-09
16:30:05 UTC (rev 5106)
@@ -7,6 +7,7 @@
package org.jboss.cache.statetransfer;
+import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
@@ -41,7 +42,7 @@
public void testBuddyBackupExclusion() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, false, false, false);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, false, false, false, true);
cache1.getConfiguration().setBuddyReplicationConfig(getBuddyConfig());
@@ -64,7 +65,7 @@
public void testBuddyIntegration() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, false, false, false);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, false, false, false, true);
cache1.getConfiguration().setBuddyReplicationConfig(getBuddyConfig());
cache1.start();
@@ -75,7 +76,7 @@
cache1.put(A_C, "name", JANE);
// now start up cache 2
- CacheSPI<Object, Object> cache2 = createCache("cache2", false,
false, false, false, false);
+ CacheSPI<Object, Object> cache2 = createCache("cache2", false,
false, false, false, false, true);
cache2.getConfiguration().setBuddyReplicationConfig(getBuddyConfig());
cache2.start();
@@ -93,7 +94,7 @@
@SuppressWarnings("null")
public void testCacheLoaderFailure() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, CorruptedFileCacheLoader.class.getName(), false, true);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, CorruptedFileCacheLoader.class.getName(), false, true, true);
cache1.put(A_B, "name", JOE);
cache1.put(A_B, "age", TWENTY);
@@ -103,7 +104,7 @@
CacheSPI cache2 = null;
try
{
- cache2 = createCache("cache2", false, false, true, false, false);
+ cache2 = createCache("cache2", false, false, true, false, false,
true);
cache2.create();
cache2.start();
@@ -360,7 +361,7 @@
false, // async
true, // use marshaller
true, // use cacheloader
- false, false);// don't start
+ false, false, true);// don't start
ClassLoader cl1 = getClassLoader();
cache1.getRegion(A, true).registerContextClassLoader(cl1);
startCache(cache1);
@@ -376,7 +377,7 @@
false, // async
true, // use marshalling
true, // use cacheloader
- false, true);// start
+ false, true, true);// start
// Pause to give caches time to see each other
TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
@@ -401,6 +402,35 @@
}
+ public void testStalePersistentState() throws Exception
+ {
+ CacheSPI c1 = createCache("1", true, false, true, false);
+ c1.put(A, "K", "V");
+
+ assert c1.get(A, "K").equals("V");
+ CacheLoader l1 = c1.getCacheLoaderManager().getCacheLoader();
+ assert l1 != null;
+
+ assert l1.exists(A);
+ assert l1.get(A).get("K").equals("V");
+
+ // test persistence
+ c1.stop();
+
+ assert l1.exists(A);
+ assert l1.get(A).get("K").equals("V");
+
+ Cache c2 = createCache("2", true, false, true, false);
+
+ c2.put(B, "K", "V");
+
+ c1.start();
+
+ assert c1.get(B, "K").equals("V");
+ assert c1.get(A, "K") == null;
+ assert !l1.exists(A);
+ }
+
private Object createBen(ClassLoader loader) throws Exception
{
Class addrClazz = loader.loadClass(ADDRESS_CLASSNAME);
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java 2008-01-09
16:16:24 UTC (rev 5105)
+++
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java 2008-01-09
16:30:05 UTC (rev 5106)
@@ -87,29 +87,38 @@
boolean useCacheLoader)
throws Exception
{
- return createCache(cacheID, sync, useMarshalling, useCacheLoader, false, true);
+ return createCache(cacheID, sync, useMarshalling, useCacheLoader, false, true,
true);
}
protected CacheSPI<Object, Object> createCache(String cacheID,
boolean sync,
boolean useMarshalling,
+ boolean useCacheLoader, boolean
fetchPersistentState)
+ throws Exception
+ {
+ return createCache(cacheID, sync, useMarshalling, useCacheLoader, false, true,
fetchPersistentState);
+ }
+
+ protected CacheSPI<Object, Object> createCache(String cacheID,
+ boolean sync,
+ boolean useMarshalling,
boolean useCacheLoader,
boolean cacheLoaderAsync,
- boolean startCache)
+ boolean startCache, boolean
fetchPersistentState)
throws Exception
{
if (useCacheLoader)
{
- return createCache(cacheID, sync, useMarshalling,
"org.jboss.cache.loader.FileCacheLoader", cacheLoaderAsync, startCache);
+ return createCache(cacheID, sync, useMarshalling,
"org.jboss.cache.loader.FileCacheLoader", cacheLoaderAsync, startCache,
fetchPersistentState);
}
else
{
- return createCache(cacheID, sync, useMarshalling, null, cacheLoaderAsync,
startCache);
+ return createCache(cacheID, sync, useMarshalling, null, cacheLoaderAsync,
startCache, fetchPersistentState);
}
}
protected CacheSPI<Object, Object> createCache(String cacheID, boolean sync,
boolean useMarshalling, String cacheLoaderClass,
- boolean cacheLoaderAsync, boolean
startCache) throws Exception
+ boolean cacheLoaderAsync, boolean
startCache, boolean fetchPersistentState) throws Exception
{
if (caches.get(cacheID) != null)
{
@@ -134,7 +143,7 @@
}
if (cacheLoaderClass != null && cacheLoaderClass.length() > 0)
{
- configureCacheLoader(c, cacheLoaderClass, cacheID, cacheLoaderAsync);
+ configureCacheLoader(c, cacheLoaderClass, cacheID, cacheLoaderAsync,
fetchPersistentState);
}
// tree.setConfiguration(c);
//c.setLockAcquisitionTimeout(60000);
@@ -201,11 +210,11 @@
boolean async)
throws Exception
{
- configureCacheLoader(c, "org.jboss.cache.loader.FileCacheLoader",
cacheID, async);
+ configureCacheLoader(c, "org.jboss.cache.loader.FileCacheLoader",
cacheID, async, true);
}
protected void configureCacheLoader(Configuration c, String cacheloaderClass, String
cacheID,
- boolean async) throws Exception
+ boolean async, boolean fetchPersistentState)
throws Exception
{
if (cacheloaderClass != null)
{
@@ -243,21 +252,21 @@
tmp_location = escapeWindowsPath(tmp_location);
String props = "location = " + tmp_location + "\n";
- c.setCacheLoaderConfig(getSingleCacheLoaderConfig("",
cacheloaderClass, props, async, true, false));
+ c.setCacheLoaderConfig(getSingleCacheLoaderConfig("",
cacheloaderClass, props, async, fetchPersistentState, false));
}
}
}
protected void initialStateTferWithLoaderTest(String cacheLoaderClass1, String
cacheLoaderClass2, boolean asyncLoader) throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, cacheLoaderClass1, false, true);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false,
false, cacheLoaderClass1, false, true, true);
cache1.put(A_B, "name", JOE);
cache1.put(A_B, "age", TWENTY);
cache1.put(A_C, "name", BOB);
cache1.put(A_C, "age", FORTY);
- CacheSPI<Object, Object> cache2 = createCache("cache2", false,
false, cacheLoaderClass2, asyncLoader, false);
+ CacheSPI<Object, Object> cache2 = createCache("cache2", false,
false, cacheLoaderClass2, asyncLoader, false, true);
cache2.start();