[jbosscache-commits] JBoss Cache SVN: r4868 - in pojo/trunk/src: test/java/org/jboss/cache/pojo/notification and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Dec 17 22:55:15 EST 2007


Author: jason.greene at jboss.com
Date: 2007-12-17 22:55:14 -0500 (Mon, 17 Dec 2007)
New Revision: 4868

Added:
   pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java
Modified:
   pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
   pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
Log:
Fix PCACHE-56


Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java	2007-12-16 17:38:31 UTC (rev 4867)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java	2007-12-18 03:55:14 UTC (rev 4868)
@@ -122,7 +122,8 @@
          if (! (o instanceof Entry))
             return false;
 
-         return ((Entry)o).equals(listener);
+         // Must be the same instance
+         return ((Entry)o).listener == this.listener;
       }
 
       private static Map<Class<?>, List<Method>> buildNotifiers(Class clazz)

Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java	2007-12-16 17:38:31 UTC (rev 4867)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java	2007-12-18 03:55:14 UTC (rev 4868)
@@ -296,7 +296,10 @@
       {
          try
          {
+            boolean wasEmpty = listenerAdaptor.isEmpty();
             listenerAdaptor.addListener(listener, pattern);
+            if (wasEmpty)
+               cache.addCacheListener(listenerAdaptor);
          }
          catch (IllegalArgumentException e)
          {
@@ -304,7 +307,6 @@
             e.fillInStackTrace();
             throw e;
          }
-         cache.addCacheListener(listenerAdaptor);
       }
    }
 

Added: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java	                        (rev 0)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java	2007-12-18 03:55:14 UTC (rev 4868)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.cache.pojo.notification;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.impl.CacheListenerAdaptor;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+// $Id: ObjectTest.java 4698 2007-10-26 18:30:20Z jason.greene at jboss.com $
+
+/**
+ * Tests that CacheListenerAdaptor is attached properly.
+ *
+ * @author Jason T. Greene
+ */
+ at Test(groups = {"functional"})
+public class ListenerCountTest
+{
+   protected PojoCache cache;
+
+   @BeforeMethod(alwaysRun = true)
+   protected void setUp() throws Exception
+   {
+      String configFile = "META-INF/local-service.xml";
+      boolean toStart = false;
+      cache = PojoCacheFactory.createCache(configFile, toStart);
+      cache.start();
+   }
+
+   @AfterMethod(alwaysRun = true)
+   protected void tearDown() throws Exception
+   {
+      cache.stop();
+   }
+
+   public void testAddRemoveListener() throws Exception
+   {    
+      assertEquals(0, getAdaptorCount());
+      
+      Object listener1 = new Listener();
+      cache.addListener(listener1);
+      assertEquals(1, getAdaptorCount());
+      
+      Object listener2 = new Listener();
+      cache.addListener(listener2);
+      assertEquals(1, getAdaptorCount());
+      
+      cache.removeListener(listener1);      
+      assertEquals(1, getAdaptorCount());
+      
+      cache.removeListener(listener2);      
+      assertEquals(0, getAdaptorCount());
+   }
+
+   private int getAdaptorCount()
+   {
+      int count = 0;
+      for (Object listener : cache.getCache().getCacheListeners())
+         if (listener instanceof CacheListenerAdaptor)
+            count++;
+      
+      return count;
+   }
+}
\ No newline at end of file




More information about the jbosscache-commits mailing list