Author: galder.zamarreno(a)jboss.com
Date: 2009-02-10 15:35:01 -0500 (Tue, 10 Feb 2009)
New Revision: 7676
Modified:
core/trunk/src/main/java/org/jboss/cache/config/Option.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerTest.java
Log:
[JBCACHE-1470] This time is correct :). Added suppress event notification option override.
Extended set of cache listener tests so that they're executed both and without
suppress event notification and make sure the event notification expectations are correct
in each scenario.
Modified: core/trunk/src/main/java/org/jboss/cache/config/Option.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Option.java 2009-02-10 13:55:59 UTC
(rev 7675)
+++ core/trunk/src/main/java/org/jboss/cache/config/Option.java 2009-02-10 20:35:01 UTC
(rev 7676)
@@ -27,6 +27,7 @@
* Used to override characteristics of specific calls to the cache. The javadocs of each
of the setters below detail functionality and behaviour.
*
* @author <a href="mailto:manik AT jboss DOT org">Manik Surtani (manik
AT jboss DOT org)</a>
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
* @since 1.3.0
*/
public class Option implements Cloneable
@@ -49,6 +50,7 @@
private int lockAcquisitionTimeout = -1;
private boolean suppressPersistence;
+ private boolean suppressEventNotification;
/**
* @since 1.4.0
@@ -270,6 +272,8 @@
", skipDataGravitation=" + skipDataGravitation +
", forceAsynchronous=" + forceAsynchronous +
", forceSynchronous=" + forceSynchronous +
+ ", suppressPersistence=" + suppressPersistence +
+ ", suppressEventNotification=" + suppressEventNotification +
'}';
}
@@ -320,6 +324,7 @@
if (forceSynchronous != option.forceSynchronous) return false;
if (lockAcquisitionTimeout != option.lockAcquisitionTimeout) return false;
if (suppressPersistence != option.suppressPersistence) return false;
+ if (suppressEventNotification != option.suppressEventNotification) return false;
return true;
}
@@ -338,6 +343,7 @@
result = 29 * result + (forceSynchronous ? 0 : 1);
result = 29 * result + (lockAcquisitionTimeout);
result = 29 * result + (suppressPersistence ? 0 : 1);
+ result = 29 * result + (suppressEventNotification ? 0 : 1);
return result;
}
@@ -357,6 +363,7 @@
this.forceSynchronous = false;
this.lockAcquisitionTimeout = -1;
this.suppressPersistence = false;
+ this.suppressEventNotification = false;
}
/**
@@ -475,4 +482,29 @@
{
this.suppressPersistence = suppressPersistence;
}
+
+ /**
+ * Get whether event notifications for this invocation will be suppresed. By
+ * default is false which means that corresponding events are sent depending
+ * on the type of invocation.
+ *
+ * @return true, if event notification will be suppressed for this invocation.
+ */
+ public boolean isSuppressEventNotification()
+ {
+ return suppressEventNotification;
+ }
+
+ /**
+ * Set whether event notifications should be suppressed for this particular
+ * cache or transaction invocation.
+ *
+ * @param suppressEventNotification <code>true</code> if event
notification
+ * should be skipped; <code>false</code> if
events
+ * should be notified if there're any listeners.
+ */
+ public void setSuppressEventNotification(boolean suppressEventNotification)
+ {
+ this.suppressEventNotification = suppressEventNotification;
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2009-02-10
13:55:59 UTC (rev 7675)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2009-02-10
20:35:01 UTC (rev 7676)
@@ -21,7 +21,6 @@
*/
package org.jboss.cache.interceptors;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -67,7 +66,6 @@
import org.jboss.cache.transaction.TransactionContext;
import org.jboss.cache.transaction.TransactionLog;
import org.jboss.cache.transaction.TransactionTable;
-import org.jboss.cache.util.Immutables;
import org.jboss.cache.util.concurrent.ConcurrentHashSet;
/**
@@ -78,6 +76,7 @@
*
* @author <a href="mailto:manik AT jboss DOT org">Manik Surtani (manik
AT jboss DOT org)</a>
* @author <a href="mailto:stevew@jofti.com">Steve Woodcock
(stevew(a)jofti.com)</a>
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
*/
public class TxInterceptor extends BaseTransactionalContextInterceptor
{
@@ -956,7 +955,9 @@
{
// this should ideally be set in beforeCompletion(), after compacting the
list.
if (modifications == null) modifications =
transactionContext.getModifications();
+ boolean isSuppressEventNotification =
ctx.getOptionOverrides().isSuppressEventNotification();
ctx.setOptionOverrides(transactionContext.getOption());
+
ctx.getOptionOverrides().setSuppressEventNotification(isSuppressEventNotification);
}
if (tx != null) transactions.remove(tx);
@@ -1086,6 +1087,7 @@
// set any transaction wide options as current for this thread, caching original
options that would then be reset
originalOptions = ctx.getOptionOverrides();
transactionalOptions = transactionContext.getOption();
+
transactionalOptions.setSuppressEventNotification(originalOptions.isSuppressEventNotification());
ctx.setOptionOverrides(transactionalOptions);
try
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2009-02-10
13:55:59 UTC (rev 7675)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2009-02-10
20:35:01 UTC (rev 7676)
@@ -64,6 +64,7 @@
* Helper class that handles all notifications to registered listeners.
*
* @author <a href="mailto:manik AT jboss DOT org">Manik Surtani (manik
AT jboss DOT org)</a>
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
*/
@NonVolatile
public class NotifierImpl implements Notifier
@@ -307,7 +308,7 @@
public void notifyNodeCreated(Fqn fqn, boolean pre, InvocationContext ctx)
{
- if (!nodeCreatedListeners.isEmpty())
+ if (!nodeCreatedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
@@ -326,7 +327,7 @@
public void notifyNodeModified(Fqn fqn, boolean pre,
NodeModifiedEvent.ModificationType modificationType, Map data, InvocationContext ctx)
{
- if (!nodeModifiedListeners.isEmpty())
+ if (!nodeModifiedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean originLocal = ctx.isOriginLocal();
Map dataCopy = copy(data, useMarshalledValueMaps);
@@ -353,7 +354,7 @@
public void notifyNodeRemoved(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
- if (!nodeRemovedListeners.isEmpty())
+ if (!nodeRemovedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean originLocal = ctx.isOriginLocal();
Map dataCopy = copy(data, useMarshalledValueMaps);
@@ -374,7 +375,7 @@
public void notifyNodeVisited(Fqn fqn, boolean pre, InvocationContext ctx)
{
- if (!nodeVisitedListeners.isEmpty())
+ if (!nodeVisitedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -391,7 +392,7 @@
public void notifyNodeMoved(Fqn originalFqn, Fqn newFqn, boolean pre,
InvocationContext ctx)
{
- if (!nodeMovedListeners.isEmpty())
+ if (!nodeMovedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
@@ -411,7 +412,7 @@
public void notifyNodeEvicted(final Fqn fqn, final boolean pre, InvocationContext
ctx)
{
- if (!nodeEvictedListeners.isEmpty())
+ if (!nodeEvictedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
final boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
@@ -430,7 +431,7 @@
public void notifyNodeInvalidated(final Fqn fqn, final boolean pre, InvocationContext
ctx)
{
- if (!nodeInvalidatedListeners.isEmpty())
+ if (!nodeInvalidatedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
final boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
@@ -449,7 +450,7 @@
public void notifyNodeLoaded(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
- if (!nodeLoadedListeners.isEmpty())
+ if (!nodeLoadedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean originLocal = ctx.isOriginLocal();
Map dataCopy = copy(data, useMarshalledValueMaps);
@@ -470,7 +471,7 @@
public void notifyNodeActivated(Fqn fqn, boolean pre, Map data, InvocationContext
ctx)
{
- if (!nodeActivatedListeners.isEmpty())
+ if (!nodeActivatedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean originLocal = ctx.isOriginLocal();
Map dataCopy = copy(data, useMarshalledValueMaps);
@@ -491,7 +492,7 @@
public void notifyNodePassivated(Fqn fqn, boolean pre, Map data, InvocationContext
ctx)
{
- if (!nodePassivatedListeners.isEmpty())
+ if (!nodePassivatedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
Map dataCopy = copy(data, useMarshalledValueMaps);
Transaction tx = ctx.getTransaction();
@@ -567,7 +568,7 @@
public void notifyTransactionCompleted(Transaction transaction, boolean successful,
InvocationContext ctx)
{
- if (!transactionCompletedListeners.isEmpty())
+ if (!transactionCompletedListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean isOriginLocal = ctx.isOriginLocal();
InvocationContext backup = resetInvocationContext(ctx);
@@ -584,7 +585,7 @@
public void notifyTransactionRegistered(Transaction transaction, InvocationContext
ctx)
{
- if (!transactionRegisteredListeners.isEmpty())
+ if (!transactionRegisteredListeners.isEmpty() &&
!ctx.getOptionOverrides().isSuppressEventNotification())
{
boolean isOriginLocal = ctx.isOriginLocal();
InvocationContext backup = resetInvocationContext(ctx);
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerTest.java 2009-02-10
13:55:59 UTC (rev 7675)
+++
core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerTest.java 2009-02-10
20:35:01 UTC (rev 7676)
@@ -12,6 +12,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Option;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.notifications.event.Event;
import static org.jboss.cache.notifications.event.Event.Type.*;
@@ -38,6 +39,7 @@
* exercises the new CacheListener annotation.
*
* @since 2.0.0
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
*/
@Test(groups = "functional", sequential = true, testName =
"notifications.CacheListenerTest")
public class CacheListenerTest
@@ -78,32 +80,53 @@
// simple tests first
- public void testCreation() throws Exception
+ public void testCreation()
{
+ creation(false);
+ eventLog.events.clear();
+ creation(true);
+ }
+
+ protected void creation(boolean supressEventNotification)
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.put(fqn, "key", "value");
Map<Object, Object> data = new HashMap<Object, Object>();
data.put("key", "value");
//expected
List<Event> expected = new ArrayList<Event>();
- if (optLocking)
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn,
null, true, null, false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, null, true, null,
false, null, NODE_MODIFIED));
- if (optLocking)
+ if (!supressEventNotification)
{
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
- eventLog.scrubImplicitTransactions();
+ if (optLocking)
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null,
false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null,
false, null, NODE_CREATED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn,
null, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, null, true, null,
false, null, NODE_MODIFIED));
+ if (optLocking)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
+ eventLog.scrubImplicitTransactions();
+ }
}
assertEquals(expected, eventLog.events);
- assertEquals("value", cache.get(fqn, "key"));
+ assertEquals("value", cache.get(fqn, "key"));
}
- public void testOnlyModification() throws Exception
+ public void testOnlyModification()
{
+ onlyModification(false);
+ eventLog.events.clear();
+ onlyModification(true);
+ }
+
+ protected void onlyModification(boolean supressEventNotification)
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
cache.put(fqn, "key", "value");
Map<Object, Object> oldData = new HashMap<Object, Object>();
@@ -114,28 +137,42 @@
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
// modify existing node
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.put(fqn, "key", "value2");
Map<Object, Object> newData = new HashMap<Object, Object>();
newData.put("key", "value2");
//expected
List<Event> expected = new ArrayList<Event>();
- if (optLocking)
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, PUT_DATA, oldData, fqn, null, true, null,
false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, PUT_DATA, newData, fqn, null, true, null,
false, null, NODE_MODIFIED));
- if (optLocking)
+ if (!supressEventNotification)
{
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
- eventLog.scrubImplicitTransactions();
+ if (optLocking)
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, oldData, fqn, null, true,
null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, newData, fqn, null, true,
null, false, null, NODE_MODIFIED));
+ if (optLocking)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
+ eventLog.scrubImplicitTransactions();
+ }
}
assertEquals(expected.size(), eventLog.events.size());
assertEquals(expected, eventLog.events);
}
- public void testOnlyRemoval() throws Exception
+ public void testOnlyRemoval()
{
+ onlyRemoval(false);
+ eventLog.events.clear();
+ onlyRemoval(true);
+ }
+
+ protected void onlyRemoval(boolean supressEventNotification)
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
cache.put(fqn, "key", "value");
Map<Object, Object> oldData = new HashMap<Object, Object>();
@@ -148,18 +185,25 @@
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
// modify existing node
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.removeNode(fqn);
//expected
List<Event> expected = new ArrayList<Event>();
- if (optLocking)
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, null, oldData, fqn, null, true, null,
false, null, NODE_REMOVED));
- expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false,
null, NODE_REMOVED));
- if (optLocking)
+ if (!supressEventNotification)
{
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
- eventLog.scrubImplicitTransactions();
+ if (optLocking)
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, oldData, fqn, null, true, null,
false, null, NODE_REMOVED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null,
false, null, NODE_REMOVED));
+ if (optLocking)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
+ eventLog.scrubImplicitTransactions();
+ }
}
assertEquals(expected, eventLog.events);
@@ -168,22 +212,42 @@
assertNull("Should be null", cache.getRoot().getChild(fqn));
}
- public void testNonexistentRemove() throws Exception
+ public void testNonexistentRemove()
{
+ nonexistentRemove(false);
+ eventLog.events.clear();
+ nonexistentRemove(true);
+ }
+
+ protected void nonexistentRemove(boolean supressEventNotification)
+ {
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.removeNode("/does/not/exist");
List<Event> expected = new ArrayList<Event>();
-
- if (optLocking)
+ if (!supressEventNotification)
{
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
- eventLog.scrubImplicitTransactions();
+ if (optLocking)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
+ eventLog.scrubImplicitTransactions();
+ }
}
assertEquals(expected, eventLog.events);
}
- public void testRemoveData() throws Exception
+ public void testRemoveData()
{
+ removeData(false);
+ eventLog.events.clear();
+ removeData(true);
+ }
+
+ protected void removeData(boolean supressEventNotification)
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
cache.put(fqn, "key", "value");
cache.put(fqn, "key2", "value2");
@@ -196,6 +260,10 @@
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
// modify existing node
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.remove(fqn, "key2");
Map<Object, Object> removedData = new HashMap<Object, Object>();
removedData.put("key2", "value2");
@@ -203,14 +271,17 @@
//expected
List<Event> expected = new ArrayList<Event>();
- if (optLocking)
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, REMOVE_DATA, oldData, fqn, null, true,
null, false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, REMOVE_DATA, removedData, fqn, null, true,
null, false, null, NODE_MODIFIED));
- if (optLocking)
+ if (!supressEventNotification)
{
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
- eventLog.scrubImplicitTransactions();
+ if (optLocking)
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, REMOVE_DATA, oldData, fqn, null, true,
null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, REMOVE_DATA, removedData, fqn, null,
true, null, false, null, NODE_MODIFIED));
+ if (optLocking)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
+ eventLog.scrubImplicitTransactions();
+ }
}
assertEquals(expected, eventLog.events);
@@ -218,6 +289,13 @@
public void testPutMap() throws Exception
{
+ putMap(false);
+ eventLog.events.clear();
+ putMap(true);
+ }
+
+ protected void putMap(boolean supressEventNotification)
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
Map<Object, Object> oldData = new HashMap<Object, Object>();
oldData.put("key", "value");
@@ -228,20 +306,27 @@
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
// modify existing node
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.put(fqn, oldData);
//expected
List<Event> expected = new ArrayList<Event>();
- if (optLocking)
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(true, cache, PUT_MAP, Collections.emptyMap(), fqn, null,
true, null, false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, PUT_MAP, oldData, fqn, null, true, null,
false, null, NODE_MODIFIED));
- if (optLocking)
- {
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
- eventLog.scrubImplicitTransactions();
+ if (!supressEventNotification)
+ {
+ if (optLocking)
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null,
false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null,
false, null, NODE_CREATED));
+ expected.add(new EventImpl(true, cache, PUT_MAP, Collections.emptyMap(), fqn,
null, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_MAP, oldData, fqn, null, true,
null, false, null, NODE_MODIFIED));
+ if (optLocking)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
+ eventLog.scrubImplicitTransactions();
+ }
}
assertEquals(expected, eventLog.events);
@@ -249,6 +334,13 @@
public void testMove()
{
+ move(false);
+ eventLog.events.clear();
+ move(true);
+ }
+
+ protected void move(boolean supressEventNotification)
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
Fqn newParent = Fqn.fromString("/a");
cache.put(fqn, "key", "value");
@@ -259,19 +351,26 @@
eventLog.events.clear();// clear events
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.move(n1.getFqn(), n2.getFqn());
//expected
Fqn newFqn = Fqn.fromRelativeElements(newParent, fqn.getLastElement());
List<Event> expected = new ArrayList<Event>();
- if (optLocking)
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, null, null, fqn, null, true, newFqn, false,
null, NODE_MOVED));
- expected.add(new EventImpl(false, cache, null, null, fqn, null, true, newFqn,
false, null, NODE_MOVED));
- if (optLocking)
- {
- expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
- eventLog.scrubImplicitTransactions();
+ if (!supressEventNotification)
+ {
+ if (optLocking)
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, newFqn,
false, null, NODE_MOVED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, newFqn,
false, null, NODE_MOVED));
+ if (optLocking)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, null, true, null,
true, null, TRANSACTION_COMPLETED));
+ eventLog.scrubImplicitTransactions();
+ }
}
assertEquals(expected, eventLog.events);
@@ -281,63 +380,138 @@
public void testTxNonexistentRemove() throws Exception
{
+ txNonexistentRemove(false);
+ eventLog.events.clear();
+ txNonexistentRemove(true);
+ }
+
+ protected void txNonexistentRemove(boolean supressEventNotification) throws Exception
+ {
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.begin();
Transaction tx = tm.getTransaction();
cache.removeNode("/does/not/exist");
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.commit();
List<Event> expected = new ArrayList<Event>();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false,
null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ }
assertEquals(expected, eventLog.events);
}
-
+
public void testTxCreationCommit() throws Exception
{
+ txCreationCommit(false);
+ eventLog.events.clear();
+ txCreationCommit(true);
+ }
+
+ protected void txCreationCommit(boolean supressEventNotification) throws Exception
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.begin();
Transaction tx = tm.getTransaction();
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.put(fqn, "key", "value");
//expected
Map<Object, Object> data = new HashMap<Object, Object>();
data.put("key", "value");
List<Event> expected = new ArrayList<Event>();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false,
null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn, tx,
true, null, false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, tx, true, null,
false, null, NODE_MODIFIED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn,
tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, tx, true, null,
false, null, NODE_MODIFIED));
+ }
assertEquals(expected, eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.commit();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ }
assertEquals(expected, eventLog.events);
assertEquals("value", cache.get(fqn, "key"));
}
public void testTxCreationRollback() throws Exception
{
+ txCreationRollback(false);
+ eventLog.events.clear();
+ txCreationRollback(true);
+ }
+
+ protected void txCreationRollback(boolean supressEventNotification) throws Exception
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.begin();
Transaction tx = tm.getTransaction();
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.put(fqn, "key", "value");
//expected
Map<Object, Object> data = new HashMap<Object, Object>();
data.put("key", "value");
List<Event> expected = new ArrayList<Event>();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false,
null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
- expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn, tx,
true, null, false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, tx, true, null,
false, null, NODE_MODIFIED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false,
null, NODE_CREATED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, Collections.emptyMap(), fqn,
tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, data, fqn, tx, true, null,
false, null, NODE_MODIFIED));
+ }
assertEquals(expected, eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.rollback();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false,
null, TRANSACTION_COMPLETED));
- assertEquals(expected, eventLog.events);
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_COMPLETED));
+ }
+ assertEquals(expected, eventLog.events);
}
public void testTxOnlyModification() throws Exception
{
+ txOnlyModification(false);
+ eventLog.events.clear();
+ txOnlyModification(true);
+ }
+
+ protected void txOnlyModification(boolean supressEventNotification) throws Exception
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
cache.put(fqn, "key", "value");
Map<Object, Object> oldData = new HashMap<Object, Object>();
@@ -348,26 +522,51 @@
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
// modify existing node
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.begin();
Transaction tx = tm.getTransaction();
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.put(fqn, "key", "value2");
Map<Object, Object> newData = new HashMap<Object, Object>();
newData.put("key", "value2");
//expected
List<Event> expected = new ArrayList<Event>();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false,
null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, PUT_DATA, oldData, fqn, tx, true, null,
false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, PUT_DATA, newData, fqn, tx, true, null,
false, null, NODE_MODIFIED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, oldData, fqn, tx, true, null,
false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, newData, fqn, tx, true, null,
false, null, NODE_MODIFIED));
+ }
assertEquals(expected, eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.commit();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ }
assertEquals(expected, eventLog.events);
- }
+ }
public void testTxOnlyRemoval() throws Exception
{
+ txOnlyRemoval(false);
+ eventLog.events.clear();
+ txOnlyRemoval(true);
+ }
+
+ protected void txOnlyRemoval(boolean supressEventNotification) throws Exception
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
cache.put(fqn, "key", "value");
Map<Object, Object> oldData = new HashMap<Object, Object>();
@@ -380,19 +579,36 @@
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
// modify existing node
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.begin();
Transaction tx = tm.getTransaction();
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.removeNode(fqn);
//expected
List<Event> expected = new ArrayList<Event>();
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, oldData, fqn, tx, true, null,
false, null, NODE_REMOVED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false,
null, NODE_REMOVED));
+ }
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false,
null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, null, oldData, fqn, tx, true, null, false,
null, NODE_REMOVED));
- expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false,
null, NODE_REMOVED));
-
assertEquals(expected, eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.commit();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ }
assertEquals(expected, eventLog.events);
// test that the node has in fact been removed.
assertNull("Should be null", cache.getRoot().getChild(fqn));
@@ -400,6 +616,13 @@
public void testTxRemoveData() throws Exception
{
+ txRemoveData(false);
+ eventLog.events.clear();
+ txRemoveData(true);
+ }
+
+ protected void txRemoveData(boolean supressEventNotification) throws Exception
+ {
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
cache.put(fqn, "key", "value");
cache.put(fqn, "key2", "value2");
@@ -412,20 +635,38 @@
assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
// modify existing node
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.begin();
Transaction tx = tm.getTransaction();
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
cache.remove(fqn, "key2");
Map<Object, Object> removedData = new HashMap<Object, Object>();
removedData.put("key2", "value2");
//expected
List<Event> expected = new ArrayList<Event>();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false,
null, TRANSACTION_REGISTERED));
- expected.add(new EventImpl(true, cache, REMOVE_DATA, oldData, fqn, tx, true, null,
false, null, NODE_MODIFIED));
- expected.add(new EventImpl(false, cache, REMOVE_DATA, removedData, fqn, tx, true,
null, false, null, NODE_MODIFIED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, REMOVE_DATA, oldData, fqn, tx, true,
null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, REMOVE_DATA, removedData, fqn, tx,
true, null, false, null, NODE_MODIFIED));
+ }
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
tm.commit();
- expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ }
assertEquals(expected, eventLog.events);
assertEquals(expected, eventLog.events);
@@ -458,4 +699,57 @@
expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
assertEquals(expected, eventLog.events);
}
+
+ protected void txMove(boolean supressEventNotification) throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
+ Fqn newParent = Fqn.fromString("/a");
+ cache.put(fqn, "key", "value");
+ cache.put(newParent, "key", "value");
+
+ Node<Object, Object> n1 = cache.getRoot().getChild(fqn);
+ Node<Object, Object> n2 = cache.getRoot().getChild(newParent);
+ eventLog.events.clear();// clear events
+ assertEquals("Event log should be empty", Collections.emptyList(),
eventLog.events);
+
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
+ cache.move(n1.getFqn(), n2.getFqn());
+ //expected
+ Fqn newFqn = Fqn.fromRelativeElements(newParent, fqn.getLastElement());
+ List<Event> expected = new ArrayList<Event>();
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null,
false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, newFqn,
false, null, NODE_MOVED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, newFqn,
false, null, NODE_MOVED));
+ }
+
+ assertEquals(expected, eventLog.events);
+ if (supressEventNotification)
+ {
+ setSuppressEventNotification();
+ }
+ tm.commit();
+ if (!supressEventNotification)
+ {
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true,
null, TRANSACTION_COMPLETED));
+ }
+ assertEquals(expected, eventLog.events);
+ }
+
+ protected void setSuppressEventNotification()
+ {
+ Option option = new Option();
+ option.setSuppressEventNotification(true);
+ cache.getInvocationContext().setOptionOverrides(option);
+ }
}