[jbosscache-commits] JBoss Cache SVN: r7622 - in core/branches/flat/src: test/java/org/horizon/notifications and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Sat Jan 31 05:39:31 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-01-31 05:39:31 -0500 (Sat, 31 Jan 2009)
New Revision: 7622

Added:
   core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerListener.java
Modified:
   core/branches/flat/src/main/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java
   core/branches/flat/src/test/java/org/horizon/notifications/ConcurrentNotificationTest.java
   core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImplTest.java
Log:
Started work on notifications

Modified: core/branches/flat/src/main/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java	2009-01-31 09:44:26 UTC (rev 7621)
+++ core/branches/flat/src/main/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImpl.java	2009-01-31 10:39:31 UTC (rev 7622)
@@ -1,6 +1,8 @@
 package org.horizon.notifications.cachemanagerlistener;
 
 import org.horizon.factories.annotations.NonVolatile;
+import org.horizon.factories.annotations.Start;
+import org.horizon.factories.annotations.Stop;
 import org.horizon.factories.scopes.Scope;
 import org.horizon.factories.scopes.Scopes;
 import org.horizon.remoting.transport.Address;
@@ -41,4 +43,14 @@
    public Set<Object> getListeners() {
       return null;  // TODO: Manik: Customise this generated block
    }
+
+   @Start
+   public void start() {
+      // TODO: Manik: Customise this generated block
+   }
+
+   @Stop
+   public void stop() {
+
+   }
 }

Modified: core/branches/flat/src/test/java/org/horizon/notifications/ConcurrentNotificationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/ConcurrentNotificationTest.java	2009-01-31 09:44:26 UTC (rev 7621)
+++ core/branches/flat/src/test/java/org/horizon/notifications/ConcurrentNotificationTest.java	2009-01-31 10:39:31 UTC (rev 7622)
@@ -1,6 +1,8 @@
 package org.horizon.notifications;
 
 import org.horizon.Cache;
+import org.horizon.logging.Log;
+import org.horizon.logging.LogFactory;
 import org.horizon.manager.CacheManager;
 import org.horizon.manager.DefaultCacheManager;
 import org.horizon.notifications.cachelistener.annotation.CacheEntryCreated;
@@ -23,6 +25,7 @@
    Cache<String, String> cache;
    CacheManager cm;
    CacheListener listener;
+   Log log = LogFactory.getLog(ConcurrentNotificationTest.class);
 
    @BeforeMethod
    public void setUp() {
@@ -88,7 +91,11 @@
       for (Exception e : exceptions)
          throw e;
 
-      assert 4 * loops * workers.length == listener.counter.get();
+      // we cannot ascertain the exact number of invocations on the listener since some removes would mean that other
+      // gets would miss.  And this would cause no notification to fire for that get.  And we cannot be sure of the
+      // timing between removes and gets, so we just make sure *some* of these have got through, and no exceptions
+      // were thrown due to concurrent access.
+      assert loops * workers.length < listener.counter.get();
    }
 
    @Listener

Added: core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerListener.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerListener.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerListener.java	2009-01-31 10:39:31 UTC (rev 7622)
@@ -0,0 +1,35 @@
+package org.horizon.notifications.cachemanagerlistener;
+
+import org.horizon.notifications.Listener;
+import org.horizon.notifications.cachemanagerlistener.annotation.CacheStarted;
+import org.horizon.notifications.cachemanagerlistener.annotation.CacheStopped;
+import org.horizon.notifications.cachemanagerlistener.annotation.ViewChanged;
+import org.horizon.notifications.cachemanagerlistener.event.Event;
+
+ at Listener
+public class CacheManagerListener {
+   Event event;
+   int invocationCount;
+
+   public void reset() {
+      event = null;
+      invocationCount = 0;
+   }
+
+   public Event getEvent() {
+      return event;
+   }
+
+   public int getInvocationCount() {
+      return invocationCount;
+   }
+
+   // handler
+   @CacheStarted
+   @CacheStopped
+   @ViewChanged
+   public void handle(Event e) {
+      event = e;
+      invocationCount++;
+   }
+}

Modified: core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImplTest.java	2009-01-31 09:44:26 UTC (rev 7621)
+++ core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierImplTest.java	2009-01-31 10:39:31 UTC (rev 7622)
@@ -1,8 +1,54 @@
 package org.horizon.notifications.cachemanagerlistener;
 
+import org.easymock.EasyMock;
+import org.horizon.notifications.cachemanagerlistener.event.CacheStartedEvent;
+import org.horizon.notifications.cachemanagerlistener.event.CacheStoppedEvent;
+import org.horizon.notifications.cachemanagerlistener.event.Event;
+import org.horizon.notifications.cachemanagerlistener.event.ViewChangedEvent;
+import org.horizon.remoting.transport.Address;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import java.util.Collections;
+import java.util.List;
+
 @Test(groups = "unit")
 public class CacheManagerNotifierImplTest {
-   // TODO implement me!
+   CacheManagerNotifierImpl n;
+   CacheManagerListener cl;
+
+   @BeforeMethod
+   public void setUp() {
+      n = new CacheManagerNotifierImpl();
+      cl = new CacheManagerListener();
+      n.start();
+      n.addListener(cl);
+   }
+
+   public void testNotifyViewChanged() {
+      Address a = EasyMock.createNiceMock(Address.class);
+      List<Address> addresses = Collections.emptyList();
+      n.notifyViewChange(addresses, a);
+
+      assert cl.invocationCount == 1;
+      assert ((ViewChangedEvent) cl.getEvent()).getLocalAddress() == a;
+      assert ((ViewChangedEvent) cl.getEvent()).getNewMemberList() == addresses;
+      assert cl.getEvent().getType() == Event.Type.VIEW_CHANGED;
+   }
+
+   public void testNotifyCacheStarted() {
+      n.notifyCacheStarted("cache");
+
+      assert cl.invocationCount == 1;
+      assert ((CacheStartedEvent) cl.getEvent()).getCacheName().equals("cache");
+      assert cl.getEvent().getType() == Event.Type.CACHE_STARTED;
+   }
+
+   public void testNotifyCacheStopped() {
+      n.notifyCacheStopped("cache");
+
+      assert cl.invocationCount == 1;
+      assert ((CacheStoppedEvent) cl.getEvent()).getCacheName().equals("cache");
+      assert cl.getEvent().getType() == Event.Type.CACHE_STOPPED;
+   }
 }




More information about the jbosscache-commits mailing list