[jbosscache-commits] JBoss Cache SVN: r5748 - core/trunk/src/test/java/org/jboss/cache/api.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Apr 29 09:06:47 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-29 09:06:47 -0400 (Tue, 29 Apr 2008)
New Revision: 5748

Modified:
   core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java
Log:
Improved to listen for view change notification before asserting whether coordinator has changed.

Modified: core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java	2008-04-29 13:04:49 UTC (rev 5747)
+++ core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java	2008-04-29 13:06:47 UTC (rev 5748)
@@ -6,14 +6,19 @@
 import org.jboss.cache.config.Configuration.CacheMode;
 import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
 import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.ViewChanged;
+import org.jboss.cache.notifications.event.ViewChangedEvent;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
- at Test(groups = {"functional"})
+ at Test(groups = "functional")
 public class CacheSPITest
 {
    private CacheSPI<Object, Object> cache1;
@@ -98,9 +103,31 @@
       cache2.start();
       assertTrue("Cache1 is still coordinator", cache1.getRPCManager().isCoordinator());
       assertFalse("Cache2 is not coordinator", cache2.getRPCManager().isCoordinator());
-
+      final CountDownLatch latch = new CountDownLatch(1);
+      ViewChangeNotifier notifier = new ViewChangeNotifier(latch);
+      cache2.addCacheListener(notifier);
       cache1.stop();
+      // wait till cache2 gets the view change notification
+      boolean viewChangeReceived = latch.await(60, TimeUnit.SECONDS);
+      assert viewChangeReceived : "Should have received a view change!";
       assertTrue("Cache2 is coordinator", cache2.getRPCManager().isCoordinator());
+   }
 
+   @CacheListener
+   public static class ViewChangeNotifier
+   {
+      CountDownLatch latch;
+
+      public ViewChangeNotifier(CountDownLatch latch)
+      {
+         this.latch = latch;
+      }
+
+      @ViewChanged
+      public void handleViewChange(ViewChangedEvent e)
+      {
+         if (!e.isPre()) latch.countDown();
+      }
    }
+
 }
\ No newline at end of file




More information about the jbosscache-commits mailing list