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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Jan 5 09:10:17 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-01-05 09:10:17 -0500 (Mon, 05 Jan 2009)
New Revision: 7367

Added:
   core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerRemovalTest.java
Log:
Added test

Added: core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerRemovalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerRemovalTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerRemovalTest.java	2009-01-05 14:10:17 UTC (rev 7367)
@@ -0,0 +1,64 @@
+package org.jboss.cache.notifications;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeVisited;
+import org.jboss.cache.notifications.event.Event;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author Manik Surtani
+ */
+ at Test(groups = "functional")
+public class CacheListenerRemovalTest
+{
+   public void testListenerRemoval()
+   {
+      Cache cache = new DefaultCacheFactory().createCache();
+      AtomicInteger i = new AtomicInteger(0);
+      try
+      {
+         assert 0 == cache.getCacheListeners().size();
+         Listener l = new Listener(i);
+         cache.addCacheListener(l);
+         assert 1 == cache.getCacheListeners().size();
+         assert cache.getCacheListeners().iterator().next() == l;
+         assert 0 == i.get();
+         cache.get(Fqn.ROOT, "x");
+         assert 1 == i.get();
+
+         // remove the listener
+         cache.removeCacheListener(l);
+         assert 0 == cache.getCacheListeners().size();
+         i.set(0);
+         assert 0 == i.get();
+         cache.get(Fqn.ROOT, "x");
+         assert 0 == i.get();
+      }
+      finally
+      {
+         cache.stop();
+      }
+   }
+
+   @CacheListener
+   public static class Listener
+   {
+      AtomicInteger i;
+
+      private Listener(AtomicInteger i)
+      {
+         this.i = i;
+      }
+
+      @NodeVisited
+      public void listen(Event e)
+      {
+         if (e.isPre()) i.incrementAndGet();
+      }
+   }
+}




More information about the jbosscache-commits mailing list