[jbosscache-commits] JBoss Cache SVN: r5883 - in core/trunk/src: main/java/org/jboss/cache/commands/remote and 5 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Fri May 23 06:34:25 EDT 2008
Author: mircea.markus
Date: 2008-05-23 06:34:25 -0400 (Fri, 23 May 2008)
New Revision: 5883
Added:
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java
Removed:
core/trunk/src/test/java/org/jboss/cache/notifications/AnnotationsTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/commands/remote/AnnounceBuddyPoolNameCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/remote/AssignToBuddyGroupCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
core/trunk/src/test/java/org/jboss/cache/invocation/InterceptorChainTest.java
Log:
JBCACHE-1338 - added unit test for NotifierImpl class + small bug fixes + small refactorings
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -630,8 +630,8 @@
{
flushBlockGate.close();
if (log.isDebugEnabled()) log.debug("Block received at " + getLocalAddress());
- notifier.notifyCacheBlocked(spi, true);
- notifier.notifyCacheBlocked(spi, false);
+ notifier.notifyCacheBlocked(true);
+ notifier.notifyCacheBlocked(false);
if (log.isDebugEnabled()) log.debug("Block processed at " + getLocalAddress());
}
@@ -643,8 +643,8 @@
{
if (log.isDebugEnabled()) log.debug("UnBlock received at " + getLocalAddress());
- notifier.notifyCacheUnblocked(spi, true);
- notifier.notifyCacheUnblocked(spi, false);
+ notifier.notifyCacheUnblocked(true);
+ notifier.notifyCacheUnblocked(false);
if (log.isDebugEnabled()) log.debug("UnBlock processed at " + getLocalAddress());
flushBlockGate.open();
Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/AnnounceBuddyPoolNameCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/AnnounceBuddyPoolNameCommand.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/AnnounceBuddyPoolNameCommand.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -55,7 +55,6 @@
buddyManager.handlePoolNameBroadcast(address, buddyPoolName);
else if (log.isWarnEnabled())
log.warn("Received annouceBuddyPoolName call from [" + address + "] but buddy replication is not enabled on this node!");
-
return null;
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/AssignToBuddyGroupCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/AssignToBuddyGroupCommand.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/AssignToBuddyGroupCommand.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -54,7 +54,6 @@
{
if (buddyManager != null)
buddyManager.handleAssignToBuddyGroup(group, state);
-
return null;
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -60,10 +60,16 @@
{
oldData = new HashMap(existingData); // defensive copy
}
- notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_MAP, oldData == null ? Collections.emptyMap() : oldData, ctx);
+ if (notifier.shouldNotifyOnNodeModified())
+ {
+ notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_MAP, oldData == null ? Collections.emptyMap() : oldData, ctx);
+ }
nodeSPI.putAllDirect(data);
- notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_MAP, nodeSPI.getDataDirect(), ctx);
+ if (notifier.shouldNotifyOnNodeModified())
+ {
+ notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_MAP, nodeSPI.getDataDirect(), ctx);
+ }
return null;
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -59,11 +59,17 @@
append(fqn).append("\", k=").append(key).append(", v=").append(value).append(")"));
}
NodeSPI n = dataContainer.peekStrict(globalTransaction, fqn, false);
- notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA, n.getDataDirect(), ctx);
+ if (notifier.shouldNotifyOnNodeModified())
+ {
+ notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA, n.getDataDirect(), ctx);
+ }
oldValue = n.putDirect(key, value);
- Map newData = Collections.singletonMap(key, value);
- notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_DATA, newData, ctx);
+ if (notifier.shouldNotifyOnNodeModified())
+ {
+ Map newData = Collections.singletonMap(key, value);
+ notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_DATA, newData, ctx);
+ }
return oldValue;
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -61,12 +61,16 @@
if (log.isDebugEnabled()) log.debug("node " + fqn + " not found");
return null;
}
- notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.REMOVE_DATA, n.getDataDirect(), ctx);
-
+ if (notifier.shouldNotifyOnNodeModified())
+ {
+ notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.REMOVE_DATA, n.getDataDirect(), ctx);
+ }
this.oldValue = n.removeDirect(key);
-
- Map removedData = Collections.singletonMap(key, oldValue);
- notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.REMOVE_DATA, removedData, ctx);
+ if (notifier.shouldNotifyOnNodeModified())
+ {
+ Map removedData = Collections.singletonMap(key, oldValue);
+ notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.REMOVE_DATA, removedData, ctx);
+ }
return oldValue;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -445,15 +445,19 @@
if (workspaceNode == null)
throw new NodeNotExistsException("optimisticCreateIfNotExistsInterceptor should have created this node!");
- Map addedData = Collections.singletonMap(key, value);
- // pre-notify
- notifier.notifyNodeModified(workspaceNode.getFqn(), true, PUT_DATA, workspaceNode.getData(), ctx);
+ if (notifier.shouldNotifyOnNodeModified())// pre-notify
+ {
+ notifier.notifyNodeModified(workspaceNode.getFqn(), true, PUT_DATA, workspaceNode.getData(), ctx);
+ }
Object old = workspaceNode.put(key, value);
workspace.addNode(workspaceNode);
- // post-notify
- notifier.notifyNodeModified(workspaceNode.getFqn(), false, PUT_DATA, addedData, ctx);
+ if (notifier.shouldNotifyOnNodeModified())// post-notify
+ {
+ Map addedData = Collections.singletonMap(key, value);
+ notifier.notifyNodeModified(workspaceNode.getFqn(), false, PUT_DATA, addedData, ctx);
+ }
return old;
}
@@ -497,15 +501,20 @@
{
if (workspaceNode == null) return null;
- // pre-notify
- notifier.notifyNodeModified(workspaceNode.getFqn(), true, REMOVE_DATA, workspaceNode.getData(), ctx);
+ if (notifier.shouldNotifyOnNodeModified())// pre-notify
+ {
+ notifier.notifyNodeModified(workspaceNode.getFqn(), true, REMOVE_DATA, workspaceNode.getData(), ctx);
+ }
Object old = workspaceNode.remove(removeKey);
workspace.addNode(workspaceNode);
- Map removedData = Collections.singletonMap(removeKey, old);
- // post-notify
- notifier.notifyNodeModified(workspaceNode.getFqn(), false, REMOVE_DATA, removedData, ctx);
+ if (notifier.shouldNotifyOnNodeModified())
+ {
+ Map removedData = Collections.singletonMap(removeKey, old);
+ // post-notify
+ notifier.notifyNodeModified(workspaceNode.getFqn(), false, REMOVE_DATA, removedData, ctx);
+ }
return old;
}
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -1,99 +1,108 @@
-package org.jboss.cache.notifications;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.buddyreplication.BuddyGroup;
-import org.jboss.cache.factories.annotations.Start;
-import org.jboss.cache.factories.annotations.Stop;
-import org.jboss.cache.notifications.event.NodeModifiedEvent;
-import org.jgroups.View;
-
-import javax.transaction.Transaction;
-import java.util.Map;
-
-/**
- * @author Mircea.Markus at jboss.com
- * @since 2.2
- */
-public interface Notifier
-{
- /**
- * Notifies all registered listeners of a nodeCreated event.
- */
- void notifyNodeCreated(Fqn fqn, boolean pre, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodeModified event.
- */
- void notifyNodeModified(Fqn fqn, boolean pre, NodeModifiedEvent.ModificationType modificationType, Map data, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodeRemoved event.
- */
- void notifyNodeRemoved(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodeVisited event.
- */
- void notifyNodeVisited(Fqn fqn, boolean pre, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodeMoved event.
- */
- void notifyNodeMoved(Fqn originalFqn, Fqn newFqn, boolean pre, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodeEvicted event.
- */
- void notifyNodeEvicted(Fqn fqn, boolean pre, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodeLoaded event.
- */
- void notifyNodeLoaded(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodeActivated event.
- */
- void notifyNodeActivated(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a nodePassivated event.
- */
- void notifyNodePassivated(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a viewChange event. Note that viewChange notifications are ALWAYS sent
- * immediately.
- */
- void notifyViewChange(View new_view, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a buddy group change event. Note that buddy group change notifications are ALWAYS sent
- * immediately.
- *
- * @param buddyGroup buddy group to set
- * @param pre if true, this has occured before the buddy group message is broadcast to the cluster
- */
- void notifyBuddyGroupChange(BuddyGroup buddyGroup, boolean pre);
-
- /**
- * Notifies all registered listeners of a transaction completion event.
- *
- * @param transaction the transaction that has just completed
- * @param successful if true, the transaction committed. If false, this is a rollback event
- */
- void notifyTransactionCompleted(Transaction transaction, boolean successful, InvocationContext ctx);
-
- /**
- * Notifies all registered listeners of a transaction registration event.
- *
- * @param transaction the transaction that has just completed
- */
- void notifyTransactionRegistered(Transaction transaction, InvocationContext ctx);
-
- void notifyCacheBlocked(CacheSPI cache, boolean pre);
-
- void notifyCacheUnblocked(CacheSPI cache, boolean pre);
-}
+package org.jboss.cache.notifications;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.factories.annotations.Stop;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jgroups.View;
+
+import javax.transaction.Transaction;
+import java.util.Map;
+
+/**
+ * Public interface with all allowed notifications.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 2.2
+ */
+public interface Notifier
+{
+ /**
+ * Notifies all registered listeners of a nodeCreated event.
+ */
+ void notifyNodeCreated(Fqn fqn, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeModified event.
+ */
+ void notifyNodeModified(Fqn fqn, boolean pre, NodeModifiedEvent.ModificationType modificationType, Map data, InvocationContext ctx);
+
+ /**
+ * When notifying about node modifications, in many scenarios there is a need of building a new Map object. If no
+ * listeners are registered for notification then it is pointless building this object - so guard the notification
+ * with this call.
+ */
+ public boolean shouldNotifyOnNodeModified();
+
+ /**
+ * Notifies all registered listeners of a nodeRemoved event.
+ */
+ void notifyNodeRemoved(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeVisited event.
+ */
+ void notifyNodeVisited(Fqn fqn, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeMoved event.
+ */
+ void notifyNodeMoved(Fqn originalFqn, Fqn newFqn, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeEvicted event.
+ */
+ void notifyNodeEvicted(Fqn fqn, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeLoaded event.
+ */
+ void notifyNodeLoaded(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeActivated event.
+ */
+ void notifyNodeActivated(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodePassivated event.
+ */
+ void notifyNodePassivated(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a viewChange event. Note that viewChange notifications are ALWAYS sent
+ * immediately.
+ */
+ void notifyViewChange(View new_view, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a buddy group change event. Note that buddy group change notifications are ALWAYS sent
+ * immediately.
+ *
+ * @param buddyGroup buddy group to set
+ * @param pre if true, this has occured before the buddy group message is broadcast to the cluster
+ */
+ void notifyBuddyGroupChange(BuddyGroup buddyGroup, boolean pre);
+
+ /**
+ * Notifies all registered listeners of a transaction completion event.
+ *
+ * @param transaction the transaction that has just completed
+ * @param successful if true, the transaction committed. If false, this is a rollback event
+ */
+ void notifyTransactionCompleted(Transaction transaction, boolean successful, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a transaction registration event.
+ *
+ * @param transaction the transaction that has just completed
+ */
+ void notifyTransactionRegistered(Transaction transaction, InvocationContext ctx);
+
+ void notifyCacheBlocked(boolean pre);
+
+ void notifyCacheUnblocked(boolean pre);
+}
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -264,6 +264,12 @@
}
}
+ public boolean shouldNotifyOnNodeModified()
+ {
+ List<ListenerInvocation> listeners = listenerInvocations.get(NodeRemoved.class);
+ return (listeners != null && !listeners.isEmpty());
+ }
+
public void notifyNodeRemoved(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
List<ListenerInvocation> listeners = listenerInvocations.get(NodeRemoved.class);
@@ -450,7 +456,7 @@
}
}
- public void notifyViewChange(final View new_view, InvocationContext ctx)
+ public void notifyViewChange(final View newView, InvocationContext ctx)
{
List<ListenerInvocation> listeners = listenerInvocations.get(ViewChanged.class);
@@ -459,7 +465,7 @@
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
- e.setNewView(new_view);
+ e.setNewView(newView);
e.setType(VIEW_CHANGED);
for (ListenerInvocation listener : listeners) listener.invoke(e);
restoreInvocationContext(backup);
@@ -487,13 +493,12 @@
if (listeners != null && !listeners.isEmpty())
{
- Transaction tx = ctx.getTransaction();
boolean isOriginLocal = ctx.isOriginLocal();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
e.setOriginLocal(isOriginLocal);
- e.setTransaction(tx);
+ e.setTransaction(transaction);
e.setSuccessful(successful);
e.setType(TRANSACTION_COMPLETED);
for (ListenerInvocation listener : listeners) listener.invoke(e);
@@ -507,41 +512,40 @@
if (listeners != null && !listeners.isEmpty())
{
- Transaction tx = ctx.getTransaction();
boolean isOriginLocal = ctx.isOriginLocal();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
e.setOriginLocal(isOriginLocal);
- e.setTransaction(tx);
+ e.setTransaction(transaction);
e.setType(TRANSACTION_REGISTERED);
for (ListenerInvocation listener : listeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
- public void notifyCacheBlocked(CacheSPI cache, boolean pre)
+ public void notifyCacheBlocked(boolean pre)
{
List<ListenerInvocation> listeners = listenerInvocations.get(CacheBlocked.class);
if (listeners != null && !listeners.isEmpty())
{
EventImpl e = new EventImpl();
- e.setCache(cache);
+ e.setCache(this.cache);
e.setPre(pre);
e.setType(CACHE_BLOCKED);
for (ListenerInvocation listener : listeners) listener.invoke(e);
}
}
- public void notifyCacheUnblocked(CacheSPI cache, boolean pre)
+ public void notifyCacheUnblocked(boolean pre)
{
List<ListenerInvocation> listeners = listenerInvocations.get(CacheUnblocked.class);
if (listeners != null && !listeners.isEmpty())
{
EventImpl e = new EventImpl();
- e.setCache(cache);
+ e.setCache(this.cache);
e.setPre(pre);
e.setType(CACHE_UNBLOCKED);
for (ListenerInvocation listener : listeners) listener.invoke(e);
Modified: core/trunk/src/test/java/org/jboss/cache/invocation/InterceptorChainTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocation/InterceptorChainTest.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/test/java/org/jboss/cache/invocation/InterceptorChainTest.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -19,7 +19,7 @@
* @author Mircea.Markus at jboss.com
* @since 2.2
*/
- at Test(groups = {"functional"})
+ at Test(groups = {"unit"})
public class InterceptorChainTest
{
private CommandInterceptor icInterceptor;
Deleted: core/trunk/src/test/java/org/jboss/cache/notifications/AnnotationsTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/AnnotationsTest.java 2008-05-21 16:59:54 UTC (rev 5882)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/AnnotationsTest.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -1,349 +0,0 @@
-package org.jboss.cache.notifications;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.notifications.annotation.CacheListener;
-import org.jboss.cache.notifications.annotation.CacheStarted;
-import org.jboss.cache.notifications.annotation.CacheStopped;
-import org.jboss.cache.notifications.annotation.NodeMoved;
-import org.jboss.cache.notifications.event.Event;
-import org.jboss.cache.notifications.event.NodeMovedEvent;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-/**
- * Tests both correct and incorrect annotations for listeners
- *
- * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
- * @since 2.0.0
- */
- at Test(groups = {"functional"})
-public class AnnotationsTest
-{
- private NotifierImpl n;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp()
- {
- Cache c = new DefaultCacheFactory().createCache(false);
- n = new NotifierImpl(c);
- }
-
- public void testControl()
- {
- Object l = new TestControlListener();
- n.addCacheListener(l);
- assertEquals(1, n.getCacheListeners().size());
- }
-
- public void testCacheListenerNoMethods()
- {
- Object l = new TestCacheListenerNoMethodsListener();
- n.addCacheListener(l);
- assertEquals("Hello", l.toString());
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty()); // since the valid listener has no methods to listen
- }
-
- public void testNonAnnotatedListener()
- {
- Object l = new TestNonAnnotatedListener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept an un-annotated cache listener");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testNonPublicListener()
- {
- Object l = new TestNonPublicListener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept a private callback class");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testNonPublicListenerMethod()
- {
- Object l = new TestNonPublicListenerMethodListener();
- n.addCacheListener(l);
-
- // should not fail, should just not register anything
-
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testNonVoidReturnTypeMethod()
- {
- Object l = new TestNonVoidReturnTypeMethodListener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept a listener method with a return type");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testIncorrectMethodSignature1()
- {
- Object l = new TestIncorrectMethodSignature1Listener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept a cache listener with a bad method signature");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testIncorrectMethodSignature2()
- {
- Object l = new TestIncorrectMethodSignature2Listener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept a cache listener with a bad method signature");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testIncorrectMethodSignature3()
- {
- Object l = new TestIncorrectMethodSignature3Listener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept a cache listener with a bad method signature");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testUnassignableMethodSignature()
- {
- Object l = new TestUnassignableMethodSignatureListener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept a cache listener with a bad method signature");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
- }
-
- public void testPartlyUnassignableMethodSignature()
- {
- Object l = new TestPartlyUnassignableMethodSignatureListener();
- try
- {
- n.addCacheListener(l);
- fail("Should not accept a cache listener with a bad method signature");
- }
- catch (IncorrectCacheListenerException icle)
- {
- // expected
- }
- }
-
- public void testMultipleMethods()
- {
- Object l = new TestMultipleMethodsListener();
- n.addCacheListener(l);
- List invocations = n.listenerInvocations.get(CacheStarted.class);
- assertEquals(1, invocations.size());
- invocations = n.listenerInvocations.get(CacheStopped.class);
- assertEquals(1, invocations.size());
- assertEquals(1, n.getCacheListeners().size());
- }
-
- public void testMultipleAnnotationsOneMethod()
- {
- Object l = new TestMultipleAnnotationsOneMethodListener();
- n.addCacheListener(l);
- List invocations = n.listenerInvocations.get(CacheStarted.class);
- assertEquals(1, invocations.size());
- invocations = n.listenerInvocations.get(CacheStopped.class);
- assertEquals(1, invocations.size());
- assertEquals(1, n.getCacheListeners().size());
- }
-
- public void testMultipleMethodsOneAnnotation()
- {
- Object l = new TestMultipleMethodsOneAnnotationListener();
- n.addCacheListener(l);
- List invocations = n.listenerInvocations.get(CacheStarted.class);
- assertEquals(2, invocations.size());
- assertEquals(1, n.getCacheListeners().size());
- }
-
- @CacheListener
- public class TestControlListener
- {
- @CacheStarted
- @CacheStopped
- public void callback(Event e)
- {
- System.out.println("Hello");
- }
- }
-
- @CacheListener
- public class TestCacheListenerNoMethodsListener
- {
- public String toString()
- {
- return "Hello";
- }
- }
-
- public class TestNonAnnotatedListener
- {
- public String toString()
- {
- return "Hello";
- }
- }
-
- @CacheListener
- protected class TestNonPublicListener
- {
- @CacheStarted
- public void callback()
- {
- }
- }
-
- @CacheListener
- public class TestNonPublicListenerMethodListener
- {
- @CacheStarted
- protected void callback(Event e)
- {
- }
- }
-
- @CacheListener
- public class TestNonVoidReturnTypeMethodListener
- {
- @CacheStarted
- public String callback(Event e)
- {
- return "Hello";
- }
- }
-
- @CacheListener
- public class TestIncorrectMethodSignature1Listener
- {
- @CacheStarted
- public void callback()
- {
- }
- }
-
- @CacheListener
- public class TestIncorrectMethodSignature2Listener
- {
- @CacheStarted
- public void callback(Event e, String s)
- {
- }
- }
-
- @CacheListener
- public class TestIncorrectMethodSignature3Listener
- {
- @CacheStarted
- public void callback(Event e, String... s)
- {
- }
- }
-
- @CacheListener
- public class TestUnassignableMethodSignatureListener
- {
- @CacheStarted
- public void callback(NodeMovedEvent nme)
- {
- }
- }
-
- @CacheListener
- public class TestPartlyUnassignableMethodSignatureListener
- {
- @NodeMoved
- @CacheStarted
- public void callback(NodeMovedEvent nme) // sig valid for NodeMoved but not CacheStarted
- {
- }
- }
-
- @CacheListener
- public class TestMultipleMethodsListener
- {
- @CacheStarted
- public void callback1(Event e)
- {
- }
-
- @CacheStopped
- public void callback2(Event e)
- {
- }
- }
-
- @CacheListener
- public class TestMultipleAnnotationsOneMethodListener
- {
- @CacheStopped
- @CacheStarted
- public void callback(Event nme)
- {
- }
- }
-
- @CacheListener
- public class TestMultipleMethodsOneAnnotationListener
- {
- @CacheStarted
- public void callback1(Event e)
- {
- }
-
- @CacheStarted
- public void callback2(Event e)
- {
- }
- }
-}
Copied: core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java (from rev 5878, core/trunk/src/test/java/org/jboss/cache/notifications/AnnotationsTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -0,0 +1,349 @@
+package org.jboss.cache.notifications;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.CacheStarted;
+import org.jboss.cache.notifications.annotation.CacheStopped;
+import org.jboss.cache.notifications.annotation.NodeMoved;
+import org.jboss.cache.notifications.event.Event;
+import org.jboss.cache.notifications.event.NodeMovedEvent;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * Tests both correct and incorrect annotations for listeners
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @since 2.0.0
+ */
+ at Test(groups = {"functional"})
+public class NotifierAnnotationsTest
+{
+ private NotifierImpl n;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp()
+ {
+ Cache c = new DefaultCacheFactory().createCache(false);
+ n = new NotifierImpl(c);
+ }
+
+ public void testControl()
+ {
+ Object l = new TestControlListener();
+ n.addCacheListener(l);
+ assertEquals(1, n.getCacheListeners().size());
+ }
+
+ public void testCacheListenerNoMethods()
+ {
+ Object l = new TestCacheListenerNoMethodsListener();
+ n.addCacheListener(l);
+ assertEquals("Hello", l.toString());
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty()); // since the valid listener has no methods to listen
+ }
+
+ public void testNonAnnotatedListener()
+ {
+ Object l = new TestNonAnnotatedListener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept an un-annotated cache listener");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testNonPublicListener()
+ {
+ Object l = new TestNonPublicListener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept a private callback class");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testNonPublicListenerMethod()
+ {
+ Object l = new TestNonPublicListenerMethodListener();
+ n.addCacheListener(l);
+
+ // should not fail, should just not register anything
+
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testNonVoidReturnTypeMethod()
+ {
+ Object l = new TestNonVoidReturnTypeMethodListener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept a listener method with a return type");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testIncorrectMethodSignature1()
+ {
+ Object l = new TestIncorrectMethodSignature1Listener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept a cache listener with a bad method signature");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testIncorrectMethodSignature2()
+ {
+ Object l = new TestIncorrectMethodSignature2Listener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept a cache listener with a bad method signature");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testIncorrectMethodSignature3()
+ {
+ Object l = new TestIncorrectMethodSignature3Listener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept a cache listener with a bad method signature");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testUnassignableMethodSignature()
+ {
+ Object l = new TestUnassignableMethodSignatureListener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept a cache listener with a bad method signature");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
+ }
+
+ public void testPartlyUnassignableMethodSignature()
+ {
+ Object l = new TestPartlyUnassignableMethodSignatureListener();
+ try
+ {
+ n.addCacheListener(l);
+ fail("Should not accept a cache listener with a bad method signature");
+ }
+ catch (IncorrectCacheListenerException icle)
+ {
+ // expected
+ }
+ }
+
+ public void testMultipleMethods()
+ {
+ Object l = new TestMultipleMethodsListener();
+ n.addCacheListener(l);
+ List invocations = n.listenerInvocations.get(CacheStarted.class);
+ assertEquals(1, invocations.size());
+ invocations = n.listenerInvocations.get(CacheStopped.class);
+ assertEquals(1, invocations.size());
+ assertEquals(1, n.getCacheListeners().size());
+ }
+
+ public void testMultipleAnnotationsOneMethod()
+ {
+ Object l = new TestMultipleAnnotationsOneMethodListener();
+ n.addCacheListener(l);
+ List invocations = n.listenerInvocations.get(CacheStarted.class);
+ assertEquals(1, invocations.size());
+ invocations = n.listenerInvocations.get(CacheStopped.class);
+ assertEquals(1, invocations.size());
+ assertEquals(1, n.getCacheListeners().size());
+ }
+
+ public void testMultipleMethodsOneAnnotation()
+ {
+ Object l = new TestMultipleMethodsOneAnnotationListener();
+ n.addCacheListener(l);
+ List invocations = n.listenerInvocations.get(CacheStarted.class);
+ assertEquals(2, invocations.size());
+ assertEquals(1, n.getCacheListeners().size());
+ }
+
+ @CacheListener
+ public class TestControlListener
+ {
+ @CacheStarted
+ @CacheStopped
+ public void callback(Event e)
+ {
+ System.out.println("Hello");
+ }
+ }
+
+ @CacheListener
+ public class TestCacheListenerNoMethodsListener
+ {
+ public String toString()
+ {
+ return "Hello";
+ }
+ }
+
+ public class TestNonAnnotatedListener
+ {
+ public String toString()
+ {
+ return "Hello";
+ }
+ }
+
+ @CacheListener
+ protected class TestNonPublicListener
+ {
+ @CacheStarted
+ public void callback()
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestNonPublicListenerMethodListener
+ {
+ @CacheStarted
+ protected void callback(Event e)
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestNonVoidReturnTypeMethodListener
+ {
+ @CacheStarted
+ public String callback(Event e)
+ {
+ return "Hello";
+ }
+ }
+
+ @CacheListener
+ public class TestIncorrectMethodSignature1Listener
+ {
+ @CacheStarted
+ public void callback()
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestIncorrectMethodSignature2Listener
+ {
+ @CacheStarted
+ public void callback(Event e, String s)
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestIncorrectMethodSignature3Listener
+ {
+ @CacheStarted
+ public void callback(Event e, String... s)
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestUnassignableMethodSignatureListener
+ {
+ @CacheStarted
+ public void callback(NodeMovedEvent nme)
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestPartlyUnassignableMethodSignatureListener
+ {
+ @NodeMoved
+ @CacheStarted
+ public void callback(NodeMovedEvent nme) // sig valid for NodeMoved but not CacheStarted
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestMultipleMethodsListener
+ {
+ @CacheStarted
+ public void callback1(Event e)
+ {
+ }
+
+ @CacheStopped
+ public void callback2(Event e)
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestMultipleAnnotationsOneMethodListener
+ {
+ @CacheStopped
+ @CacheStarted
+ public void callback(Event nme)
+ {
+ }
+ }
+
+ @CacheListener
+ public class TestMultipleMethodsOneAnnotationListener
+ {
+ @CacheStarted
+ public void callback1(Event e)
+ {
+ }
+
+ @CacheStarted
+ public void callback2(Event e)
+ {
+ }
+ }
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java 2008-05-23 10:34:25 UTC (rev 5883)
@@ -0,0 +1,343 @@
+package org.jboss.cache.notifications;
+
+import static org.easymock.EasyMock.*;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
+import org.jboss.cache.Cache;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.notifications.annotation.*;
+import org.jboss.cache.notifications.event.*;
+import org.jgroups.View;
+
+import javax.transaction.Transaction;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Tester class for {@link org.jboss.cache.notifications.NotifierImpl}.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 2.2
+ */
+ at Test(groups = "unit")
+public class NotifierTest
+{
+ private NotifierImpl notifier;
+ private Cache cache;
+ private InvocationContext ctx;
+ private AllEventsListener allEventsListener;
+ private Fqn fqn = Fqn.fromString("/a/b/c");
+
+ @BeforeMethod
+ public void setUp()
+ {
+ cache = createNiceMock(Cache.class);
+ notifier = new NotifierImpl(cache);
+ ctx = new InvocationContext();
+ allEventsListener = new AllEventsListener();
+ notifier.addCacheListener(allEventsListener);
+ }
+
+ public void testNotifyNodeCreated()
+ {
+ assert allEventsListener.nodeCreatedEvent == null;
+ notifier.notifyNodeCreated(fqn, true, ctx);
+ assert allEventsListener.nodeCreatedEvent != null;
+ assert allEventsListener.nodeCreatedEvent.getType() == Event.Type.NODE_CREATED;
+ }
+
+
+ public void testShouldNotifyOnNodeModified()
+ {
+ assert notifier.shouldNotifyOnNodeModified();
+ notifier.destroy();
+ assert !notifier.shouldNotifyOnNodeModified();
+ }
+
+ public void testNotifyNodeModified()
+ {
+ assert allEventsListener.nodeModifiedEvent == null;
+ Map expected = new HashMap();
+ expected.put("k", "v");
+ notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA, expected, ctx);
+ assert allEventsListener.nodeModifiedEvent != null;
+ assert allEventsListener.nodeModifiedEvent.getData().equals(expected);
+ assert allEventsListener.nodeModifiedEvent.getModificationType() == NodeModifiedEvent.ModificationType.PUT_DATA;
+ }
+
+ public void testNotifyNodeRemoved()
+ {
+ assert allEventsListener.nodeRemoveEvent == null;
+ Map data = new HashMap();
+ data.put("k", "v");
+ notifier.notifyNodeRemoved(fqn, true, data, ctx);
+ assert allEventsListener.nodeRemoveEvent != null;
+ assert allEventsListener.nodeRemoveEvent.getData().equals(data);
+ assert allEventsListener.nodeRemoveEvent.getType() == Event.Type.NODE_REMOVED;
+ }
+
+ public void testNotifyNodeVisited()
+ {
+ assert allEventsListener.nodeVisistedEvent == null;
+ notifier.notifyNodeVisited(fqn, true, ctx);
+ assert allEventsListener.nodeVisistedEvent != null;
+ assert allEventsListener.nodeVisistedEvent.getType() == Event.Type.NODE_VISITED;
+ }
+
+ public void testNotifyNodeMoved()
+ {
+ assert allEventsListener.nodeMovedEvent == null;
+ Fqn second = Fqn.fromString("/a/s/f");
+ notifier.notifyNodeMoved(fqn, second, true, ctx);
+ assert allEventsListener.nodeMovedEvent != null;
+ assert allEventsListener.nodeMovedEvent.getFqn().equals(fqn);
+ assert allEventsListener.nodeMovedEvent.getTargetFqn().equals(second);
+ assert allEventsListener.nodeMovedEvent.getType() == Event.Type.NODE_MOVED;
+ }
+
+ public void testNotifyNodeEvicted()
+ {
+ assert allEventsListener.nodeEvictedEvent == null;
+ notifier.notifyNodeEvicted(fqn, true, ctx);
+ assert allEventsListener.nodeEvictedEvent != null;
+ assert allEventsListener.nodeEvictedEvent.getFqn().equals(fqn);
+ assert allEventsListener.nodeEvictedEvent.getType() == Event.Type.NODE_EVICTED;
+ }
+
+ public void testNotifyNodeLoaded()
+ {
+ assert allEventsListener.nodeLoadedEvent == null;
+ Map expected = new HashMap();
+ expected.put("key", "value");
+ notifier.notifyNodeLoaded(fqn, true, expected, ctx);
+ assert allEventsListener.nodeLoadedEvent != null;
+ assert allEventsListener.nodeLoadedEvent.getFqn().equals(fqn);
+ assert allEventsListener.nodeLoadedEvent.getData().equals(expected);
+ assert allEventsListener.nodeLoadedEvent.getType() == Event.Type.NODE_LOADED;
+ }
+
+ public void testNotifyNodeActivated()
+ {
+ assert allEventsListener.nodeActivatedEvent == null;
+ Map expected = new HashMap();
+ expected.put("key", "value");
+ notifier.notifyNodeActivated(fqn, true, expected, ctx);
+ assert allEventsListener.nodeActivatedEvent != null;
+ assert allEventsListener.nodeActivatedEvent.getFqn().equals(fqn);
+ assert allEventsListener.nodeActivatedEvent.getData().equals(expected);
+ assert allEventsListener.nodeActivatedEvent.getType() == Event.Type.NODE_ACTIVATED;
+ }
+
+ public void testNotifyNodePassivated()
+ {
+ assert allEventsListener.nodePassivatedEvent == null;
+ Map expected = new HashMap();
+ expected.put("key", "value");
+ notifier.notifyNodePassivated(fqn, true, expected, ctx);
+ assert allEventsListener.nodePassivatedEvent != null;
+ assert allEventsListener.nodePassivatedEvent.getFqn().equals(fqn);
+ assert allEventsListener.nodePassivatedEvent.getData().equals(expected);
+ assert allEventsListener.nodePassivatedEvent.getType() == Event.Type.NODE_PASSIVATED;
+ }
+
+ public void testNotifyCacheStarted()
+ {
+ assert allEventsListener.cacheStartedEvent == null;
+ notifier.notifyCacheStarted();
+ assert allEventsListener.cacheStartedEvent != null;
+ assert allEventsListener.cacheStartedEvent.getType() == Event.Type.CACHE_STARTED;
+ }
+
+ public void testNotifyCacheStopped()
+ {
+ assert allEventsListener.cacheStoppedEvent == null;
+ notifier.notifyCacheStopped();
+ assert allEventsListener.cacheStoppedEvent != null;
+ assert allEventsListener.cacheStoppedEvent.getType() == Event.Type.CACHE_STOPPED;
+ }
+
+ public void testNotifyViewChange()
+ {
+ assert allEventsListener.viewChanged == null;
+ View view = new View();
+ notifier.notifyViewChange(view, ctx);
+ assert allEventsListener.viewChanged != null;
+ assert allEventsListener.viewChanged.getNewView().equals(view);
+ assert allEventsListener.viewChanged.getType() == Event.Type.VIEW_CHANGED;
+ }
+
+ public void testNotifyBuddyGroupChange()
+ {
+ assert allEventsListener.buddyGroupChangedEvent == null;
+ BuddyGroup buddyGroup = new BuddyGroup();
+ notifier.notifyBuddyGroupChange(buddyGroup, true);
+ assert allEventsListener.buddyGroupChangedEvent != null;
+ assert allEventsListener.buddyGroupChangedEvent.getBuddyGroup().equals(buddyGroup);
+ assert allEventsListener.buddyGroupChangedEvent.getType() == Event.Type.BUDDY_GROUP_CHANGED;
+ }
+
+ public void testNotifyTransactionCompleted()
+ {
+ assert allEventsListener.transactionCompleted == null;
+ Transaction tx = createNiceMock(Transaction.class);
+ notifier.notifyTransactionCompleted(tx, false, ctx);
+ assert allEventsListener.transactionCompleted != null;
+ assert allEventsListener.transactionCompleted.getTransaction() == tx;
+ assert !allEventsListener.transactionCompleted.isSuccessful();
+ assert allEventsListener.transactionCompleted.getType() == Event.Type.TRANSACTION_COMPLETED;
+ }
+
+ public void testNotifyTransactionRegistered()
+ {
+ assert allEventsListener.transactionRegistered == null;
+ Transaction tx = createNiceMock(Transaction.class);
+ notifier.notifyTransactionRegistered(tx, ctx);
+ assert allEventsListener.transactionRegistered != null;
+ assert allEventsListener.transactionRegistered.getTransaction() == tx;
+ assert allEventsListener.transactionRegistered.getType() == Event.Type.TRANSACTION_REGISTERED;
+ }
+
+ public void testNotifyCacheBlocked()
+ {
+ assert allEventsListener.cacheBlockedEvent == null;
+ notifier.notifyCacheBlocked(false);
+ assert allEventsListener.cacheBlockedEvent != null;
+ assert !allEventsListener.cacheBlockedEvent.isPre();
+ assert allEventsListener.cacheBlockedEvent.getType() == Event.Type.CACHE_BLOCKED;
+ }
+
+ public void testNotifyCacheUnblocked()
+ {
+ assert allEventsListener.cacheUnblockedEvent== null;
+ notifier.notifyCacheUnblocked(false);
+ assert allEventsListener.cacheUnblockedEvent != null;
+ assert !allEventsListener.cacheUnblockedEvent.isPre();
+ assert allEventsListener.cacheUnblockedEvent.getType() == Event.Type.CACHE_UNBLOCKED;
+ }
+
+ @CacheListener
+ public static class AllEventsListener
+ {
+ CacheStartedEvent cacheStartedEvent;
+ CacheStoppedEvent cacheStoppedEvent;
+ CacheBlockedEvent cacheBlockedEvent;
+ CacheUnblockedEvent cacheUnblockedEvent;
+ NodeCreatedEvent nodeCreatedEvent;
+ NodeRemovedEvent nodeRemoveEvent;
+ NodeVisitedEvent nodeVisistedEvent;
+ NodeModifiedEvent nodeModifiedEvent;
+ NodeMovedEvent nodeMovedEvent;
+ NodeActivatedEvent nodeActivatedEvent;
+ NodePassivatedEvent nodePassivatedEvent;
+ NodeLoadedEvent nodeLoadedEvent;
+ NodeEvictedEvent nodeEvictedEvent;
+ TransactionRegisteredEvent transactionRegistered;
+ TransactionCompletedEvent transactionCompleted;
+ ViewChangedEvent viewChanged;
+ BuddyGroupChangedEvent buddyGroupChangedEvent;
+
+ @CacheStarted
+ public void onCacheStarted(CacheStartedEvent event)
+ {
+ cacheStartedEvent = event;
+ }
+
+ @CacheStopped
+ public void onCacheStopped(CacheStoppedEvent event)
+ {
+ cacheStoppedEvent = event;
+ }
+
+ @CacheBlocked
+ public void onCacheBlocked(CacheBlockedEvent event)
+ {
+ cacheBlockedEvent = event;
+ }
+
+ @CacheUnblocked
+ public void onCacheUnblocked(CacheUnblockedEvent event)
+ {
+ cacheUnblockedEvent = event;
+ }
+
+ @NodeCreated
+ public void onNodeCreated(NodeCreatedEvent event)
+ {
+ nodeCreatedEvent = event;
+ }
+
+ @NodeRemoved
+ public void onNodeRemoved(NodeRemovedEvent event)
+ {
+ nodeRemoveEvent = event;
+ }
+
+ @NodeVisited
+ public void onNodeVisited(NodeVisitedEvent event)
+ {
+ nodeVisistedEvent = event;
+ }
+
+ @NodeModified
+ public void onNodeModified(NodeModifiedEvent event)
+ {
+ nodeModifiedEvent = event;
+ }
+
+ @NodeMoved
+ public void onNodeMoved(NodeMovedEvent event)
+ {
+ nodeMovedEvent = event;
+ }
+
+ @NodeActivated
+ public void onNodeActivated(NodeActivatedEvent event)
+ {
+ nodeActivatedEvent = event;
+ }
+
+ @NodePassivated
+ public void onNodePassivated(NodePassivatedEvent event)
+ {
+ nodePassivatedEvent = event;
+ }
+
+ @NodeLoaded
+ public void onNodeLoaded(NodeLoadedEvent event)
+ {
+ nodeLoadedEvent = event;
+ }
+
+ @NodeEvicted
+ public void onNodeEvicted(NodeEvictedEvent event)
+ {
+ nodeEvictedEvent = event;
+ }
+
+ @TransactionRegistered
+ public void onTransactionRegistered(TransactionRegisteredEvent event)
+ {
+ transactionRegistered = event;
+ }
+
+ @TransactionCompleted
+ public void onTransactionCompleted(TransactionCompletedEvent event)
+ {
+ transactionCompleted = event;
+ }
+
+ @ViewChanged
+ public void onViewChanged(ViewChangedEvent event)
+ {
+ viewChanged = event;
+ }
+
+ @BuddyGroupChanged
+ public void onBuddyGroupChanged(BuddyGroupChangedEvent event)
+ {
+ buddyGroupChangedEvent = event;
+ }
+ }
+}
More information about the jbosscache-commits
mailing list