[jbosscache-commits] JBoss Cache SVN: r5156 - in pojo/branches/2.1/src: test/java/org/jboss/cache/pojo/notification and 1 other directory.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Wed Jan 16 18:51:09 EST 2008
Author: jason.greene at jboss.com
Date: 2008-01-16 18:51:09 -0500 (Wed, 16 Jan 2008)
New Revision: 5156
Added:
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java
Modified:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
Log:
Merge 4868 - Fix for PCACHE-56
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java 2008-01-16 22:52:32 UTC (rev 5155)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java 2008-01-16 23:51:09 UTC (rev 5156)
@@ -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/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 22:52:32 UTC (rev 5155)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 23:51:09 UTC (rev 5156)
@@ -298,7 +298,10 @@
{
try
{
+ boolean wasEmpty = listenerAdaptor.isEmpty();
listenerAdaptor.addListener(listener, pattern);
+ if (wasEmpty)
+ cache.addCacheListener(listenerAdaptor);
}
catch (IllegalArgumentException e)
{
@@ -306,7 +309,6 @@
e.fillInStackTrace();
throw e;
}
- cache.addCacheListener(listenerAdaptor);
}
}
Copied: pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java (from rev 4868, pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java)
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java (rev 0)
+++ pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java 2008-01-16 23:51:09 UTC (rev 5156)
@@ -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