Author: manik.surtani(a)jboss.com
Date: 2008-06-27 18:41:20 -0400 (Fri, 27 Jun 2008)
New Revision: 6112
Removed:
core/trunk/src/main/java/org/jboss/cache/commands/ReversibleCommand.java
core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/PutDataMapCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveNodeCommandTest.java
Log:
Refactored to move pess locking specific rollbacks into separate command subclasses
Deleted: core/trunk/src/main/java/org/jboss/cache/commands/ReversibleCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/ReversibleCommand.java 2008-06-27
22:36:56 UTC (rev 6111)
+++ core/trunk/src/main/java/org/jboss/cache/commands/ReversibleCommand.java 2008-06-27
22:41:20 UTC (rev 6112)
@@ -1,33 +0,0 @@
-package org.jboss.cache.commands;
-
-import org.jboss.cache.transaction.GlobalTransaction;
-
-/**
- * A reversible command is one that can be rolled back. Also typically has a reference
to a {@link org.jboss.cache.transaction.GlobalTransaction}.
- *
- * @author Mircea.Markus(a)jboss.com
- * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
- * @since 2.2.0
- */
-public interface ReversibleCommand extends DataCommand
-{
- /**
- * Reverses a command that has already been invoked.
- *
- * <b>Important</b>: this method will be invoked at the end of
interceptors chain. It should never be called directly from
- * a custom interceptor.
- */
- void rollback();
-
- /**
- * @return a GlobalTransaction associated with this command.
- */
- GlobalTransaction getGlobalTransaction();
-
- /**
- * Sets a GlobalTransaction on this command.
- *
- * @param gtx global transaction to set
- */
- void setGlobalTransaction(GlobalTransaction gtx);
-}
Deleted:
core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java 2008-06-27
22:36:56 UTC (rev 6111)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java 2008-06-27
22:41:20 UTC (rev 6112)
@@ -1,94 +0,0 @@
-package org.jboss.cache.commands.write;
-
-import static org.easymock.EasyMock.expect;
-import org.jboss.cache.notifications.event.NodeModifiedEvent;
-import org.testng.annotations.Test;
-
-import java.util.Collections;
-
-/**
- * tester class for {@link ClearDataCommand}.
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-@Test(groups = "unit")
-public class ClearDataCommandTest extends AbstractVersionedDataCommandTest
-{
-
- ClearDataCommand command;
-
- public AbstractVersionedDataCommand moreSetUp()
- {
- command = new ClearDataCommand(globalTransaction, fqn);
- command.setDataVersion(dataVersion);
- return command;
- }
-
- public void testNonexistentNode()
- {
- expect(container.peek(fqn)).andReturn(null);
- control.replay();
- assert null == command.perform(ctx);
- control.verify();
- }
-
- public void testExistentDataVersioned()
- {
- nodes.adfgNode.put("key", "value");
- nodes.adfgNode.setVersion(dataVersion);
- expect(container.peek(fqn)).andReturn(nodes.adfgNode);
- notifier.notifyNodeModified(fqn, true,
NodeModifiedEvent.ModificationType.REMOVE_DATA, nodes.adfgNode.getDataDirect(), ctx);
- notifier.notifyNodeModified(fqn, false,
NodeModifiedEvent.ModificationType.REMOVE_DATA, Collections.EMPTY_MAP, ctx);
- control.replay();
- assert null == command.perform(ctx);
- assert nodes.adfgNode.getData().isEmpty();
- control.verify();
-
- //now do a rollback
- control.reset();
- expect(container.peek(fqn, false, true)).andReturn(nodes.aNode);
- control.replay();
- command.rollback();
- assert nodes.aNode.dataSize() == 1;
- assert nodes.aNode.getData().get("key").equals("value");
- }
-
- public void testExistentDataUnversioned()
- {
- command.setDataVersion(null);
- nodes.adfgNode.put("key", "value");
- expect(container.peek(fqn)).andReturn(nodes.adfgNode);
- notifier.notifyNodeModified(fqn, true,
NodeModifiedEvent.ModificationType.REMOVE_DATA, nodes.adfgNode.getDataDirect(), ctx);
- notifier.notifyNodeModified(fqn, false,
NodeModifiedEvent.ModificationType.REMOVE_DATA, Collections.EMPTY_MAP, ctx);
- control.replay();
- assert null == command.perform(ctx);
- assert nodes.adfgNode.getData().isEmpty();
- control.verify();
-
- //now do a rollback
- control.reset();
- expect(container.peek(fqn, false, true)).andReturn(nodes.aNode);
- control.replay();
- command.rollback();
- assert nodes.aNode.dataSize() == 1;
- assert nodes.aNode.getData().get("key").equals("value");
- }
-
- /**
- * If clearing data on an inexistent node, the rollback should not fail
- */
- public void testNoOpRollback()
- {
- expect(container.peek(fqn, false, true)).andReturn(null);
- control.replay();
- try
- {
- command.rollback();
- }
- catch (Exception e)
- {
- assert false : "should not fail but expect this scenarion";
- }
- }
-}
Deleted:
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-27
22:36:56 UTC (rev 6111)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java 2008-06-27
22:41:20 UTC (rev 6112)
@@ -1,73 +0,0 @@
-package org.jboss.cache.commands.write;
-
-import static org.easymock.EasyMock.*;
-import org.jboss.cache.commands.read.AbstractDataCommandTest;
-import org.jboss.cache.mock.MockNodesFixture;
-import org.testng.annotations.Test;
-
-import java.util.ArrayList;
-
-/**
- * Tester class for {@link CreateNodeCommand}
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-@Test(groups = "unit")
-public class CreateNodeCommandTest extends AbstractDataCommandTest
-{
- CreateNodeCommand command;
- private Object[] result;
- private ArrayList createdNodes;
-
- protected void moreSetup()
- {
- command = new CreateNodeCommand(testFqn, false);
- command.initialize(container);
- createdNodes = new ArrayList();
- result = new Object[2];
- result[0] = this.createdNodes;
- }
-
- public void testPerformNoNodesCreated()
- {
- expect(container.createNodes(testFqn)).andReturn(result);
- replay(container);
- assert null == command.perform(ctx);
- assert command.getNewlyCreated().isEmpty();
- }
-
- public void testPerformWithCreatedNodes()
- {
- MockNodesFixture nodes = new MockNodesFixture();
- createdNodes.add(nodes.aNode);
- createdNodes.add(nodes.abNode);
- createdNodes.add(nodes.abcNode);
- result[1] = nodes.abcNode;
-
- expect(container.createNodes(testFqn)).andReturn(result);
- replay(container);
- assert nodes.abcNode == command.perform(ctx);
- assert command.getNewlyCreated().size() == 3;
- assert command.getNewlyCreated().contains(nodes.a);
- assert command.getNewlyCreated().contains(nodes.ab);
- assert command.getNewlyCreated().contains(nodes.abc);
- }
-
- public void testRollback()
- {
- MockNodesFixture nodes = new MockNodesFixture();
- createdNodes.add(nodes.aNode);
- createdNodes.add(nodes.abNode);
- createdNodes.add(nodes.abcNode);
- expect(container.createNodes(testFqn)).andReturn(result);
- expect(container.removeFromDataStructure(nodes.a, true)).andReturn(Boolean.TRUE);
- expect(container.removeFromDataStructure(nodes.ab, true)).andReturn(Boolean.TRUE);
- expect(container.removeFromDataStructure(nodes.abc,
true)).andReturn(Boolean.TRUE);
- replay(container);
- command.perform(ctx);
- command.rollback();
- verify(container);
- }
-
-}
Deleted:
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-27
22:36:56 UTC (rev 6111)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/PutDataMapCommandTest.java 2008-06-27
22:41:20 UTC (rev 6112)
@@ -1,81 +0,0 @@
-package org.jboss.cache.commands.write;
-
-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.jboss.cache.notifications.event.NodeModifiedEvent;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Tester class for {@link PutDataMapCommand}
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-@Test(groups = "unit")
-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
- protected void setUp()
- {
- gtx = new GlobalTransaction();
- dataMap = new HashMap();
- command = new PutDataMapCommand(gtx, testFqn, dataMap);
- control = createStrictControl();
- notifier = control.createMock(Notifier.class);
- container = control.createMock(DataContainer.class);
- command.initialize(notifier, container, false);
- node = new NodeSpiMock(testFqn);
- node.put("k", "v");
- ctx = createLegacyInvocationContext(container);
- }
-
- public void testAddDataNoErase()
- {
- 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(), ctx);
- expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
- notifier.notifyNodeModified(testFqn, false,
NodeModifiedEvent.ModificationType.PUT_MAP, expected, ctx);
-
- control.replay();
- 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);
- control.replay();
- command.rollback();
- control.verify();
- }
-}
Deleted:
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-27
22:36:56 UTC (rev 6111)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java 2008-06-27
22:41:20 UTC (rev 6112)
@@ -1,98 +0,0 @@
-package org.jboss.cache.commands.write;
-
-import static org.easymock.EasyMock.expect;
-import org.jboss.cache.notifications.event.NodeModifiedEvent;
-import org.testng.annotations.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * tester class for {@link RemoveKeyCommand}.
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-@Test(groups = "unit")
-public class RemoveKeyCommandTest extends AbstractVersionedDataCommandTest
-{
- RemoveKeyCommand command;
- private String key;
-
- public AbstractVersionedDataCommand moreSetUp()
- {
- key = "key";
- command = new RemoveKeyCommand(globalTransaction, fqn, key);
- return command;
- }
-
- public void testNonexistentNode()
- {
- expect(container.peek(fqn)).andReturn(null);
- control.replay();
- assert null == command.perform(ctx);
- control.verify();
- }
-
- public void testRemoveNonexistentPair()
- {
- Map expected = new HashMap();
- expected.put("newKey", "newValue");
- nodes.adfgNode.putAll(expected);
- 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);
- expect(notifier.shouldNotifyOnNodeModified()).andReturn(true);
- notifier.notifyNodeModified(fqn, false,
NodeModifiedEvent.ModificationType.REMOVE_DATA, expected, ctx);
- control.replay();
- assert null == command.perform(ctx);
- assert nodes.adfgNode.getData().size() == 1;
- assert
"newValue".equals(nodes.adfgNode.getData().get("newKey"));
- control.verify();
-
- control.reset();
- expect(container.peek(fqn, false, true)).andReturn(nodes.adfgNode);
- control.replay();
- command.rollback();
- assert nodes.adfgNode.getData().size() == 1;
- assert
"newValue".equals(nodes.adfgNode.getData().get("newKey"));
- control.verify();
- }
-
- public void testRemoveExistentPair()
- {
- Map expected = new HashMap();
- expected.put(key, "newValue");
- nodes.adfgNode.putAll(expected);
- 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);
- notifier.notifyNodeModified(fqn, false,
NodeModifiedEvent.ModificationType.REMOVE_DATA, expected, ctx);
- control.replay();
- assert "newValue" == command.perform(ctx);
- assert nodes.adfgNode.getData().get(key) == null;
- control.verify();
-
- control.reset();
- expect(container.peek(fqn, false, true)).andReturn(nodes.adfgNode);
- control.replay();
- command.rollback();
- assert nodes.adfgNode.getData().size() == 1;
- assert "newValue".equals(nodes.adfgNode.getData().get(key));
- control.verify();
- }
-
- /**
- * On an no-op scenario the user will try to remove a key on an unexisting node.
- * When rollback is being called, the node might not exist in the cache and we should
know how to handle that.
- */
- public void testRollbackOnNoOp()
- {
- expect(container.peek(fqn, false, true)).andReturn(null);
- control.replay();
- command.rollback();
- }
-}
Deleted:
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveNodeCommandTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveNodeCommandTest.java 2008-06-27
22:36:56 UTC (rev 6111)
+++
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveNodeCommandTest.java 2008-06-27
22:41:20 UTC (rev 6112)
@@ -1,86 +0,0 @@
-package org.jboss.cache.commands.write;
-
-import static org.easymock.EasyMock.expect;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.testng.annotations.Test;
-
-/**
- * tester for {@link RemoveNodeCommand}.
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-@Test(groups = "unit")
-public class RemoveNodeCommandTest extends AbstractVersionedDataCommandTest
-{
- RemoveNodeCommand command;
-
- public AbstractVersionedDataCommand moreSetUp()
- {
- command = new RemoveNodeCommand(globalTransaction, fqn);
- command.setDataVersion(dataVersion);
- return command;
- }
-
- public void testNonExistentNode()
- {
- expect(container.peek(fqn)).andReturn(null);
- control.replay();
- assert Boolean.FALSE == command.perform(ctx) : "nonexistent node was not
remove; false expected";
- }
-
- public void testRemovalNoNotificationsValidNode()
- {
- //aditional setup
- command.setSkipSendingNodeEvents(true); //no notification
- nodes.adfNode.put("akey", "avalue");
- nodes.adfNode.setVersion(dataVersion);
- ctx.setGlobalTransaction(new GlobalTransaction());
-
- //check perform
- expect(container.peek(fqn)).andReturn(nodes.adfNode);
- control.replay();
- assert Boolean.TRUE == command.perform(ctx);
- assert nodes.adfgNode.isDeleted();
- assert nodes.adfhNode.isDeleted();
- assert command.originalData != null;
- control.verify();
-
- //check rollback
- control.reset();
- nodes.adNode.removeChild("f");
- expect(container.peek(nodes.ad)).andReturn(nodes.adNode);
- control.replay();
- command.rollback();
- assert nodes.adNode.hasChild("f");
- }
-
- public void testRemovalNoNotificationsInvalidNode()
- {
- command.setSkipSendingNodeEvents(true); //no notification
- nodes.adfNode.setValid(false, false); //invalid node
- nodes.adfNode.setVersion(dataVersion);
-
- expect(container.peek(fqn)).andReturn(nodes.adfNode);
- control.replay();
- assert Boolean.FALSE == command.perform(ctx);
- assert nodes.adfgNode.isDeleted();
- assert nodes.adfhNode.isDeleted();
- control.verify();
- }
-
- public void testRemovalWithNotificationsInvalidNode()
- {
- nodes.adfNode.setValid(false, false); //invalid node
- nodes.adfNode.setVersion(dataVersion);
-
- expect(container.peek(fqn)).andReturn(nodes.adfNode);
- notifier.notifyNodeRemoved(fqn, true, nodes.adfNode.getDataDirect(), ctx);
- notifier.notifyNodeRemoved(fqn, false, null, ctx);
- control.replay();
- assert Boolean.FALSE == command.perform(ctx);
- assert nodes.adfgNode.isDeleted();
- assert nodes.adfhNode.isDeleted();
- control.verify();
- }
-}