[jbosscache-commits] JBoss Cache SVN: r4687 - core/branches/1.4.X/tests/functional/org/jboss/cache/buddyreplication.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Oct 25 02:20:32 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-10-25 02:20:32 -0400 (Thu, 25 Oct 2007)
New Revision: 4687

Modified:
   core/branches/1.4.X/tests/functional/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
Log:
[JBCACHE-1194] Test data gravitation when nodes with the data are slow to respond

Modified: core/branches/1.4.X/tests/functional/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
===================================================================
--- core/branches/1.4.X/tests/functional/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java	2007-10-25 06:00:40 UTC (rev 4686)
+++ core/branches/1.4.X/tests/functional/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java	2007-10-25 06:20:32 UTC (rev 4687)
@@ -7,13 +7,18 @@
 package org.jboss.cache.buddyreplication;
 
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.jboss.cache.AbstractTreeCacheListener;
 import org.jboss.cache.TreeCache;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.config.Option;
+import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.marshall.JBCMethodCall;
+import org.jboss.cache.marshall.MethodDeclarations;
 import org.jboss.cache.misc.TestingUtil;
+import org.jgroups.blocks.MethodCall;
 
 /**
  * Tests behaviour when data owners fail - essentially this tests data gravitation
@@ -248,40 +253,77 @@
        assertNull("Backup should not exist on node3", caches[3].get(backupFqn, key));
        
        // Add a listener that will delay data gravitation from node0
-       BlockingListener listener0 = new BlockingListener();
-       caches[1].addTreeCacheListener(listener0);       
+       BlockingInterceptor interceptor0 = insertBlockingInterceptor(caches[0]);       
        
        // Add a listener that will delay data gravitation from node1
-       BlockingListener listener1 = new BlockingListener();
-       caches[1].addTreeCacheListener(listener1);
+       BlockingInterceptor interceptor1 = insertBlockingInterceptor(caches[1]);
        
        Option opt = new Option();
        opt.setForceDataGravitation(true);
-       assertEquals("Gravitation to node4 successful", value, caches[3].get(fqn, key, opt));
+       assertEquals("Gravitation to node4 successful", value, caches[3].get(fqn, key, opt));       
        
        // Just double-check the listeners worked as expected
-       assertNull("Listener0 saw no exception", listener0.exception);
-       assertNull("Listener1 saw no exception", listener1.exception);
-       assertTrue("Known issue JBCACHE-1192: listener0 blocked " + fqn, listener0.visited.contains(fqn));
-       assertTrue("Known issue JBCACHE-1192: listener1 blocked " + backupFqn, listener1.visited.contains(backupFqn));
+       synchronized (interceptor0.monitor)
+       {
+          interceptor0.monitor.notifyAll();
+       }
+       synchronized (interceptor1.monitor)
+       {
+          interceptor1.monitor.notifyAll();
+       }
+       
+       TestingUtil.sleepThread(5);
+       
+       assertNull("interceptor0 saw no exception", interceptor0.exception);
+       assertNull("interceptor1 saw no exception", interceptor1.exception);       
+       assertTrue("interceptor0 blocked " + fqn, interceptor0.blocked.contains(fqn));
+       assertTrue("interceptor1 blocked " + backupFqn, interceptor1.blocked.contains(backupFqn));
+       
+       
     }
     
-    private class BlockingListener extends AbstractTreeCacheListener
+    private BlockingInterceptor insertBlockingInterceptor(TreeCache cache)
     {
+       BlockingInterceptor interceptor = new BlockingInterceptor();
+       
+       List interceptors = cache.getInterceptors();
+       Interceptor first = (Interceptor) interceptors.get(0);
+       Interceptor next = first.getNext();
+       
+       interceptor.setNext(next);
+       first.setNext(interceptor);
+       
+       return interceptor;
+    }
+    
+    private class BlockingInterceptor extends Interceptor
+    {
       Exception exception = null;
-      Set visited = new HashSet();
+      Set blocked = new HashSet();
+      Object monitor = new Object();
       
-      public void nodeVisited(Fqn fqn)
-      {
-         try
+      public Object invoke(MethodCall m) throws Throwable
+      {         
+         JBCMethodCall call = (JBCMethodCall) m;
+         if (call.getMethodId() == MethodDeclarations.getNodeMethodLocal_id) 
          {
-            Thread.sleep(2000);
-            visited.add(fqn);            
+            try
+            {
+               Object[] args = call.getArgs();
+               Fqn fqn = (Fqn) args[0];
+               synchronized (monitor)
+               {
+                  monitor.wait(2000);
+               }      
+               blocked.add(fqn);
+            }
+            catch (Exception e)
+            {
+               exception = e;
+            }
+            
          }
-         catch (Exception e)
-         {
-            exception = e;
-         }
+         return super.invoke(m);
       }
        
     }




More information about the jbosscache-commits mailing list