[jbosscache-commits] JBoss Cache SVN: r4673 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Tue Oct 23 13:02:47 EDT 2007
Author: manik.surtani at jboss.com
Date: 2007-10-23 13:02:47 -0400 (Tue, 23 Oct 2007)
New Revision: 4673
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
Log:
Added some more info on blocks
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2007-10-23 11:54:46 UTC (rev 4672)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2007-10-23 17:02:47 UTC (rev 4673)
@@ -6,24 +6,27 @@
*/
package org.jboss.cache.buddyreplication;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.notifications.annotation.CacheBlocked;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.CacheUnblocked;
+import org.jboss.cache.notifications.event.Event;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Teststhe transfer of content under *normal* operation
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
+ at Test (groups = {"functional"})
public class BuddyReplicationContentTest extends BuddyReplicationTestsBase
{
private String key = "key";
@@ -239,11 +242,19 @@
caches = null;
caches = createCaches(3, false, true);
+ CacheBlockListener blockListener = new CacheBlockListener();
+
+ caches.get(0).addCacheListener(blockListener);
+ caches.get(1).addCacheListener(blockListener);
+ caches.get(2).addCacheListener(blockListener);
+
caches.get(0).put("/0", "key", "value");
caches.get(1).put("/1", "key", "value");
caches.get(2).put("/2", "key", "value");
- TestingUtil.sleepThread(getSleepTimeout());
+// TestingUtil.sleepThread(getSleepTimeout());
+ //TestingUtil.sleepThread(caches.get(0).getConfiguration().getStateRetrievalTimeout() * 3);
+ blockListener.blockUntilAllCachesAreUnblocked(60000);
log.info("stopping 2");
caches.get(2).stop();
@@ -252,7 +263,9 @@
log.info("1 ** " + caches.get(1).printLockInfo());
log.info("2 ** " + caches.get(2).printLockInfo());
- TestingUtil.sleepThread(getSleepTimeout());
+// TestingUtil.sleepThread(getSleepTimeout());
+// TestingUtil.sleepThread(caches.get(0).getConfiguration().getStateRetrievalTimeout() * 3);
+ blockListener.blockUntilAllCachesAreUnblocked(60000);
assertEquals("value", caches.get(0).get("/2", "key"));
@@ -260,7 +273,9 @@
log.info("1 ** " + caches.get(1).printLockInfo());
log.info("2 ** " + caches.get(2).printLockInfo());
- TestingUtil.sleepThread(getSleepTimeout());
+// TestingUtil.sleepThread(getSleepTimeout());
+// TestingUtil.sleepThread(caches.get(0).getConfiguration().getStateRetrievalTimeout() * 3);
+ blockListener.blockUntilAllCachesAreUnblocked(60000);
caches.get(1).stop();
log.info("0 ** " + caches.get(0).printLockInfo());
@@ -285,4 +300,50 @@
assertEquals("value", caches.get(0).get("/1", "key"));
assertEquals("value", caches.get(0).get("/2", "key"));
}
+
+ @CacheListener
+ public static class CacheBlockListener
+ {
+ private int blocks = 0;
+ @CacheBlocked
+ public void processBlock(Event e)
+ {
+ if (e.isPre())
+ {
+ System.out.println(">>>>>>>> Got BLOCK on cache " + e.getCache().getLocalAddress());
+ synchronized (this)
+ {
+ blocks ++;
+ notifyAll();
+ }
+ }
+ }
+
+ @CacheUnblocked
+ public void processUnblock(Event e)
+ {
+ if (e.isPre())
+ {
+ System.out.println(">>>>>>>> Got UNBLOCK on cache " + e.getCache().getLocalAddress());
+ synchronized (this)
+ {
+ blocks --;
+ notifyAll();
+ }
+ }
+ }
+
+ public void blockUntilAllCachesAreUnblocked(long maxWait) throws InterruptedException
+ {
+ synchronized (this)
+ {
+ if (blocks != 0)
+ {
+ wait(maxWait);
+ }
+ if (blocks != 0)
+ throw new RuntimeException("Timed out waiting for unblocks. Number of blocks = " + blocks);
+ }
+ }
+ }
}
More information about the jbosscache-commits
mailing list