[jbosscache-commits] JBoss Cache SVN: r6081 - in core/trunk/src: main/java/org/jboss/cache/commands/remote and 4 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Jun 26 20:26:04 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-06-26 20:26:03 -0400 (Thu, 26 Jun 2008)
New Revision: 6081

Modified:
   core/trunk/src/main/java/org/jboss/cache/DataContainer.java
   core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
   core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.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/EvictCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/VersionedInvalidateCommand.java
   core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java
   core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java
   core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java
   core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java
   core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java
   core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveNodeCommandTest.java
   core/trunk/src/test/java/org/jboss/cache/commands/write/VersionedInvalidateCommandTest.java
Log:
Removed reliance on certain peek methods on DataContainer, preferring to use invocationContext.lookup() instead as it allows us to cache nodes in the context.

Modified: core/trunk/src/main/java/org/jboss/cache/DataContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -2,8 +2,6 @@
 
 import org.jboss.cache.marshall.NodeData;
 import org.jboss.cache.mvcc.InternalNode;
-import org.jboss.cache.optimistic.DataVersion;
-import org.jboss.cache.transaction.GlobalTransaction;
 
 import java.util.List;
 import java.util.Set;
@@ -41,40 +39,6 @@
    NodeSPI peek(Fqn fqn);
 
    /**
-    * Finds a node given a fully qualified name and DataVersion.  Does not include invalid or deleted nodes.  If the data
-    * version passed in is null, then data version checking is skipped.  Data version checking is also skipped if optimistic
-    * locking is not used.
-    *
-    * @param fqn     fqn to find
-    * @param version version of the node to find
-    * @return a node, if found, or null if not.
-    */
-   NodeSPI peekVersioned(Fqn fqn, DataVersion version);
-
-   /**
-    * Similar to {@link #peekVersioned(Fqn, org.jboss.cache.optimistic.DataVersion)} except that it throws a {@link org.jboss.cache.NodeNotExistsException}
-    * if the node cannot be found.
-    *
-    * @param gtx            global transaction
-    * @param fqn            fqn to find
-    * @param includeInvalid if true, invalid nodes are considered as well.
-    * @return the node
-    */
-   NodeSPI peekStrict(GlobalTransaction gtx, Fqn fqn, boolean includeInvalid);
-
-   /**
-    * Searches for a specific node, with a specific data version and, optionally, invalid nodes as well, but not
-    * deleted nodes.  If the data version passed in is null, then data version checking is skipped.  Data version
-    * checking is also skipped if optimistic locking is not used.
-    *
-    * @param fqn                 Fqn to find
-    * @param version             version of the node to find
-    * @param includeInvalidNodes if true, invalid nodes are considered
-    * @return the node, if found, or null otherwise.
-    */
-   NodeSPI peekVersioned(Fqn fqn, DataVersion version, boolean includeInvalidNodes);
-
-   /**
     * Same as calling <tt>peek(fqn, includeDeletedNodes, false)</tt>.
     *
     * @param fqn                 Fqn to find

Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -3,7 +3,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.factories.annotations.NonVolatile;
 import org.jboss.cache.factories.annotations.Start;
@@ -12,8 +11,6 @@
 import org.jboss.cache.lock.LockManager;
 import org.jboss.cache.marshall.NodeData;
 import org.jboss.cache.mvcc.InternalNode;
-import org.jboss.cache.optimistic.DataVersion;
-import org.jboss.cache.transaction.GlobalTransaction;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -34,8 +31,6 @@
    private static final Log log = LogFactory.getLog(DataContainerImpl.class);
    private static boolean trace = log.isTraceEnabled();
 
-   private Configuration configuration;
-
    /**
     * Root node.
     */
@@ -51,9 +46,9 @@
    private BuddyFqnTransformer buddyFqnTransformer;
 
    @Inject
-   public void injectDependencies(Configuration configuration, NodeFactory nodeFactory, LockManager lockManager, BuddyFqnTransformer transformer)
+   public void injectDependencies(NodeFactory nodeFactory, LockManager lockManager, BuddyFqnTransformer transformer)
    {
-      setDependencies(configuration, nodeFactory, lockManager);
+      setDependencies(nodeFactory, lockManager);
 
       // We need to create a root node even at this stage since certain components rely on this being available before
       // start() is called.
@@ -63,9 +58,8 @@
       this.buddyFqnTransformer = transformer;
    }
 
