Author: manik.surtani(a)jboss.com
Date: 2008-06-26 13:22:45 -0400 (Thu, 26 Jun 2008)
New Revision: 6065
Added:
core/trunk/src/test/java/org/jboss/cache/commands/TestContextBase.java
Removed:
core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/read/ExistsCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/AbstractVersionedDataCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.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/commands/write/RemoveNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java
core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeyValueCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/AbstractVersionedDataCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/PutDataMapCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/PutKeyValueCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java
Log:
Preparing commands for MVCC
Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/ExistsCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/ExistsCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/ExistsCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -40,6 +40,7 @@
*/
public Object perform(InvocationContext ctx)
{
+ // this command will use the data container directly since it does not require any
form of locking.
return dataContainer.exists(fqn);
}
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -41,7 +41,7 @@
*/
public Object perform(InvocationContext ctx)
{
- NodeSPI n = dataContainer.peek(fqn);
+ NodeSPI n = ctx.lookUpNode(fqn);
if (n == null) return null;
Map childrenMap = n.getChildrenMapDirect();
if (childrenMap == null || childrenMap.isEmpty()) return Collections.emptySet();
Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -35,7 +35,7 @@
*/
public Object perform(InvocationContext ctx)
{
- NodeSPI n = dataContainer.peek(fqn);
+ NodeSPI n = ctx.lookUpNode(fqn);
if (n == null) return null;
return new MapCopy(n.getDataDirect());
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -57,7 +57,7 @@
log.trace(new
StringBuffer("get(").append("\"").append(fqn).append("\",
\"").append(key).append("\", \"").
append(sendNodeEvent).append("\")"));
}
- NodeSPI n = dataContainer.peek(fqn);
+ NodeSPI n = ctx.lookUpNode(fqn);
if (n == null)
{
log.trace("node not found");
Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -36,7 +36,7 @@
@SuppressWarnings("unchecked")
public Object perform(InvocationContext ctx)
{
- NodeSPI n = dataContainer.peek(fqn);
+ NodeSPI n = ctx.lookUpNode(fqn);
if (n == null) return null;
return n.getKeysDirect();
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -34,7 +34,7 @@
*/
public Object perform(InvocationContext ctx)
{
- return dataContainer.peek(fqn);
+ return ctx.lookUpNode(fqn);
}
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -73,6 +73,8 @@
@SuppressWarnings("unchecked")
public Object perform(InvocationContext ctx)
{
+ // TODO: Test this with MVCC.
+
// for now, perform a very simple series of getData calls.
if (trace) log.trace("Caller is asking for " + fqn);
try
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/write/AbstractVersionedDataCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/write/AbstractVersionedDataCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/AbstractVersionedDataCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,5 +1,6 @@
package org.jboss.cache.commands.write;
+import org.jboss.cache.CacheException;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
import org.jboss.cache.commands.VersionedDataCommand;
@@ -20,13 +21,24 @@
protected DataVersion dataVersion;
protected GlobalTransaction globalTransaction;
+ private boolean suppressRollbacks;
- public void initialize(Notifier notifier, DataContainer dataContainer)
+ public void initialize(Notifier notifier, DataContainer dataContainer, boolean
suppressRollbacks)
{
this.notifier = notifier;
this.dataContainer = dataContainer;
+ this.suppressRollbacks = suppressRollbacks;
}
+ /**
+ * Test if the current node locking scheme allows for rollbacks.
+ */
+ protected void assertRollbackAllowed()
+ {
+ if (suppressRollbacks)
+ throw new CacheException("Rollback should never be called directly on a
command when using MVCC, since this should be dealt with in the
MVCCLockingInterceptor.");
+ }
+
public DataVersion getDataVersion()
{
return dataVersion;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -49,7 +49,9 @@
public Object perform(InvocationContext ctx)
{
if (trace) log.trace("perform(" + globalTransaction + ",
\"" + fqn + "\")");
+
NodeSPI targetNode = dataContainer.peekVersioned(fqn, dataVersion);
+// NodeSPI targetNode = ctx.lookUpNode(fqn);
if (targetNode == null)
{
log.warn("node " + fqn + " not found");
@@ -74,6 +76,7 @@
public void rollback()
{
+ assertRollbackAllowed();
if (trace) log.trace("rollback(" + globalTransaction + ",
\"" + fqn + "\", " + originalData + ")");
NodeSPI nodeSpi = dataContainer.peek(fqn, false, true);
if (nodeSpi == null)
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,5 +1,6 @@
package org.jboss.cache.commands.write;
+import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.ReversibleCommand;
@@ -21,10 +22,12 @@
{
public static final int METHOD_ID = 48;
private final List<Fqn> newlyCreated = new LinkedList<Fqn>();
+ private boolean suppressRollbacks;
- public CreateNodeCommand(Fqn fqn)
+ public CreateNodeCommand(Fqn fqn, boolean suppressRollbacks)
{
this.fqn = fqn;
+ this.suppressRollbacks = suppressRollbacks;
newlyCreated.add(fqn);
}
@@ -32,6 +35,15 @@
{
}
+ /**
+ * Test if the current node locking scheme allows for rollbacks.
+ */
+ protected void assertRollbackAllowed()
+ {
+ if (suppressRollbacks)
+ throw new CacheException("Rollback should never be called directly on a
command when using MVCC, since this should be dealt with in the
MVCCLockingInterceptor.");
+ }
+
public int getCommandId()
{
return METHOD_ID;
@@ -76,6 +88,7 @@
public void rollback()
{
+ assertRollbackAllowed();
if (newlyCreated != null)
{
for (Fqn f : newlyCreated) dataContainer.removeFromDataStructure(f, true);
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -2,6 +2,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeNotExistsException;
@@ -25,6 +26,7 @@
public static final int METHOD_ID = 36;
private static final Log log = LogFactory.getLog(MoveCommand.class);
private static boolean trace = log.isTraceEnabled();
+ private boolean suppressRollbacks;
/* dependencies */
private Notifier notifier;
@@ -37,10 +39,11 @@
{
}
- public void initialize(Notifier notifier, DataContainer dataContainer)
+ public void initialize(Notifier notifier, DataContainer dataContainer, boolean
suppressRollbacks)
{
this.notifier = notifier;
this.dataContainer = dataContainer;
+ this.suppressRollbacks = suppressRollbacks;
}
public MoveCommand(Fqn from, Fqn to)
@@ -49,6 +52,15 @@
this.to = to;
}
+ /**
+ * Test if the current node locking scheme allows for rollbacks.
+ */
+ protected void assertRollbackAllowed()
+ {
+ if (suppressRollbacks)
+ throw new CacheException("Rollback should never be called directly on a
command when using MVCC, since this should be dealt with in the
MVCCLockingInterceptor.");
+ }
+
public GlobalTransaction getGlobalTransaction()
{
return globalTransaction;
@@ -73,6 +85,7 @@
public void rollback()
{
+ assertRollbackAllowed();
move(Fqn.fromRelativeElements(to, fqn.getLastElement()), fqn.getParent(), true,
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-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -3,6 +3,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.Visitor;
import org.jboss.cache.invocation.InvocationContext;
@@ -54,7 +55,9 @@
{
log.trace("perform(" + globalTransaction + ", \"" + fqn
+ "\", " + data + ")");
}
- NodeSPI nodeSPI = dataContainer.peekStrict(globalTransaction, fqn, false);
+// NodeSPI nodeSPI = dataContainer.peekStrict(globalTransaction, fqn, false);
+ NodeSPI nodeSPI = ctx.lookUpNode(fqn);
+ if (nodeSPI == null) throw new NodeNotExistsException("Node " + fqn +
" does not exist!");
Map existingData = nodeSPI.getDataDirect();
if (!existingData.isEmpty())
{
@@ -75,6 +78,7 @@
public void rollback()
{
+ assertRollbackAllowed();
if (trace) log.trace("rollback(" + globalTransaction + ", " +
fqn + ", " + data + ")");
NodeSPI n = dataContainer.peek(fqn, false, true);
if (n != 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-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -4,6 +4,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.Visitor;
import org.jboss.cache.invocation.InvocationContext;
@@ -58,7 +59,11 @@
log.trace(new
StringBuffer("perform(").append(globalTransaction).append(",
\"").
append(fqn).append("\", k=").append(key).append(",
v=").append(value).append(")"));
}
- NodeSPI n = dataContainer.peekStrict(globalTransaction, fqn, false);
+// NodeSPI n = dataContainer.peekStrict(globalTransaction, fqn, false);
+ NodeSPI n = ctx.lookUpNode(fqn);
+ if (n == null) throw new NodeNotExistsException("Node " + fqn + "
does not exist!");
+
+
if (notifier.shouldNotifyOnNodeModified())
{
notifier.notifyNodeModified(fqn, true,
NodeModifiedEvent.ModificationType.PUT_DATA, n.getDataDirect(), ctx);
@@ -75,6 +80,7 @@
public void rollback()
{
+ assertRollbackAllowed();
NodeSPI n = dataContainer.peek(fqn, false, false);
if (n == null) throw new CacheException("node " + fqn + " not found
for rollback!");
if (oldValue == null)
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-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -54,7 +54,8 @@
{
if (trace) log.trace("perform(" + globalTransaction + ",
\"" + fqn + "\", key=" + key + ")");
- NodeSPI n = dataContainer.peek(fqn, false, false);
+// NodeSPI n = dataContainer.peek(fqn, false, false);
+ NodeSPI n = ctx.lookUpNode(fqn);
if (n == null)
{
if (log.isDebugEnabled()) log.debug("node " + fqn + " not
found");
@@ -75,6 +76,7 @@
public void rollback()
{
+ assertRollbackAllowed();
NodeSPI targetNode = dataContainer.peek(fqn, false, true);
if (oldValue != null)
{
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -96,6 +96,7 @@
public void rollback()
{
+ assertRollbackAllowed();
if (targetNode != null)
{
Object childName = targetNode.getFqn().getLastElement();
Modified: core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java 2008-06-26
17:19:42 UTC (rev 6064)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -30,8 +30,10 @@
import org.jboss.cache.commands.tx.RollbackCommand;
import org.jboss.cache.commands.write.*;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.NonVolatile;
+import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.interceptors.InterceptorChain;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -68,6 +70,7 @@
private Configuration configuration;
private TransactionManager txManager;
private BuddyFqnTransformer buddyFqnTransformer;
+ private boolean suppressRollbacks;
public CommandsFactory()
{
@@ -90,25 +93,31 @@
this.buddyFqnTransformer = buddyFqnTransformer;
}
+ @Start
+ public void start()
+ {
+ suppressRollbacks = configuration.getNodeLockingScheme() ==
NodeLockingScheme.MVCC;
+ }
+
public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map
data)
{
PutDataMapCommand cmd = new PutDataMapCommand(gtx, fqn, data);
- cmd.initialize(notifier, dataContainer);
+ cmd.initialize(notifier, dataContainer, suppressRollbacks);
return cmd;
}
public PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn,
Object key, Object value)
{
- PutKeyValueCommand command = new PutKeyValueCommand(gtx, fqn, key, value);
- command.initialize(notifier, dataContainer);
- return command;
+ PutKeyValueCommand cmd = new PutKeyValueCommand(gtx, fqn, key, value);
+ cmd.initialize(notifier, dataContainer, suppressRollbacks);
+ return cmd;
}
public PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx,
Fqn fqn, Object key, Object value)
{
- PutForExternalReadCommand command = new PutForExternalReadCommand(gtx, fqn, key,
value);
- command.initialize(notifier, dataContainer);
- return command;
+ PutForExternalReadCommand cmd = new PutForExternalReadCommand(gtx, fqn, key,
value);
+ cmd.initialize(notifier, dataContainer, suppressRollbacks);
+ return cmd;
}
public ReplicateCommand buildReplicateCommand(ReplicableCommand command)
@@ -156,16 +165,16 @@
public RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn)
{
- RemoveNodeCommand command = new RemoveNodeCommand(gtx, fqn);
- command.initialize(notifier, dataContainer);
- return command;
+ RemoveNodeCommand cmd = new RemoveNodeCommand(gtx, fqn);
+ cmd.initialize(notifier, dataContainer, suppressRollbacks);
+ return cmd;
}
public ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn)
{
- ClearDataCommand command = new ClearDataCommand(gtx, fqn);
- command.initialize(notifier, dataContainer);
- return command;
+ ClearDataCommand cmd = new ClearDataCommand(gtx, fqn);
+ cmd.initialize(notifier, dataContainer, suppressRollbacks);
+ return cmd;
}
public EvictCommand buildEvictFqnCommand(Fqn fqn)
@@ -194,9 +203,9 @@
public RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn,
Object key)
{
- RemoveKeyCommand command = new RemoveKeyCommand(tx, fqn, key);
- command.initialize(notifier, dataContainer);
- return command;
+ RemoveKeyCommand cmd = new RemoveKeyCommand(tx, fqn, key);
+ cmd.initialize(notifier, dataContainer, suppressRollbacks);
+ return cmd;
}
public GetDataMapCommand buildGetDataMapCommand(Fqn fqn)
@@ -243,9 +252,9 @@
public MoveCommand buildMoveCommand(Fqn from, Fqn to)
{
- MoveCommand command = new MoveCommand(from, to);
- command.initialize(notifier, dataContainer);
- return command;
+ MoveCommand cmd = new MoveCommand(from, to);
+ cmd.initialize(notifier, dataContainer, suppressRollbacks);
+ return cmd;
}
public RollbackCommand buildRollbackCommand(GlobalTransaction gtx)
@@ -288,7 +297,7 @@
public CreateNodeCommand buildCreateNodeCommand(Fqn fqn)
{
- CreateNodeCommand command = new CreateNodeCommand(fqn);
+ CreateNodeCommand command = new CreateNodeCommand(fqn, suppressRollbacks);
command.initialize(dataContainer);
return command;
}
@@ -350,7 +359,7 @@
case MoveCommand.METHOD_ID:
{
MoveCommand returnValue = new MoveCommand();
- returnValue.initialize(notifier, dataContainer);
+ returnValue.initialize(notifier, dataContainer, suppressRollbacks);
command = returnValue;
break;
}
@@ -360,7 +369,7 @@
case PutDataMapCommand.VERSIONED_METHOD_ID:
{
PutDataMapCommand returnValue = new PutDataMapCommand();
- returnValue.initialize(notifier, dataContainer);
+ returnValue.initialize(notifier, dataContainer, suppressRollbacks);
command = returnValue;
break;
}
@@ -368,7 +377,7 @@
case PutKeyValueCommand.VERSIONED_METHOD_ID:
{
PutKeyValueCommand returnValue = new PutKeyValueCommand();
- returnValue.initialize(notifier, dataContainer);
+ returnValue.initialize(notifier, dataContainer, suppressRollbacks);
command = returnValue;
break;
}
@@ -376,7 +385,7 @@
case PutForExternalReadCommand.VERSIONED_METHOD_ID:
{
PutForExternalReadCommand returnValue = new PutForExternalReadCommand();
- returnValue.initialize(notifier, dataContainer);
+ returnValue.initialize(notifier, dataContainer, suppressRollbacks);
command = returnValue;
break;
}
@@ -384,7 +393,7 @@
case ClearDataCommand.VERSIONED_METHOD_ID:
{
ClearDataCommand returnValue = new ClearDataCommand();
- returnValue.initialize(notifier, dataContainer);
+ returnValue.initialize(notifier, dataContainer, suppressRollbacks);
command = returnValue;
break;
}
@@ -392,7 +401,7 @@
case RemoveKeyCommand.VERSIONED_METHOD_ID:
{
RemoveKeyCommand returnValue = new RemoveKeyCommand();
- returnValue.initialize(notifier, dataContainer);
+ returnValue.initialize(notifier, dataContainer, suppressRollbacks);
command = returnValue;
break;
}
@@ -401,13 +410,13 @@
case RemoveNodeCommand.VERSIONED_METHOD_ID:
{
RemoveNodeCommand returnValue = new RemoveNodeCommand();
- returnValue.initialize(notifier, dataContainer);
+ returnValue.initialize(notifier, dataContainer, suppressRollbacks);
command = returnValue;
break;
}
case CreateNodeCommand.METHOD_ID:
{
- CreateNodeCommand returnValue = new CreateNodeCommand();
+ CreateNodeCommand returnValue = new CreateNodeCommand(null,
suppressRollbacks);
returnValue.initialize(dataContainer);
command = returnValue;
break;
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,7 +1,6 @@
package org.jboss.cache.invocation;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.factories.context.ContextFactory;
/**
@@ -10,7 +9,6 @@
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
* @since 2.1.0
*/
-@NonVolatile
public class InvocationContextContainer extends ThreadLocal<InvocationContext>
{
ContextFactory contextFactory;
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2008-06-26
17:19:42 UTC (rev 6064)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -11,7 +11,6 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.RPCManager;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.factories.context.ContextFactory;
import org.jboss.cache.invocation.InvocationContext;
import org.jgroups.Address;
@@ -30,7 +29,6 @@
* @author <a href="mailto:bela@jboss.org">Bela Ban</a> Apr 14,
2003
* @version $Revision$
*/
-@NonVolatile
public class TransactionTable
{
private static final Log log = LogFactory.getLog(TransactionTable.class);
Added: core/trunk/src/test/java/org/jboss/cache/commands/TestContextBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/TestContextBase.java
(rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/commands/TestContextBase.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -0,0 +1,19 @@
+package org.jboss.cache.commands;
+
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.invocation.InvocationContext;
+import org.jboss.cache.invocation.LegacyInvocationContext;
+import org.jboss.cache.invocation.MVCCInvocationContext;
+
+public class TestContextBase
+{
+ protected InvocationContext createMVCCInvocationContext()
+ {
+ return new MVCCInvocationContext();
+ }
+
+ protected InvocationContext createLegacyInvocationContext(DataContainer dc)
+ {
+ return new LegacyInvocationContext(dc);
+ }
+}
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -3,8 +3,8 @@
import static org.easymock.EasyMock.createMock;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.TestContextBase;
import org.jboss.cache.invocation.InvocationContext;
-import org.jboss.cache.invocation.LegacyInvocationContext;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -15,7 +15,7 @@
* @since 2.2
*/
@Test(groups = "unit")
-public abstract class AbstractDataCommandTest
+public abstract class AbstractDataCommandTest extends TestContextBase
{
protected Fqn testFqn = Fqn.fromString("/testfqn");
protected DataContainer container;
@@ -25,7 +25,7 @@
final public void setUp()
{
container = createMock(DataContainer.class);
- ctx = new LegacyInvocationContext(container);
+ ctx = createLegacyInvocationContext(container);
moreSetup();
}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -5,10 +5,11 @@
/**
* Tester class for {@link org.jboss.cache.commands.read.ExistsCommand}
+ *
* @author Mircea.Markus(a)jboss.com
* @since 2.2
*/
-@Test(groups="unit")
+@Test(groups = "unit")
public class ExistsCommandTest extends AbstractDataCommandTest
{
private ExistsCommand command;
@@ -21,12 +22,12 @@
public void testPerform()
{
- expect(container.exists(testFqn)).andReturn(Boolean.FALSE);
+ expect(container.exists(testFqn)).andReturn(false);
replay(container);
- assert Boolean.FALSE == command.perform(null);
+ assert !((Boolean) command.perform(null));
reset(container);
-
- expect(container.exists(testFqn)).andReturn(Boolean.TRUE);
+
+ expect(container.exists(testFqn)).andReturn(true);
replay(container);
assert Boolean.TRUE == command.perform(null);
}
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,10 +1,10 @@
package org.jboss.cache.commands.read;
-import static org.easymock.EasyMock.*;
-
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import org.jboss.cache.mock.MockNodesFixture;
+import org.jboss.cache.mock.NodeSpiMock;
import org.testng.annotations.Test;
-import org.jboss.cache.mock.NodeSpiMock;
-import org.jboss.cache.mock.MockNodesFixture;
import java.util.Set;
@@ -14,7 +14,7 @@
* @author Mircea.Markus(a)jboss.com
* @since 2.2
*/
-@Test (groups="unit")
+@Test(groups = "unit")
public class GetChildrenNamesCommandTest extends AbstractDataCommandTest
{
private GetChildrenNamesCommand command;
@@ -32,15 +32,15 @@
NodeSpiMock node = new NodeSpiMock(testFqn);
expect(container.peek(testFqn)).andReturn(node);
replay(container);
- Set result = (Set) command.perform(null);
+ Set result = (Set) command.perform(ctx);
assert result.isEmpty() : "empty result expected";
}
-
+
public void testPerformInexistingNode()
{
expect(container.peek(testFqn)).andReturn(null);
replay(container);
- Set result = (Set) command.perform(null);
+ Set result = (Set) command.perform(ctx);
assert result == null : "empty result expected";
}
@@ -48,7 +48,7 @@
{
expect(container.peek(testFqn)).andReturn(nodes.adfNode);
replay(container);
- Set result = (Set) command.perform(null);
+ Set result = (Set) command.perform(ctx);
assert result.size() == 2;
assert result.contains("h");
assert result.contains("g");
@@ -59,7 +59,7 @@
nodes.adfgNode.markAsDeleted(true);
expect(container.peek(testFqn)).andReturn(nodes.adfNode);
replay(container);
- Set result = (Set) command.perform(null);
+ Set result = (Set) command.perform(ctx);
assert result.size() == 1;
assert result.contains("h");
}
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,8 +1,9 @@
package org.jboss.cache.commands.read;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import org.jboss.cache.mock.NodeSpiMock;
import org.testng.annotations.Test;
-import static org.easymock.EasyMock.*;
-import org.jboss.cache.mock.NodeSpiMock;
import java.util.Map;
@@ -27,17 +28,17 @@
{
expect(container.peek(testFqn)).andReturn(null);
replay(container);
- assert null == command.perform(null);
+ assert null == command.perform(ctx);
}
public void testForExistingNode()
{
NodeSpiMock node = new NodeSpiMock(testFqn);
- node.putDirect("k1","v1");
- node.putDirect("k2","v2");
+ node.putDirect("k1", "v1");
+ node.putDirect("k2", "v2");
expect(container.peek(testFqn)).andReturn(node);
replay(container);
- Map result = (Map) command.perform(null);
+ Map result = (Map) command.perform(ctx);
assert 2 == result.entrySet().size();
assert result.get("k1").equals("v1");
assert result.get("k2").equals("v2");
@@ -46,7 +47,8 @@
{
result.put("k3", "v3");
assert false : "map should be immutable";
- } catch (RuntimeException ex)
+ }
+ catch (RuntimeException ex)
{
//expected
}
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeyValueCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeyValueCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeyValueCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,13 +1,16 @@
package org.jboss.cache.commands.read;
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeMethod;
-import static org.easymock.EasyMock.*;
-import org.easymock.*;
-import org.jboss.cache.notifications.Notifier;
+import static org.easymock.EasyMock.createStrictControl;
+import static org.easymock.EasyMock.expect;
+import org.easymock.IMocksControl;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.TestContextBase;
+import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.mock.NodeSpiMock;
+import org.jboss.cache.notifications.Notifier;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
/**
* Tester class for {@link GetKeyValueCommand}.
@@ -16,7 +19,7 @@
* @since 2.2
*/
@Test(groups = "unit")
-public class GetKeyValueCommandTest
+public class GetKeyValueCommandTest extends TestContextBase
{
private IMocksControl control;
Notifier notifierMock;
@@ -24,6 +27,7 @@
GetKeyValueCommand command;
Fqn fqn = Fqn.fromString("/dummy");
String key = "key";
+ InvocationContext ctx;
@BeforeMethod
protected void setUup()
@@ -33,13 +37,14 @@
notifierMock = control.createMock(Notifier.class);
command = new GetKeyValueCommand(fqn, key, false);
command.initialize(containerMock, notifierMock);
+ ctx = createLegacyInvocationContext(containerMock);
}
public void testNonexistentNodeNoNotifications()
{
expect(containerMock.peek(fqn)).andReturn(null);
control.replay();
- assert null == command.perform(null);
+ assert null == command.perform(ctx);
}
public void testExistentNodeNoNotifications()
@@ -49,7 +54,7 @@
node.put(key, value);
expect(containerMock.peek(fqn)).andReturn(node);
control.replay();
- assert value.equals(command.perform(null));
+ assert value.equals(command.perform(ctx));
}
/**
@@ -60,7 +65,7 @@
command.sendNodeEvent = true;
expect(containerMock.peek(fqn)).andReturn(null);
control.replay();
- assert null == command.perform(null);
+ assert null == command.perform(ctx);
}
public void testExistentNodeWithNotifications()
@@ -72,11 +77,11 @@
//not ordred because the peek hapens before notification - that is to make sure
that no notification
// is sent for an nonexistent node.
control.checkOrder(false);
- notifierMock.notifyNodeVisited(fqn, true, null);
+ notifierMock.notifyNodeVisited(fqn, true, ctx);
expect(containerMock.peek(fqn)).andReturn(node);
- notifierMock.notifyNodeVisited(fqn, false, null);
+ notifierMock.notifyNodeVisited(fqn, false, ctx);
control.replay();
- assert value.equals(command.perform(null));
+ assert value.equals(command.perform(ctx));
control.verify();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,9 +1,9 @@
package org.jboss.cache.commands.read;
-import org.testng.annotations.Test;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import org.jboss.cache.mock.NodeSpiMock;
+import org.testng.annotations.Test;
import java.util.Set;
@@ -29,7 +29,7 @@
{
expect(container.peek(testFqn)).andReturn(null);
replay(container);
- assert null == command.perform(null);
+ assert null == command.perform(ctx);
}
public void testForExistingNode()
@@ -39,7 +39,7 @@
node.putDirect("k2", "v2");
expect(container.peek(testFqn)).andReturn(node);
replay(container);
- Set result = (Set) command.perform(null);
+ Set result = (Set) command.perform(ctx);
assert 2 == result.size();
assert result.contains("k1");
assert result.contains("k2");
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/write/AbstractVersionedDataCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/AbstractVersionedDataCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/AbstractVersionedDataCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -4,8 +4,8 @@
import org.easymock.IMocksControl;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.TestContextBase;
import org.jboss.cache.invocation.InvocationContext;
-import org.jboss.cache.invocation.LegacyInvocationContext;
import org.jboss.cache.mock.MockNodesFixture;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.optimistic.DataVersion;
@@ -21,7 +21,7 @@
* @since 2.2
*/
@Test(groups = "unit")
-public abstract class AbstractVersionedDataCommandTest
+public abstract class AbstractVersionedDataCommandTest extends TestContextBase
{
Notifier notifier;
DataContainer container;
@@ -43,10 +43,10 @@
nodes = new MockNodesFixture();
globalTransaction = new GlobalTransaction();
dataVersion = new DefaultDataVersion(10);
- ctx = new LegacyInvocationContext(container);
+ ctx = createLegacyInvocationContext(container);
AbstractVersionedDataCommand command = moreSetUp();
- command.initialize(notifier, container);
+ command.initialize(notifier, container, false);
}
public abstract AbstractVersionedDataCommand moreSetUp();
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,10 +1,9 @@
package org.jboss.cache.commands.write;
import static org.easymock.EasyMock.*;
-
-import org.testng.annotations.Test;
import org.jboss.cache.commands.read.AbstractDataCommandTest;
import org.jboss.cache.mock.MockNodesFixture;
+import org.testng.annotations.Test;
import java.util.ArrayList;
@@ -23,7 +22,7 @@
protected void moreSetup()
{
- command = new CreateNodeCommand(testFqn);
+ command = new CreateNodeCommand(testFqn, false);
command.initialize(container);
createdNodes = new ArrayList();
result = new Object[2];
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,14 +1,14 @@
package org.jboss.cache.commands.write;
-import static org.easymock.EasyMock.*;
-import org.jboss.cache.notifications.Notifier;
-import org.jboss.cache.mock.MockNodesFixture;
-import org.jboss.cache.commands.read.AbstractDataCommandTest;
+import static org.easymock.EasyMock.createStrictControl;
+import static org.easymock.EasyMock.expect;
+import org.easymock.IMocksControl;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeNotExistsException;
-import org.easymock.IMocksControl;
-import static org.easymock.EasyMock.createStrictControl;
+import org.jboss.cache.commands.read.AbstractDataCommandTest;
+import org.jboss.cache.mock.MockNodesFixture;
+import org.jboss.cache.notifications.Notifier;
import org.testng.annotations.Test;
/**
@@ -34,7 +34,7 @@
notifier = control.createMock(Notifier.class);
container = control.createMock(DataContainer.class);
command = new MoveCommand(source, destination);
- command.initialize(notifier, container);
+ command.initialize(notifier, container, false);
nodes = new MockNodesFixture();
}
@@ -48,7 +48,8 @@
{
command.perform(ctx);
assert false : "should have thrown an exception as the source is
null";
- } catch (NodeNotExistsException e)
+ }
+ catch (NodeNotExistsException e)
{
//expected
}
@@ -64,7 +65,8 @@
{
command.perform(ctx);
assert false : "should have thrown an exception as the source is
null";
- } catch (NodeNotExistsException e)
+ }
+ catch (NodeNotExistsException e)
{
//expected
}
Deleted:
core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,137 +0,0 @@
-package org.jboss.cache.commands.write;
-
-import static org.easymock.EasyMock.*;
-import org.easymock.IMocksControl;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.optimistic.DataVersion;
-import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.commands.read.AbstractDataCommandTest;
-import org.jboss.cache.mock.MockNodesFixture;
-import org.jboss.cache.notifications.Notifier;
-import org.testng.annotations.Test;
-
-import javax.transaction.TransactionManager;
-import javax.transaction.Transaction;
-import java.util.Collections;
-
-/**
- * tester class for {@link OptimisticInvalidateCommand}.
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-@Test(groups = "unit")
-public class OptimisticInvalidateCommandTest extends AbstractDataCommandTest
-{
- DataVersion dataVersion;
- OptimisticInvalidateCommand command;
- IMocksControl control;
-
- Notifier notifier;
- TransactionManager tmMock;
-
- MockNodesFixture nodes;
- CacheSPI spiMock;
-
- protected void moreSetup()
- {
- control = createStrictControl();
- notifier = control.createMock(Notifier.class);
- container = control.createMock(DataContainer.class);
- tmMock = control.createMock(TransactionManager.class);
- spiMock = control.createMock(CacheSPI.class);
- nodes = new MockNodesFixture();
-
- command = new OptimisticInvalidateCommand(testFqn);
- dataVersion = new DefaultDataVersion(10);
- command.setDataVersion(dataVersion);
- command.initialize(spiMock, container, notifier);
- command.initialize(tmMock);
- }
-
- public void testWithExistingNode()
- {
- nodes.adfNode.put("key", "value");
- nodes.adfNode.setDataLoaded(true);
- expect(spiMock.getNode(testFqn)).andReturn(nodes.adfNode);
- expect(container.peekVersioned(testFqn, dataVersion)).andReturn(nodes.adfNode);
- notifier.notifyNodeEvicted(testFqn, true, ctx);
- notifier.notifyNodeEvicted(testFqn, false, ctx);
- expect(container.peek(testFqn, false, true)).andReturn(nodes.adfNode);
-
- control.replay();
- assert null == command.perform(ctx);
- assert nodes.adfNode.getData().isEmpty();
- assert !nodes.adfNode.isDataLoaded();
- assert !nodes.adfNode.isValid();
- assert nodes.adfNode.getVersion().equals(dataVersion);
-
- control.verify();
- }
-
- public void testWithExistingNodeInvalidVersion()
- {
- nodes.adfNode.put("key", "value");
- nodes.adfNode.setDataLoaded(true);
- expect(spiMock.getNode(testFqn)).andReturn(nodes.adfNode);
- expect(container.peekVersioned(testFqn, dataVersion)).andThrow(new
RuntimeException());
- control.replay();
-
- try
- {
- command.perform(ctx);
- assert false : "exception expected";
- } catch (Exception e)
- {
- //expected as there is a version mismatch
- }
- assert !nodes.adfNode.getData().isEmpty();
- assert nodes.adfNode.isDataLoaded();
- assert nodes.adfNode.isValid();
- assert !dataVersion.equals(nodes.adfNode.getVersion());
-
- control.verify();
- }
-
- public void testExistingTumbstone()
- {
- nodes.adfNode.setValid(false, true);
- expect(spiMock.getNode(testFqn)).andReturn(null);
- expect(container.peek(testFqn, false, true)).andReturn(nodes.adfNode);
- expect(container.peekVersioned(testFqn, dataVersion)).andReturn(nodes.adfNode);
- notifier.notifyNodeEvicted(testFqn, true, ctx);
- notifier.notifyNodeEvicted(testFqn, false, ctx);
- expect(container.peek(testFqn, false, true)).andReturn(nodes.adfNode);
-
- control.replay();
- assert null == command.perform(ctx);
- assert nodes.adfNode.getData().isEmpty();
- assert !nodes.adfNode.isDataLoaded();
- assert !nodes.adfNode.isValid();
- assert nodes.adfNode.getVersion().equals(dataVersion);
- control.verify();
- }
-
- public void testCreateTumbstone() throws Exception
- {
- Transaction tx = control.createMock(Transaction.class);
- expect(tmMock.suspend()).andReturn(tx);
- spiMock.put(testFqn, Collections.emptyMap());
- tmMock.resume(tx);
-
- control.replay();
- command.createTombstone(ctx);
- control.verify();
- }
-
- public void testCreateTumbstoneNoTx() throws Exception
- {
- expect(tmMock.suspend()).andReturn(null);
- spiMock.put(testFqn, Collections.EMPTY_MAP);
-
- control.replay();
- command.createTombstone(ctx);
- control.verify();
- }
-}
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/write/PutDataMapCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/PutDataMapCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/PutDataMapCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,18 +1,21 @@
package org.jboss.cache.commands.write;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.createStrictControl;
+import static org.easymock.EasyMock.expect;
import org.easymock.IMocksControl;
-import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.TestContextBase;
+import org.jboss.cache.invocation.InvocationContext;
+import org.jboss.cache.mock.NodeSpiMock;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.mock.NodeSpiMock;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.testng.annotations.BeforeMethod;
+import java.util.HashMap;
import java.util.Map;
-import java.util.HashMap;
/**
* Tester class for {@link PutDataMapCommand}
@@ -21,17 +24,17 @@
* @since 2.2
*/
@Test(groups = "unit")
-public class PutDataMapCommandTest
+public class PutDataMapCommandTest extends TestContextBase
{
Fqn testFqn = Fqn.fromString("/testfqn");
PutDataMapCommand command;
-
GlobalTransaction gtx;
Notifier notifier;
DataContainer container;
Map dataMap;
IMocksControl control;
NodeSpiMock node;
+ InvocationContext ctx;
@BeforeMethod
@@ -43,30 +46,31 @@
control = createStrictControl();
notifier = control.createMock(Notifier.class);
container = control.createMock(DataContainer.class);
- command.initialize(notifier, container);
+ command.initialize(notifier, container, false);
node = new NodeSpiMock(testFqn);
- node.put("k","v");
+ node.put("k", "v");
+ ctx = createLegacyInvocationContext(container);
}
public void testAddDataNoErase()
{
- expect(container.peekStrict(gtx, testFqn, false)).andReturn(node);
+ expect(container.peek(testFqn)).andReturn(node);
dataMap.put("k2", "v2");
Map expected = new HashMap(dataMap);
expected.putAll(node.getDataDirect());
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
- notifier.notifyNodeModified(testFqn, true,
NodeModifiedEvent.ModificationType.PUT_MAP, node.getData(), null);
+ notifier.notifyNodeModified(testFqn, true,
NodeModifiedEvent.ModificationType.PUT_MAP, node.getData(), ctx);
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
- notifier.notifyNodeModified(testFqn, false,
NodeModifiedEvent.ModificationType.PUT_MAP, expected, null);
-
+ notifier.notifyNodeModified(testFqn, false,
NodeModifiedEvent.ModificationType.PUT_MAP, expected, ctx);
+
control.replay();
- assert null == command.perform(null) : "null result is always expected";
+ assert null == command.perform(ctx) : "null result is always expected";
assert command.getOldData().size() == 1;
assert command.getOldData().get("k").equals("v");
control.verify();
}
-
+
public void testRollbackNonexistentNode()
{
expect(container.peek(testFqn, false, true)).andReturn(null);
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/write/PutKeyValueCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/PutKeyValueCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/PutKeyValueCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,12 +1,12 @@
package org.jboss.cache.commands.write;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.expect;
+import org.jboss.cache.NodeNotExistsException;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
import org.testng.annotations.Test;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import java.util.HashMap;
import java.util.Map;
-import java.util.HashMap;
/**
* tester class for {@link PutKeyValueCommand}.
@@ -27,13 +27,14 @@
public void testInexistentNode()
{
- expect(container.peekStrict(globalTransaction, fqn, false)).andThrow(new
CacheException());
+ expect(container.peek(fqn)).andReturn(null); // simulate node not existing.
control.replay();
try
{
command.perform(ctx);
assert false : "exception should have been thrown as data does not
exists.";
- } catch (Exception e)
+ }
+ catch (NodeNotExistsException e)
{
//expected
}
@@ -43,7 +44,7 @@
public void testAddNewData()
{
nodes.adfNode.put("existingKey", "existingValue");
- expect(container.peekStrict(globalTransaction, fqn,
false)).andReturn(nodes.adfNode);
+ expect(container.peek(fqn)).andReturn(nodes.adfNode);
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA,
nodes.adfNode.getDataDirect(), ctx);
Map expected = new HashMap();
@@ -69,7 +70,7 @@
public void testOverWriteData()
{
nodes.adfNode.put("k", "oldValue");
- expect(container.peekStrict(globalTransaction, fqn,
false)).andReturn(nodes.adfNode);
+ expect(container.peek(fqn)).andReturn(nodes.adfNode);
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA,
nodes.adfNode.getDataDirect(), ctx);
Map expected = new HashMap();
@@ -88,6 +89,6 @@
command.rollback();
assert nodes.adfNode.getData().size() == 1;
assert "oldValue".equals(nodes.adfNode.getData().get("k"));
- control.verify();
+ control.verify();
}
}
Modified:
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java 2008-06-26
17:19:42 UTC (rev 6064)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java 2008-06-26
17:22:45 UTC (rev 6065)
@@ -1,12 +1,11 @@
package org.jboss.cache.commands.write;
-import static org.easymock.EasyMock.*;
-import org.testng.annotations.Test;
+import static org.easymock.EasyMock.expect;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.testng.annotations.Test;
-import java.util.Collections;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
/**
* tester class for {@link RemoveKeyCommand}.
@@ -14,7 +13,7 @@
* @author Mircea.Markus(a)jboss.com
* @since 2.2
*/
-@Test(groups="unit")
+@Test(groups = "unit")
public class RemoveKeyCommandTest extends AbstractVersionedDataCommandTest
{
RemoveKeyCommand command;
@@ -29,7 +28,7 @@
public void testNonexistentNode()
{
- expect(container.peek(fqn, false, false)).andReturn(null);
+ expect(container.peek(fqn)).andReturn(null);
control.replay();
assert null == command.perform(ctx);
control.verify();
@@ -38,13 +37,13 @@
public void testRemoveNonexistentPair()
{
Map expected = new HashMap();
- expected.put("newKey","newValue");
+ expected.put("newKey", "newValue");
nodes.adfgNode.putAll(expected);
- expect(container.peek(fqn, false, false)).andReturn(nodes.adfgNode);
+ expect(container.peek(fqn)).andReturn(nodes.adfgNode);
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
notifier.notifyNodeModified(fqn, true,
NodeModifiedEvent.ModificationType.REMOVE_DATA, expected, ctx);
expected = new HashMap();
- expected.put(key,null);
+ expected.put(key, null);
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
notifier.notifyNodeModified(fqn, false,
NodeModifiedEvent.ModificationType.REMOVE_DATA, expected, ctx);
control.replay();
@@ -65,9 +64,9 @@
public void testRemoveExistentPair()
{
Map expected = new HashMap();
- expected.put(key,"newValue");
+ expected.put(key, "newValue");
nodes.adfgNode.putAll(expected);
- expect(container.peek(fqn, false, false)).andReturn(nodes.adfgNode);
+ expect(container.peek(fqn)).andReturn(nodes.adfgNode);
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
notifier.notifyNodeModified(fqn, true,
NodeModifiedEvent.ModificationType.REMOVE_DATA, expected, ctx);
expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
@@ -94,12 +93,6 @@
{
expect(container.peek(fqn, false, true)).andReturn(null);
control.replay();
- try
- {
- command.rollback();
- } catch (Exception ex)
- {
- assert false : "No exception should be thrown here.";
- }
+ command.rollback();
}
}