[infinispan-commits] Infinispan SVN: r1720 - in trunk/core/src: test/java/org/infinispan/notifications/cachemanagerlistener and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Apr 23 03:47:07 EDT 2010


Author: galder.zamarreno at jboss.com
Date: 2010-04-23 03:47:07 -0400 (Fri, 23 Apr 2010)
New Revision: 1720

Modified:
   trunk/core/src/main/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java
   trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java
Log:
[ISPN-410] (Event.getCacheManager() always returns null) Fixed. @Inject was missing in injectCacheManager method.

Modified: trunk/core/src/main/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java	2010-04-22 16:42:35 UTC (rev 1719)
+++ trunk/core/src/main/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java	2010-04-23 07:47:07 UTC (rev 1720)
@@ -1,5 +1,6 @@
 package org.infinispan.notifications.cachemanagerlistener;
 
+import org.infinispan.factories.annotations.Inject;
 import org.infinispan.factories.annotations.Stop;
 import org.infinispan.manager.CacheManager;
 import org.infinispan.notifications.AbstractListenerImpl;
@@ -51,6 +52,7 @@
       listenersMap.put(ViewChanged.class, viewChangedListeners);
    }
 
+   @Inject
    public void injectCacheManager(CacheManager cacheManager) {
       this.cacheManager = cacheManager;
    }

Modified: trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java	2010-04-22 16:42:35 UTC (rev 1719)
+++ trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java	2010-04-23 07:47:07 UTC (rev 1720)
@@ -5,6 +5,9 @@
 import org.infinispan.Cache;
 import org.infinispan.config.Configuration;
 import org.infinispan.manager.CacheManager;
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged;
+import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
 import org.infinispan.remoting.transport.Address;
 import org.infinispan.test.AbstractInfinispanTest;
 import org.infinispan.test.TestingUtil;
@@ -14,6 +17,9 @@
 import org.testng.annotations.Test;
 
 import java.util.List;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
 
 @Test(groups = "unit", testName = "notifications.cachemanagerlistener.CacheManagerNotifierTest")
 public class CacheManagerNotifierTest extends AbstractInfinispanTest {
@@ -25,7 +31,7 @@
       TestingUtil.killCacheManagers(cm1, cm2);
    }
 
-   public void testViewChange() {
+   public void testMockViewChange() {
       cm1 = TestCacheManagerFactory.createClusteredCacheManager();
       cm2 = TestCacheManagerFactory.createClusteredCacheManager();
       Configuration c = new Configuration();
@@ -57,7 +63,7 @@
       }
    }
 
-   public void testCacheStartedAndStopped() {
+   public void testMockCacheStartedAndStopped() {
       cm1 = TestCacheManagerFactory.createLocalCacheManager();
       cm1.getCache();
       CacheManagerNotifier mockNotifier = createMock(CacheManagerNotifier.class);
@@ -80,4 +86,40 @@
          TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, origNotifier, true);
       }
    }
+
+   public void testViewChange() throws Exception {
+      CacheManager cmA = TestCacheManagerFactory.createClusteredCacheManager();
+      cmA.getCache();
+      CyclicBarrier barrier = new CyclicBarrier(2);
+      GetCacheManagerCheckListener listener = new GetCacheManagerCheckListener(barrier);
+      cmA.addListener(listener);
+      CacheManager cmB = TestCacheManagerFactory.createClusteredCacheManager();
+      cmB.getCache();
+      try {
+         barrier.await();
+         barrier.await();
+         assert listener.cacheManager != null;
+      } finally {
+         TestingUtil.killCacheManagers(cmA, cmB);
+      }
+   }
+
+   @Listener
+   public class GetCacheManagerCheckListener {
+      CacheManager cacheManager;
+      CyclicBarrier barrier;
+      
+      public GetCacheManagerCheckListener(CyclicBarrier barrier) {
+         this.barrier = barrier;
+      }
+
+      @ViewChanged
+      public void onViewChange(ViewChangedEvent e) throws Exception {
+         barrier.await();
+         cacheManager = e.getCacheManager();
+         barrier.await();
+      }
+
+   }
+
 }



More information about the infinispan-commits mailing list