[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/statetransfer ...
Vladmir Blagojevic
vladimir.blagojevic at jboss.com
Tue Nov 14 14:56:09 EST 2006
User: vblagojevic
Date: 06/11/14 14:56:09
Modified: tests/functional/org/jboss/cache/statetransfer
VersionedTestBase.java
Log:
[JBCACHE-591] partial state transfer
Revision Changes Path
1.19 +200 -45 JBossCache/tests/functional/org/jboss/cache/statetransfer/VersionedTestBase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: VersionedTestBase.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/VersionedTestBase.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- VersionedTestBase.java 14 Nov 2006 14:17:11 -0000 1.18
+++ VersionedTestBase.java 14 Nov 2006 19:56:09 -0000 1.19
@@ -219,14 +219,8 @@
assertNull("/a/c name transferred against policy", cache2.get(A_C, "name"));
assertNull("/a/c age transferred against policy", cache2.get(A_C, "age"));
- // TODO: Reinstate once we have proper FLUSH working.
- // This test relies on calls to inactive regions being queued and re-run
- // when the region is activated. After discussions with Brian, the queueing
- // was removed, presuming FLUSH will fix this. Need to test with FLUSH.
- // - Manik Surtani (13 Oct 2006)
- /*
cache2.getRegion(A_B, true).activate();
- System.out.println("ERegion A_B on cache2: " + cache2.getRegion(A_B, false));
+ System.out.println("Region A_B on cache2: " + cache2.getRegion(A_B, false));
assertEquals("Incorrect name for /a/b", JOE, cache2.get(A_B, "name"));
assertEquals("Incorrect age for /a/b", TWENTY, cache2.get(A_B, "age"));
@@ -264,7 +258,7 @@
assertEquals("Incorrect name for /a/c", BOB, cache1.get(A_C, "name"));
assertEquals("Incorrect age for /a/c", FORTY, cache1.get(A_C, "age"));
assertEquals("Incorrect name for /a/d", JANE, cache1.get(A_D, "name"));
- */
+
}
public void testPartialStateTferWithLoader() throws Exception
@@ -292,13 +286,6 @@
assertNull("/a/c name transferred against policy", cache2.get(A_C, "name"));
assertNull("/a/c age transferred against policy", cache2.get(A_C, "age"));
- // TODO: Reinstate once we have proper FLUSH working.
- // This test relies on calls to inactive regions being queued and re-run
- // when the region is activated. After discussions with Brian, the queueing
- // was removed, presuming FLUSH will fix this. Need to test with FLUSH.
- // - Manik Surtani (13 Oct 2006)
-
-/*
cache2.getRegion(A_B, true).activate();
assertEquals("Incorrect name from loader for /a/b", JOE, loader.get(A_B).get("name"));
@@ -359,7 +346,7 @@
assertEquals("Incorrect age for /a/b", TWENTY, cache1.get(A_B, "age"));
assertEquals("Incorrect name for /a/c", BOB, cache1.get(A_C, "name"));
assertEquals("Incorrect age for /a/c", FORTY, cache1.get(A_C, "age"));
- assertEquals("Incorrect name for /a/d", JANE, cache1.get(A_D, "name"));*/
+ assertEquals("Incorrect name for /a/d", JANE, cache1.get(A_D, "name"));
}
public void testPartialStateTferWithClassLoader() throws Exception
@@ -410,19 +397,11 @@
Region r = cache2.getRegion(A, true);
r.registerContextClassLoader(cl2);
- // TODO: Reinstate once we have proper FLUSH working.
- // This test relies on calls to inactive regions being queued and re-run
- // when the region is activated. After discussions with Brian, the queueing
- // was removed, presuming FLUSH will fix this. Need to test with FLUSH.
- // - Manik Surtani (13 Oct 2006)
-
- /*
-
r.activate();
assertEquals("Correct state from loader for /a/b", ben.toString(), loader.get(A_B).get("person").toString());
- assertEquals("Correct state from cache for /a/b", ben.toString(), cache2.get(A_B, "person").toString());*/
+ assertEquals("Correct state from cache for /a/b", ben.toString(), cache2.get(A_B, "person").toString());
}
@@ -451,13 +430,6 @@
assertNull("/a/c name transferred against policy", cache2.get(A_C, "name"));
assertNull("/a/c age transferred against policy", cache2.get(A_C, "age"));
- // TODO: Reinstate once we have proper FLUSH working.
- // This test relies on calls to inactive regions being queued and re-run
- // when the region is activated. After discussions with Brian, the queueing
- // was removed, presuming FLUSH will fix this. Need to test with FLUSH.
- // - Manik Surtani (13 Oct 2006)
-
-/*
cache2.getRegion(Fqn.ROOT, true).activate();
assertEquals("Incorrect name from loader for /a/b", JOE, loader.get(A_B).get("name"));
@@ -469,8 +441,6 @@
assertEquals("Incorrect age for /a/b", TWENTY, cache2.get(A_B, "age"));
assertEquals("Incorrect name for /a/c", BOB, cache2.get(A_C, "name"));
assertEquals("Incorrect age for /a/c", FORTY, cache2.get(A_C, "age"));
- */
-
}
/**
@@ -482,7 +452,8 @@
*/
public void testConcurrentActivationSync() throws Exception
{
- // TODO: Needs revisiting after FLUSH
+ // TODO: Needs revisiting after concurrent FLUSH is supported
+ //http://jira.jboss.com/jira/browse/JGRP-332
//concurrentActivationTest(true);
}
@@ -495,7 +466,8 @@
*/
public void testConcurrentActivationAsync() throws Exception
{
- // TODO: Needs revisiting after FLUSH
+ // TODO: Needs revisiting after concurrent FLUSH is supported
+ //http://jira.jboss.com/jira/browse/JGRP-332
//concurrentActivationTest(false);
}
@@ -562,9 +534,13 @@
// Ensure the caches held by the activators see all the values
for (int i = 0; i < count; i++)
{
- if (activators[i].getException() != null && !(activators[i].getException() instanceof InactiveRegionException))
+ Exception aException = activators[i].getException();
+ boolean gotUnexpectedException = aException != null
+ && !(aException instanceof InactiveRegionException ||
+ aException.getCause() instanceof InactiveRegionException);
+ if (gotUnexpectedException)
{
- fail("Activator " + names[i] + " caught an exception " + activators[i].getException());
+ fail("Activator " + names[i] + " caught an exception " +aException);
}
for (int j = 0; j < count; j++)
@@ -590,6 +566,149 @@
}
/**
+ * Starts two caches where each cache has N regions. We put some data in each of the regions.
+ * We run two threads where each thread creates a cache then goes into a loop where it
+ * activates the N regions, with a 1 sec pause between activations.
+ *
+ * Threads are started with 10 sec difference.
+ *
+ * This test simulates a 10 sec staggered start of 2 servers in a cluster, with each server
+ * then deploying webapps.
+ *
+ *
+ * <p/>
+ * Failure condition is if any node sees an exception or if the final state
+ * of all caches is not consistent.
+ *
+ * @param sync use REPL_SYNC or REPL_ASYNC
+ * @throws Exception
+ */
+ private void concurrentActivationTest2(boolean sync) throws Exception
+ {
+ String[] names = {"A","B"};
+ int count = names.length;
+ int regionsToActivate = 15;
+ int sleepTimeBetweenNodeStarts = 10000;
+ StaggeredWebDeployerActivator[] activators = new StaggeredWebDeployerActivator[count];
+ try
+ {
+ // Create a semaphore and take all its tickets
+ Semaphore semaphore = new Semaphore(count);
+ for (int i = 0; i < count; i++)
+ {
+ semaphore.acquire();
+ }
+
+ // Create activation threads that will block on the semaphore
+ CacheSPI[] caches = new CacheSPI[count];
+ for (int i = 0; i < count; i++)
+ {
+ activators[i] = new StaggeredWebDeployerActivator(semaphore, names[i], sync,regionsToActivate);
+ caches[i] = activators[i].getCacheSPI();
+
+ // Release the semaphore to allow the thread to start working
+ semaphore.release(1);
+
+ activators[i].start();
+ TestingUtil.sleepThread(sleepTimeBetweenNodeStarts);
+ }
+
+ // Make sure everyone is in sync
+ TestingUtil.blockUntilViewsReceived(caches, 60000);
+
+ // Sleep to ensure the threads get all the semaphore tickets
+ TestingUtil.sleepThread(1000);
+
+ // Reacquire the semaphore tickets; when we have them all
+ // we know the threads are done
+ for (int i = 0; i < count; i++)
+ {
+ boolean acquired = semaphore.attempt(60000);
+ if (!acquired)
+ fail("failed to acquire semaphore " + i);
+ }
+
+ // Sleep to allow any async calls to clear
+ if (!sync)
+ TestingUtil.sleepThread(1000);
+
+ // Ensure the caches held by the activators see all the values
+ for (int i = 0; i < count; i++)
+ {
+ Exception aException = activators[i].getException();
+ boolean gotUnexpectedException = aException != null
+ && !(aException instanceof InactiveRegionException ||
+ aException.getCause() instanceof InactiveRegionException);
+ if (gotUnexpectedException)
+ {
+ fail("Activator " + names[i] + " caught an exception " +aException);
+ }
+
+ for (int j = 0; j < regionsToActivate; j++)
+ {
+ Fqn fqn = Fqn.fromString("/a/" + i + "/" + names[i]);
+ assertEquals("Incorrect value for " + fqn + " on activator " + names[i],
+ "VALUE", activators[i].getCacheValue(fqn));
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ fail(ex.getLocalizedMessage());
+ }
+ finally
+ {
+ for (int i = 0; i < count; i++)
+ activators[i].cleanup();
+ }
+
+ }
+
+ /**
+ * Starts two caches where each cache has N regions. We put some data in each of the regions.
+ * We run two threads where each thread creates a cache then goes into a loop where it
+ * activates the N regions, with a 1 sec pause between activations.
+ *
+ * Threads are started with 10 sec difference.
+ *
+ * This test simulates a 10 sec staggered start of 2 servers in a cluster, with each server
+ * then deploying webapps.
+ *
+ *
+ * <p/>
+ * Failure condition is if any node sees an exception or if the final state
+ * of all caches is not consistent.
+ *
+ *
+ */
+ public void testConcurrentStartupActivationAsync() throws Exception
+ {
+ concurrentActivationTest2(false);
+ }
+
+ /**
+ * Starts two caches where each cache has N regions. We put some data in each of the regions.
+ * We run two threads where each thread creates a cache then goes into a loop where it
+ * activates the N regions, with a 1 sec pause between activations.
+ *
+ * Threads are started with 10 sec difference.
+ *
+ * This test simulates a 10 sec staggered start of 2 servers in a cluster, with each server
+ * then deploying webapps.
+ *
+ *
+ * <p/>
+ * Failure condition is if any node sees an exception or if the final state
+ * of all caches is not consistent.
+ *
+ *
+ */
+ public void testConcurrentStartupActivationSync() throws Exception
+ {
+ concurrentActivationTest2(true);
+ }
+
+ /**
* Tests partial state transfer under heavy concurrent load and REPL_SYNC.
* See <code>concurrentUseTest</code> for details.
*
@@ -597,7 +716,8 @@
*/
public void testConcurrentUseSync() throws Exception
{
- // TODO: Needs revisiting after FLUSH
+ // TODO: Needs revisiting after concurrent FLUSH is supported
+ //http://jira.jboss.com/jira/browse/JGRP-332
//concurrentUseTest(true);
}
@@ -609,7 +729,8 @@
*/
public void testConcurrentUseAsync() throws Exception
{
- // TODO: Needs revisiting after FLUSH
+ // TODO: Needs revisiting after concurrent FLUSH is supported
+ //http://jira.jboss.com/jira/browse/JGRP-332
//concurrentUseTest(false);
}
@@ -775,6 +896,7 @@
void useCache() throws Exception
{
+ TestingUtil.sleepRandom(5000);
cache.getRegion(A_B, true).activate();
// System.out.println(name + " activated region" + " " + System.currentTimeMillis());
Fqn childFqn = Fqn.fromString("/a/b/" + name);
@@ -790,6 +912,39 @@
}
}
+ private class StaggeredWebDeployerActivator extends CacheUser
+ {
+
+ int regionCount = 15;
+ StaggeredWebDeployerActivator(Semaphore semaphore,
+ String name,
+ boolean sync,
+ int regionCount)
+ throws Exception
+ {
+ super(semaphore, name, sync, false);
+ this.regionCount = regionCount;
+ }
+
+ void useCache() throws Exception
+ {
+ for (int i = 0; i < regionCount; i++)
+ {
+ cache.getRegion(Fqn.fromString("/a/"+i), true).activate();
+
+ Fqn childFqn = Fqn.fromString("/a/" + i + "/" + name);
+ cache.put(childFqn, "KEY", "VALUE");
+
+ TestingUtil.sleepThread(1000);
+ }
+ }
+
+ public Object getCacheValue(Fqn fqn) throws CacheException
+ {
+ return cache.get(fqn, "KEY");
+ }
+ }
+
private class CacheStressor extends CacheUser
{
private Random random = new Random(System.currentTimeMillis());
More information about the jboss-cvs-commits
mailing list