-   public void setDependencies(Configuration configuration, NodeFactory nodeFactory, LockManager lockManager)
+   public void setDependencies(NodeFactory nodeFactory, LockManager lockManager)
    {
-      this.configuration = configuration;
       this.nodeFactory = nodeFactory;
       this.lockManager = lockManager;
    }
@@ -120,68 +114,11 @@
       internalFqns.add(fqn);
    }
 
-   /**
-    * Finds a node given a fully qualified name, directly off the interceptor chain.  In the event of an exception,
-    * returns null.  Does not include invalid or deleted nodes.
-    *
-    * @param fqn Fully qualified name for the corresponding node.
-    * @return Node referenced by the given Fqn, or null if the node cannot be found or if there is an exception.
-    */
    public NodeSPI peek(Fqn fqn)
    {
-      try
-      {
-         return peekVersioned(fqn, null);
-      }
-      catch (CacheException e)
-      {
-         log.warn("Unexpected error", e);
-         return null;
-      }
+      return peek(fqn, false, false);
    }
 
-   public NodeSPI peekStrict(GlobalTransaction gtx, Fqn fqn, boolean includeInvalid)
-   {
-      NodeSPI n = peekVersioned(fqn, null, includeInvalid);
-      if (n == null)
-      {
-         StringBuilder builder = new StringBuilder();
-         builder.append("Node ").append(fqn).append(" not found");
-         String errStr = builder.toString();
-         if (trace) log.trace(errStr);
-         throw new NodeNotExistsException(errStr);
-      }
-      return n;
-   }
-
-   public NodeSPI peekVersioned(Fqn fqn, DataVersion version)
-   {
-      return peekVersioned(fqn, version, false);
-   }
-
-   public NodeSPI peekVersioned(Fqn fqn, DataVersion version, boolean includeInvalidNodes)
-   {
-      if (fqn == null) return null;
-
-      NodeSPI toReturn = peek(fqn, false, includeInvalidNodes);
-
-      if (toReturn != null && version != null && configuration.getNodeLockingScheme().isVersionedScheme())
-      {
-         // we need to check the version of the data node...
-         DataVersion nodeVersion = toReturn.getVersion();
-         if (trace)
-         {
-            log.trace("looking for optimistic node [" + fqn + "] with version [" + version + "].  My version is [" + nodeVersion + "]");
-         }
-         if (nodeVersion.newerThan(version))
-         {
-            // we have a versioning problem; throw an exception!
-            throw new CacheException("Unable to validate versions.");
-         }
-      }
-      return toReturn;
-   }
-
    public NodeSPI peek(Fqn<?> fqn, boolean includeDeletedNodes)
    {
       return peek(fqn, includeDeletedNodes, false);
@@ -476,7 +413,7 @@
 
    private void removeNode(Fqn fqn)
    {
-      NodeSPI targetNode = peekVersioned(fqn, null, true);
+      NodeSPI targetNode = peek(fqn, false, true);
       if (targetNode == null) return;
       NodeSPI parentNode = targetNode.getParent();
       targetNode.setValid(false, false);
@@ -489,7 +426,7 @@
 
    protected void removeData(Fqn fqn)
    {
-      NodeSPI n = peekVersioned(fqn, null);
+      NodeSPI n = peek(fqn);
       if (n == null)
       {
          log.warn("node " + fqn + " not found");

Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -88,14 +88,14 @@
                // if this is a DIRECT child of a DEAD buddy backup region, then remove the empty dead region structural node.
                if (buddyFqnTransformer.isDeadBackupFqn(backup) && buddyFqnTransformer.isDeadBackupRoot(backup.getParent().getParent()))
                {
-                  NodeSPI deadBackupRoot = dataContainer.peek(backup.getParent(), false);
+                  NodeSPI deadBackupRoot = ctx.lookUpNode(backup.getParent());
                   if (deadBackupRoot.getChildrenMapDirect().isEmpty())
                   {
                      if (trace) log.trace("Removing dead backup region " + deadBackupRoot.getFqn());
                      executeRemove(gtx, deadBackupRoot.getFqn());
 
                      // now check the grand parent and see if we are free of versions
-                     deadBackupRoot = dataContainer.peek(deadBackupRoot.getFqn().getParent(), false);
+                     deadBackupRoot = ctx.lookUpNode(deadBackupRoot.getFqn().getParent());
                      if (deadBackupRoot.getChildrenMapDirect().isEmpty())
                      {
                         if (trace) log.trace("Removing dead backup region " + deadBackupRoot.getFqn());

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-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/AbstractVersionedDataCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -3,10 +3,13 @@
 import org.jboss.cache.CacheException;
 import org.jboss.cache.DataContainer;
 import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
 import org.jboss.cache.commands.VersionedDataCommand;
 import org.jboss.cache.commands.read.AbstractDataCommand;
+import org.jboss.cache.invocation.InvocationContext;
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.optimistic.DataVersioningException;
 import org.jboss.cache.transaction.GlobalTransaction;
 
 /**
@@ -97,4 +100,23 @@
    {
       return 31 * super.hashCode() + (dataVersion != null ? dataVersion.hashCode() : 0);
    }
+
+   /**
+    * Utility method to peek a node and throw an exception if the version isn't what is expected.
+    *
+    * @param ctx context to use
+    * @return node peeked, null if nonexistent
+    * @throws org.jboss.cache.optimistic.DataVersioningException
+    *          if there is a version mismatch
+    */
+   protected NodeSPI peekVersioned(InvocationContext ctx)
+   {
+      NodeSPI n = ctx.lookUpNode(fqn);
+      if (n != null && isVersioned() && n.getVersion().newerThan(dataVersion))
+      {
+         String errMsg = new StringBuilder("Node found, but version is not equal to or less than the expected [").append(dataVersion).append("].  Is [").append(n.getVersion()).append("] instead!").toString();
+         throw new DataVersioningException(errMsg);
+      }
+      return n;
+   }
 }
\ No newline at end of file

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-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -50,8 +50,7 @@
    {
       if (trace) log.trace("perform(" + globalTransaction + ", \"" + fqn + "\")");
 
-      NodeSPI targetNode = dataContainer.peekVersioned(fqn, dataVersion);
-//      NodeSPI targetNode = ctx.lookUpNode(fqn);
+      NodeSPI targetNode = peekVersioned(ctx);
       if (targetNode == null)
       {
          log.warn("node " + fqn + " not found");

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -50,12 +50,16 @@
     */
    public Object perform(InvocationContext ctx)
    {
-      NodeSPI node = dataContainer.peek(fqn, false, false);
-      if (node != null && node.isResident())
+      NodeSPI node = ctx.lookUpNode(fqn);
+      if (node == null)
       {
+         return false;
+      }
+      else if (node.isResident())
+      {
          return true;
       }
-      if (recursive)
+      else if (recursive)
       {
          List<Fqn> nodesToEvict = dataContainer.getNodesForEviction(fqn, true);
          for (Fqn aFqn : nodesToEvict)

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-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -104,13 +104,13 @@
    private void move(Fqn toMoveFqn, Fqn newParentFqn, boolean skipNotifications, InvocationContext ctx)
    {
       // the actual move algorithm.
-      NodeSPI newParent = dataContainer.peek(newParentFqn, false, false);
+      NodeSPI newParent = ctx.lookUpNode(newParentFqn);
       if (newParent == null)
       {
          throw new NodeNotExistsException("New parent node " + newParentFqn + " does not exist when attempting to move node!!");
       }
 
-      NodeSPI node = dataContainer.peek(toMoveFqn, false, false);
+      NodeSPI node = ctx.lookUpNode(toMoveFqn);
 
       if (node == 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-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -54,12 +54,8 @@
     */
    public Object perform(InvocationContext ctx)
    {
-      if (trace)
-      {
-         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);
+      if (trace) log.trace("Perform('" + globalTransaction + "', '" + fqn + "', k='" + key + "', v='" + value + "')");
+
       NodeSPI n = ctx.lookUpNode(fqn);
       if (n == null) throw new NodeNotExistsException("Node " + fqn + " does not exist!");
 

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-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -47,8 +47,9 @@
    public Object perform(InvocationContext ctx)
    {
       if (trace) log.trace("perform(" + globalTransaction + ", \"" + fqn + ")");
+
       // Find the node
-      targetNode = dataContainer.peekVersioned(fqn, dataVersion, true);
+      targetNode = peekVersioned(ctx);
       if (targetNode == null)
       {
          if (trace) log.trace("node " + fqn + " not found");

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/VersionedInvalidateCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/VersionedInvalidateCommand.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/VersionedInvalidateCommand.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -9,6 +9,7 @@
 import org.jboss.cache.config.Option;
 import org.jboss.cache.invocation.InvocationContext;
 import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.optimistic.DataVersioningException;
 import org.jboss.cache.transaction.GlobalTransaction;
 
 import javax.transaction.Transaction;
@@ -64,7 +65,7 @@
       if (node == null)
       {
          // check if a tombstone already exists
-         NodeSPI nodeSPI = dataContainer.peek(fqn, false, true);
+         NodeSPI nodeSPI = dataContainer.peek(fqn, true, true);
          if (nodeSPI == null)
          {
             if (dataVersion == null)
@@ -78,9 +79,20 @@
          }
          node = nodeSPI;
       }
-      removeData(ctx);
+      else if (node.getVersion() == null)
+      {
+         throw new NullPointerException("Node " + node.getFqn() + " has a null data version, and is of type " + node.getClass().getSimpleName() + ".  This command expects versioned nodes.");
+      }
+      else if (node.getVersion().newerThan(dataVersion))
+      {
+         String errMsg = new StringBuilder("Node found, but version is not equal to or less than the expected [").append(dataVersion).append("].  Is [").append(node.getVersion()).append("] instead!").toString();
+         log.warn(errMsg);
+         throw new DataVersioningException(errMsg);
+      }
+
+      removeData(node, ctx);
       invalidateNode(node);
-      updateDataVersion();
+      node.setVersion(dataVersion);
       return null;
    }
 
@@ -111,23 +123,8 @@
       }
    }
 
-   private void updateDataVersion()
+   protected void removeData(NodeSPI n, InvocationContext ctx) throws CacheException
    {
-      if (dataVersion != null)
-      {
-         NodeSPI n = dataContainer.peek(fqn, false, true);
-         n.setVersion(dataVersion);
-      }
-   }
-
-   protected void removeData(InvocationContext ctx) throws CacheException
-   {
-      NodeSPI n = dataContainer.peekVersioned(fqn, dataVersion);
-      if (n == null)
-      {
-         log.warn("node " + fqn + " not found");
-         return;
-      }
       notifier.notifyNodeEvicted(fqn, true, ctx);
       n.clearDataDirect();
       n.setDataLoaded(false);

Modified: core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -1,11 +1,8 @@
 package org.jboss.cache;
 
-import org.jboss.cache.config.Configuration;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.jboss.cache.marshall.NodeData;
 import org.jboss.cache.mock.MockNodesFixture;
-import org.jboss.cache.optimistic.DataVersion;
-import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -67,56 +64,6 @@
    }
 
    /**
-    * tests {@link DataContainerImpl#peekVersioned(Fqn, org.jboss.cache.optimistic.DataVersion, boolean)} method.
-    */
-   public void testPeekVersioned()
-   {
-      assert nodes.adfgNode == container.peekVersioned(nodes.adfg, null, true) : "if data version is null this returns same value as peek(boolean, boolean)";
-
-      //test pessimistic loking
-      Configuration config = new Configuration();
-      config.setNodeLockingScheme(Configuration.NodeLockingScheme.PESSIMISTIC);
-      DataVersion dataVersion = new DefaultDataVersion(2);
-      container.setDependencies(config, null, null);
-      assert nodes.adfgNode == container.peekVersioned(nodes.adfg, dataVersion, true) : "if NOT opt locking same value as peek(boolean, boolean) expected";
-
-      //test optimistic locking with same version
-      config.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
-      DataVersion adfgDataVersion = new DefaultDataVersion(2);
-      nodes.adfgNode.setVersion(adfgDataVersion);
-      assert nodes.adfgNode == container.peekVersioned(nodes.adfg, adfgDataVersion, true) : "same version, expcting node to be returned";
-
-      //test optimistic locking with a an older
-      try
-      {
-         container.peekVersioned(nodes.adfg, new DefaultDataVersion(1), true);
-         assert false : "exception expected as version changed.";
-      }
-      catch (CacheException e)
-      {
-         //expected
-      }
-   }
-
-   /**
-    * tests {@link DataContainerImpl#peekStrict(org.jboss.cache.transaction.GlobalTransaction, Fqn, boolean)}.
-    */
-   public void testPeekStrict()
-   {
-      assert nodes.adfgNode == container.peekStrict(null, nodes.adfg, true) : "if data version is null this returns same value as peek(boolean, boolean)";
-
-      try
-      {
-         container.peekStrict(null, nodes.notExistent, true);
-         assert false : "excpetion expected as node does not exist";
-      }
-      catch (Exception e)
-      {
-         //expected
-      }
-   }
-
-   /**
     * tests {@link DataContainerImpl#exists(Fqn)}
     */
    public void testsExists()

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-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -25,8 +25,8 @@
    final public void setUp()
    {
       container = createMock(DataContainer.class);
+      moreSetup();
       ctx = createLegacyInvocationContext(container);
-      moreSetup();
    }
 
    /**

Modified: 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 00:17:00 UTC (rev 6080)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -1,8 +1,8 @@
 package org.jboss.cache.commands.write;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.expect;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
 import org.testng.annotations.Test;
-import org.jboss.cache.notifications.event.NodeModifiedEvent;
 
 import java.util.Collections;
 
@@ -12,7 +12,7 @@
  * @author Mircea.Markus at jboss.com
  * @since 2.2
  */
- at Test (groups = "unit")
+ at Test(groups = "unit")
 public class ClearDataCommandTest extends AbstractVersionedDataCommandTest
 {
 
@@ -27,16 +27,17 @@
 
    public void testNonexistentNode()
    {
-      expect(container.peekVersioned(fqn, dataVersion)).andReturn(null);
+      expect(container.peek(fqn)).andReturn(null);
       control.replay();
       assert null == command.perform(ctx);
       control.verify();
    }
 
-   public void testExistentData()
+   public void testExistentDataVersioned()
    {
       nodes.adfgNode.put("key", "value");
-      expect(container.peekVersioned(fqn, dataVersion)).andReturn(nodes.adfgNode);
+      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();
@@ -53,6 +54,27 @@
       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
     */
@@ -63,9 +85,10 @@
       try
       {
          command.rollback();
-      } catch (Exception e)
+      }
+      catch (Exception e)
       {
-         assert false : "should not fail but expect this scenarion"; 
+         assert false : "should not fail but expect this scenarion";
       }
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -1,16 +1,17 @@
 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.testng.annotations.Test;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
 import org.jboss.cache.commands.read.AbstractDataCommandTest;
+import org.jboss.cache.mock.MockNodesFixture;
 import org.jboss.cache.notifications.Notifier;
-import org.jboss.cache.mock.MockNodesFixture;
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.Fqn;
+import org.testng.annotations.Test;
 
+import java.util.ArrayList;
 import java.util.List;
-import java.util.ArrayList;
 
 /**
  * tester class for {@link EvictCommand}
@@ -39,7 +40,7 @@
    public void testResidentNodesEviction()
    {
       nodes.abNode.setResident(true);
-      expect(container.peek(testFqn, false,false)).andReturn(nodes.abNode);
+      expect(container.peek(testFqn)).andReturn(nodes.abNode);
       control.replay();
       assert Boolean.TRUE == command.perform(ctx);
       control.verify();
@@ -47,7 +48,7 @@
 
    public void testSimpleEviction()
    {
-      expect(container.peek(testFqn, false,false)).andReturn(nodes.abNode);
+      expect(container.peek(testFqn)).andReturn(nodes.abNode);
       notifier.notifyNodeEvicted(testFqn, true, ctx);
       expect(container.evict(testFqn)).andReturn(true);
       notifier.notifyNodeEvicted(testFqn, false, ctx);
@@ -62,7 +63,7 @@
       nodesToEvict.add(nodes.a);
       nodesToEvict.add(nodes.ab);
       command.setRecursive(true);
-      expect(container.peek(testFqn, false,false)).andReturn(nodes.aNode);
+      expect(container.peek(testFqn)).andReturn(nodes.aNode);
 
       expect(container.getNodesForEviction(testFqn, true)).andReturn(nodesToEvict);
       control.checkOrder(false);

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-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -41,8 +41,8 @@
    public void testFailsOnMissingSource()
    {
       control.checkOrder(false);
-      expect(container.peek(source, false, false)).andReturn(null);
-      expect(container.peek(destination, false, false)).andReturn(nodes.adfgNode);
+      expect(container.peek(source)).andReturn(null);
+      expect(container.peek(destination)).andReturn(nodes.adfgNode);
       control.replay();
       try
       {
@@ -58,8 +58,8 @@
    public void testFailsOnMissingDestination()
    {
       control.checkOrder(false);
-      expect(container.peek(source, false, false)).andReturn(nodes.adfgNode);
-      expect(container.peek(destination, false, false)).andReturn(null);
+      expect(container.peek(source)).andReturn(nodes.adfgNode);
+      expect(container.peek(destination)).andReturn(null);
       control.replay();
       try
       {

Modified: 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 00:17:00 UTC (rev 6080)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveNodeCommandTest.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -1,8 +1,8 @@
 package org.jboss.cache.commands.write;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.expect;
+import org.jboss.cache.transaction.GlobalTransaction;
 import org.testng.annotations.Test;
-import org.jboss.cache.transaction.GlobalTransaction;
 
 /**
  * tester for  {@link RemoveNodeCommand}.
@@ -24,7 +24,7 @@
 
    public void testNonExistentNode()
    {
-      expect(container.peekVersioned(fqn, dataVersion, true)).andReturn(null);
+      expect(container.peek(fqn)).andReturn(null);
       control.replay();
       assert Boolean.FALSE == command.perform(ctx) : "nonexistent node was not remove; false expected";
    }
@@ -33,11 +33,12 @@
    {
       //aditional setup
       command.setSkipSendingNodeEvents(true); //no notification
-      nodes.adfNode.put("akey","avalue");
+      nodes.adfNode.put("akey", "avalue");
+      nodes.adfNode.setVersion(dataVersion);
       ctx.setGlobalTransaction(new GlobalTransaction());
 
       //check perform
-      expect(container.peekVersioned(fqn, dataVersion, true)).andReturn(nodes.adfNode);
+      expect(container.peek(fqn)).andReturn(nodes.adfNode);
       control.replay();
       assert Boolean.TRUE == command.perform(ctx);
       assert nodes.adfgNode.isDeleted();
@@ -53,24 +54,27 @@
       command.rollback();
       assert nodes.adNode.hasChild("f");
    }
+
    public void testRemovalNoNotificationsInvalidNode()
    {
       command.setSkipSendingNodeEvents(true); //no notification
       nodes.adfNode.setValid(false, false);   //invalid node
-      
-      expect(container.peekVersioned(fqn, dataVersion, true)).andReturn(nodes.adfNode);
+      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.peekVersioned(fqn, dataVersion, true)).andReturn(nodes.adfNode);
+      expect(container.peek(fqn)).andReturn(nodes.adfNode);
       notifier.notifyNodeRemoved(fqn, true, nodes.adfNode.getDataDirect(), ctx);
       notifier.notifyNodeRemoved(fqn, false, null, ctx);
       control.replay();

Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/VersionedInvalidateCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/VersionedInvalidateCommandTest.java	2008-06-27 00:17:00 UTC (rev 6080)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/VersionedInvalidateCommandTest.java	2008-06-27 00:26:03 UTC (rev 6081)
@@ -9,6 +9,7 @@
 import org.jboss.cache.mock.MockNodesFixture;
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.optimistic.DataVersioningException;
 import org.jboss.cache.optimistic.DefaultDataVersion;
 import org.testng.annotations.Test;
 
@@ -54,12 +55,11 @@
    public void testWithExistingNode()
    {
       nodes.adfNode.put("key", "value");
+      nodes.adfNode.setVersion(dataVersion);
       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);
@@ -75,8 +75,8 @@
    {
       nodes.adfNode.put("key", "value");
       nodes.adfNode.setDataLoaded(true);
+      nodes.adfNode.setVersion(new DefaultDataVersion(100));
       expect(spiMock.getNode(testFqn)).andReturn(nodes.adfNode);
-      expect(container.peekVersioned(testFqn, dataVersion)).andThrow(new RuntimeException());
       control.replay();
 
       try
@@ -84,7 +84,7 @@
          command.perform(ctx);
          assert false : "exception expected";
       }
-      catch (Exception e)
+      catch (DataVersioningException e)
       {
          //expected as there is a version mismatch
       }
@@ -96,15 +96,14 @@
       control.verify();
    }
 
-   public void testExistingTumbstone()
+   public void testExistingTombstone()
    {
       nodes.adfNode.setValid(false, true);
+      nodes.adfNode.setVersion(dataVersion);
       expect(spiMock.getNode(testFqn)).andReturn(null);
-      expect(container.peek(testFqn, false, true)).andReturn(nodes.adfNode);
-      expect(container.peekVersioned(testFqn, dataVersion)).andReturn(nodes.adfNode);
+      expect(container.peek(testFqn, true, true)).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);




More information about the jbosscache-commits mailing list