jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1390369 - in /jackrabbit/oak/trunk: oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/ oak-mongomk-test/ oak-mongomk/ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/ oak-mongomk/src/main/java/org/apache/jackrabbit/mong...
Date Wed, 26 Sep 2012 10:12:22 GMT
Author: jukka
Date: Wed Sep 26 10:12:22 2012
New Revision: 1390369

URL: http://svn.apache.org/viewvc?rev=1390369&view=rev
Log:
OAK-339: [MongoMK] Fix GetCommandsMongoTest

Patch by Mete Atamel

Added:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java
Modified:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
    jackrabbit/oak/trunk/oak-mongomk-test/pom.xml
    jackrabbit/oak/trunk/oak-mongomk/pom.xml
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongo.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitCommandInstructionVisitor.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQuery.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
Wed Sep 26 10:12:22 2012
@@ -297,7 +297,7 @@ public class MicroKernelIT extends Abstr
 
     @Test
     public void snapshotIsolation() {
-        final int NUM_COMMITS = 1000;
+        final int NUM_COMMITS = 100;
 
         String[] revs = new String[NUM_COMMITS];
 
@@ -1025,16 +1025,21 @@ public class MicroKernelIT extends Abstr
     }
 
     @Test
-    public void testBlobs() {
-        // test with small blobs
-        testBlobs(1234);
-        // test with medium sized blobs
-        testBlobs(1234567);
-        // test with large blobs
-        testBlobs(32 * 1024 * 1024);
+    public void testSmallBlob() {
+        testBlobs(1234, 8 * 1024);
     }
 
-    private void testBlobs(int size) {
+    @Test
+    public void testMediumBlob() {
+        testBlobs(1234567, 8 * 1024);
+    }
+
+    @Test
+    public void testLargeBlob() {
+        testBlobs(32 * 1024 * 1024, 1024 * 1024);
+    }
+
+    private void testBlobs(int size, int bufferSize) {
         // write data
         TestInputStream in = new TestInputStream(size);
         String id = mk.write(in);
@@ -1054,7 +1059,8 @@ public class MicroKernelIT extends Abstr
 
         // verify data
         InputStream in1 = new TestInputStream(size);
-        InputStream in2 = new BufferedInputStream(new MicroKernelInputStream(mk, id));
+        InputStream in2 = new BufferedInputStream(
+                new MicroKernelInputStream(mk, id), bufferSize);
         try {
             while (true) {
                 int x = in1.read();

Modified: jackrabbit/oak/trunk/oak-mongomk-test/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/pom.xml?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-mongomk-test/pom.xml Wed Sep 26 10:12:22 2012
@@ -26,44 +26,31 @@
   <parent>
     <groupId>org.apache.jackrabbit</groupId>
     <artifactId>oak-parent</artifactId>
-    <version>0.5-SNAPSHOT</version>
+    <version>0.6-SNAPSHOT</version>
+    <relativePath>../oak-parent/pom.xml</relativePath>
   </parent>
 
   <artifactId>oak-mongomk-test</artifactId>
+  <name>Oak Mongo MicroKernel Test</name>
 
   <dependencies>
-    <dependency>
-      <groupId>org.apache.jackrabbit</groupId>
-      <artifactId>oak-mongomk-api</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.jackrabbit</groupId>
-      <artifactId>oak-mongomk-impl</artifactId>
-      <version>${project.version}</version>
-    </dependency>
+
+    <!-- Oak MongoMK -->
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>oak-mongomk</artifactId>
       <version>${project.version}</version>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.json</groupId>
-      <artifactId>json</artifactId>
-      <version>20090211</version>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
+
+    <!-- Test -->
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>oak-it-mk</artifactId>
       <version>${project.version}</version>
       <scope>test</scope>
     </dependency>
+
   </dependencies>
 
 </project>

Modified: jackrabbit/oak/trunk/oak-mongomk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/pom.xml?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-mongomk/pom.xml Wed Sep 26 10:12:22 2012
@@ -80,12 +80,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <version>3.1</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
         <groupId>ch.qos.logback</groupId>
         <artifactId>logback-classic</artifactId>
         <version>1.0.1</version>

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongo.java?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongo.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongo.java
Wed Sep 26 10:12:22 2012
@@ -42,10 +42,6 @@ import org.slf4j.LoggerFactory;
  */
 public class GetNodesCommandMongo extends AbstractCommand<Node> {
 
-    class InconsitentNodeHierarchyException extends Exception {
-        private static final long serialVersionUID = 8155418280936077632L;
-    }
-
     private static final Logger LOG = LoggerFactory.getLogger(GetNodesCommandMongo.class);
 
     private final MongoConnection mongoConnection;
@@ -87,7 +83,7 @@ public class GetNodesCommandMongo extend
         boolean verified = verifyProblematicNodes() && verifyNodeHierarchy();
 
         if (!verified) {
-            throw new InconsitentNodeHierarchyException();
+            throw new InconsistentNodeHierarchyException();
         }
 
         this.buildNodeStructure();
@@ -102,7 +98,7 @@ public class GetNodesCommandMongo extend
 
     @Override
     public boolean needsRetry(Exception e) {
-        return e instanceof InconsitentNodeHierarchyException;
+        return e instanceof InconsistentNodeHierarchyException;
     }
 
     private void buildNodeStructure() {

Added: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java?rev=1390369&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java
(added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java
Wed Sep 26 10:12:22 2012
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mongomk.command;
+
+public class InconsistentNodeHierarchyException extends Exception {
+
+    private static final long serialVersionUID = 6361719178625761034L;
+
+}

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitCommandInstructionVisitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitCommandInstructionVisitor.java?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitCommandInstructionVisitor.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitCommandInstructionVisitor.java
Wed Sep 26 10:12:22 2012
@@ -17,8 +17,11 @@
 package org.apache.jackrabbit.mongomk.model;
 
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
 import org.apache.jackrabbit.mongomk.MongoConnection;
 import org.apache.jackrabbit.mongomk.api.model.Instruction.AddNodeInstruction;
@@ -187,9 +190,27 @@ public class CommitCommandInstructionVis
             NodeMongo srcNode = getStoredNode(srcPath);
             destNode = srcNode;
             destNode.setPath(destPath);
+            pathNodeMap.remove(srcPath);
             pathNodeMap.put(destPath, destNode);
         }
 
+        // [Mete] Check that this works in all cases.
+        // Remove all the pending old node child changes.
+        Map<String, NodeMongo> pendingChanges = new HashMap<String, NodeMongo>();
+        for (Iterator<Entry<String, NodeMongo>> iterator = pathNodeMap.entrySet().iterator();
iterator.hasNext();) {
+            Entry<String, NodeMongo> entry = iterator.next();
+            String path = entry.getKey();
+            NodeMongo node = entry.getValue();
+            if (path.startsWith(srcPath)) {
+                iterator.remove();
+                String newPath = destPath + path.substring(srcPath.length());
+                node.setPath(newPath);
+                pendingChanges.put(newPath, node);
+            }
+        }
+        pathNodeMap.putAll(pendingChanges);
+
+
         // Remove from srcParent - [Mete] What if there is no such child?
         NodeMongo scrParentNode = getStoredNode(srcParentPath);
         scrParentNode.removeChild(srcNodeName);

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java
Wed Sep 26 10:12:22 2012
@@ -86,7 +86,7 @@ public class CommitMongo extends BasicDB
 
     @SuppressWarnings("unchecked")
     public List<String> getAffectedPaths() {
-        return (List<String>) this.get(KEY_AFFECTED_PATH);
+        return (List<String>) get(KEY_AFFECTED_PATH);
     }
 
     public long getBaseRevisionId() {
@@ -110,7 +110,7 @@ public class CommitMongo extends BasicDB
     }
 
     public boolean hasFailed() {
-        return this.getBoolean(KEY_FAILED);
+        return getBoolean(KEY_FAILED);
     }
 
     public void setAffectedPaths(List<String> affectedPaths) {
@@ -142,7 +142,7 @@ public class CommitMongo extends BasicDB
     }
 
     public void setRevisionId(String revisionId) {
-        this.setRevisionId(MongoUtil.toMongoRepresentation(revisionId));
+        setRevisionId(MongoUtil.toMongoRepresentation(revisionId));
     }
 
     public void setTimestamp(long timestamp) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java
Wed Sep 26 10:12:22 2012
@@ -255,16 +255,16 @@ public class NodeMongo extends BasicDBOb
     public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append(super.toString());
-        sb.append(" internal props: ");
-        sb.append("AddedChildren = ");
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(", addedChildren : ");
         sb.append(addedChildren);
-        sb.append(", RemovedChildren = ");
+        sb.append(", removedChildren : ");
         sb.append(removedChildren);
-        sb.append(", AddedProps = ");
+        sb.append(", addedProps : ");
         sb.append(addedProps);
-        sb.append(", RemovedProps = ");
+        sb.append(", removedProps : ");
         sb.append(removedProps);
-
+        sb.append(" }");
         return sb.toString();
     }
 }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQuery.java?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQuery.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQuery.java
Wed Sep 26 10:12:22 2012
@@ -113,6 +113,9 @@ public class FetchValidCommitsQuery exte
 
         while (true) {
             CommitMongo commitMongo = revisions.get(currentRevision);
+            if (commitMongo == null) {
+                break;
+            }
             validCommits.add(commitMongo);
             Long baseRevision = commitMongo.getBaseRevisionId();
             Long fromRevision = MongoUtil.toMongoRepresentation(fromRevisionId);

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java?rev=1390369&r1=1390368&r2=1390369&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java
Wed Sep 26 10:12:22 2012
@@ -16,153 +16,72 @@
  */
 package org.apache.jackrabbit.mongomk.command;
 
-import java.util.Arrays;
-import java.util.Set;
+import static org.junit.Assert.fail;
 
 import org.apache.jackrabbit.mongomk.BaseMongoTest;
-import org.apache.jackrabbit.mongomk.MongoConnection;
 import org.apache.jackrabbit.mongomk.api.model.Node;
 import org.apache.jackrabbit.mongomk.impl.NodeAssert;
 import org.apache.jackrabbit.mongomk.impl.builder.NodeBuilder;
-import org.apache.jackrabbit.mongomk.model.CommitMongo;
-import org.apache.jackrabbit.mongomk.model.NodeMongo;
 import org.apache.jackrabbit.mongomk.scenario.SimpleNodeScenario;
-import org.easymock.EasyMock;
-import org.junit.Ignore;
 import org.junit.Test;
 
-import com.mongodb.BasicDBList;
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-
 /**
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ * Tests GetNodesCommandMongo.
  */
-@SuppressWarnings("javadoc")
 public class GetNodesCommandMongoTest extends BaseMongoTest {
 
     @Test
-    public void testGetNodesAfterDeletion() throws Exception {
+    public void getNodesSimple() throws Exception {
         SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
-        String revisionId = scenario.create();
-        revisionId = scenario.delete_A();
-
-        GetNodesCommandMongo command = new GetNodesCommandMongo(mongoConnection, "/", revisionId,
-1);
-        Node actual = command.execute();
-        Node expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : {} }", revisionId));
-
-        NodeAssert.assertDeepEquals(expected, actual);
-    }
-
-    @Test
-    @Ignore
-    public void testGetNodeWithMissingLeafNode() throws Exception {
-        Node expected = NodeBuilder
-                .build(String
-                        .format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\"
: 0.123 , \"b#%1$s\" : { \"string\" : \"foo\" , \"e#%2$s\" : { \"array\" : [ 123, null, 123.456,
\"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null
} } } }",
-                                "1", "2"));
-        MongoConnection mockConnection = createMissingNodeScenario(expected, "/a/c");
-
-        GetNodesCommandMongo command = new GetNodesCommandMongo(mockConnection, "/", "2",
-1);
-        Node actual = command.execute();
-
-        NodeAssert.assertDeepEquals(expected, actual);
-    }
-
-    @Test
-    @Ignore
-    public void testGetNodeWithMissingParentNode() throws Exception {
-        Node expected = NodeBuilder
-                .build(String
-                        .format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\"
: 0.123 , \"b#%1$s\" : { \"string\" : \"foo\" , \"e#%2$s\" : { \"array\" : [ 123, null, 123.456,
\"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null
} } } }",
-                                "1", "2"));
-        MongoConnection mockConnection = createMissingNodeScenario(expected, "/a");
-
-        GetNodesCommandMongo command = new GetNodesCommandMongo(mockConnection, "/", "2",
-1);
-        Node actual = command.execute();
-
-        NodeAssert.assertDeepEquals(expected, actual);
-    }
-
-    @Test
-    @Ignore
-    public void testGetNodeWithStaleLeafNode() throws Exception {
-        Node expected = NodeBuilder
-                .build(String
-                        .format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\"
: 0.123 , \"b#%1$s\" : { \"string\" : \"foo\" , \"e#%2$s\" : { \"array\" : [ 123, null, 123.456,
\"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null
} } } }",
-                                "1", "2"));
-        MongoConnection mockConnection = createStaleNodeScenario(expected, "/a/c");
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
 
-        GetNodesCommandMongo command = new GetNodesCommandMongo(mockConnection, "/", "2",
-1);
+        GetNodesCommandMongo command = new GetNodesCommandMongo(mongoConnection, "/",
+                firstRevisionId, 0);
         Node actual = command.execute();
-
+        Node expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : { \"a\" : {} } }",
+                firstRevisionId));
         NodeAssert.assertDeepEquals(expected, actual);
-    }
-
-    @Test
-    @Ignore
-    public void testGetNodeWithStaleParentNode() throws Exception {
-        Node expected = NodeBuilder
-                .build(String
-                        .format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\"
: 0.123 , \"b#%1$s\" : { \"string\" : \"foo\" , \"e#%2$s\" : { \"array\" : [ 123, null, 123.456,
\"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null
} } } }",
-                                "1", "2"));
-        MongoConnection mockConnection = createStaleNodeScenario(expected, "/a");
-
-        GetNodesCommandMongo command = new GetNodesCommandMongo(mockConnection, "/", "2",
-1);
-        Node actual = command.execute();
 
+        command = new GetNodesCommandMongo(mongoConnection, "/", secondRevisionId, 0);
+        actual = command.execute();
+        expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : { \"a\" : {} } }",
+                firstRevisionId, secondRevisionId));
         NodeAssert.assertDeepEquals(expected, actual);
     }
 
     @Test
-    public void testSimpleGetNodes() throws Exception {
+    public void getNodesDepthLimited() throws Exception {
         SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
         String firstRevisionId = scenario.create();
         String secondRevisionId = scenario.update_A_and_add_D_and_E();
 
-        GetNodesCommandMongo command = new GetNodesCommandMongo(mongoConnection, "/", firstRevisionId,
0);
+        GetNodesCommandMongo command = new GetNodesCommandMongo(mongoConnection, "/", firstRevisionId,
1);
         Node actual = command.execute();
-        Node expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : { \"a\" : {} } }",
-                firstRevisionId));
-        NodeAssert.assertDeepEquals(expected, actual);
-
-        command = new GetNodesCommandMongo(mongoConnection, "/", secondRevisionId, 0);
-        actual = command.execute();
-        expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : { \"a\" : {} } }", firstRevisionId,
-                secondRevisionId));
-        NodeAssert.assertDeepEquals(expected, actual);
-
-        command = new GetNodesCommandMongo(mongoConnection, "/", firstRevisionId, 1);
-        actual = command.execute();
-        expected = NodeBuilder.build(String.format(
-                "{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b\" : {} , \"c\" : {} }
} }",
-                firstRevisionId));
+        Node expected = NodeBuilder.build(
+                String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b\" : {} ,
\"c\" : {} } } }",
+                        firstRevisionId));
         NodeAssert.assertDeepEquals(expected, actual);
 
         command = new GetNodesCommandMongo(mongoConnection, "/", secondRevisionId, 1);
         actual = command.execute();
-        expected = NodeBuilder
-                .build(String
-                        .format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\"
: 0.123, \"b\" : {} , \"c\" : {} , \"d\" : {} } } }",
-                                firstRevisionId, secondRevisionId));
+        expected = NodeBuilder.build(
+                String.format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" :
0.123, \"b\" : {} , \"c\" : {} , \"d\" : {} } } }",
+                        firstRevisionId, secondRevisionId));
         NodeAssert.assertDeepEquals(expected, actual);
 
         command = new GetNodesCommandMongo(mongoConnection, "/", firstRevisionId, 2);
         actual = command.execute();
-        expected = NodeBuilder
-                .build(String
-                        .format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\"
: { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
-                                firstRevisionId));
+        expected = NodeBuilder.build(
+                String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" :
{ \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                        firstRevisionId));
         NodeAssert.assertDeepEquals(expected, actual);
 
         command = new GetNodesCommandMongo(mongoConnection, "/", secondRevisionId, 2);
         actual = command.execute();
-        expected = NodeBuilder
-                .build(String
-                        .format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\"
: 0.123 , \"b#%2$s\" : { \"string\" : \"foo\" , \"e\" : {} } , \"c#%1$s\" : { \"bool\" : true
}, \"d#%2$s\" : { \"null\" : null } } } }",
-                                firstRevisionId, secondRevisionId));
+        expected = NodeBuilder.build(
+                String.format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" :
0.123 , \"b#%2$s\" : { \"string\" : \"foo\" , \"e\" : {} } , \"c#%1$s\" : { \"bool\" : true
}, \"d#%2$s\" : { \"null\" : null } } } }",
+                        firstRevisionId, secondRevisionId));
         NodeAssert.assertDeepEquals(expected, actual);
 
         command = new GetNodesCommandMongo(mongoConnection, "/", firstRevisionId, -1);
@@ -182,119 +101,50 @@ public class GetNodesCommandMongoTest ex
         NodeAssert.assertDeepEquals(expected, actual);
     }
 
-    private MongoConnection createMissingNodeScenario(Node expected, String missingPath)
{
-        BasicDBList results1 = new BasicDBList();
-        BasicDBList results2 = new BasicDBList();
-
-        Set<NodeMongo> expectedNodeMongos = NodeMongo.fromNodes(expected.getDescendants(true));
-        for (NodeMongo nodeMongo : expectedNodeMongos) {
-
-            BasicDBObject groupDbObject = new BasicDBObject();
-            groupDbObject.put("result", nodeMongo);
-            if (!nodeMongo.getPath().equals(missingPath)) {
-                results1.add(groupDbObject);
-            }
-            results2.add(groupDbObject);
-        }
+    @Test
+    public void getNodesDepthUnlimited() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
 
-        DBCollection mockNodeCollection = EasyMock.createMock(DBCollection.class);
-        EasyMock.expect(
-                mockNodeCollection.group(EasyMock.anyObject(DBObject.class), EasyMock.anyObject(DBObject.class),
-                        EasyMock.anyObject(DBObject.class), EasyMock.anyObject(String.class))).andReturn(results1)
-                .once();
-        EasyMock.expect(
-                mockNodeCollection.group(EasyMock.anyObject(DBObject.class), EasyMock.anyObject(DBObject.class),
-                        EasyMock.anyObject(DBObject.class), EasyMock.anyObject(String.class))).andReturn(results2)
-                .once();
-        EasyMock.replay(mockNodeCollection);
-
-        CommitMongo firstCommit = new CommitMongo();
-        firstCommit.setAffectedPaths(Arrays.asList(new String[] { "/", "/a", "/a/b", "/a/c"
}));
-        firstCommit.setRevisionId(1L);
-
-        CommitMongo secondCommit = new CommitMongo();
-        secondCommit.setAffectedPaths(Arrays.asList(new String[] { "/a", "/a/d", "/a/b/e"
}));
-        secondCommit.setRevisionId(2L);
-
-        DBCursor mockDbCursor = EasyMock.createMock(DBCursor.class);
-        EasyMock.expect(mockDbCursor.sort(EasyMock.anyObject(DBObject.class))).andReturn(mockDbCursor);
-        EasyMock.expect(mockDbCursor.limit(EasyMock.anyInt())).andReturn(mockDbCursor);
-        EasyMock.expect(mockDbCursor.hasNext()).andReturn(true).once();
-        EasyMock.expect(mockDbCursor.next()).andReturn(firstCommit).once();
-        EasyMock.expect(mockDbCursor.hasNext()).andReturn(true).once();
-        EasyMock.expect(mockDbCursor.next()).andReturn(secondCommit).once();
-        EasyMock.expect(mockDbCursor.hasNext()).andReturn(false).once();
-        EasyMock.replay(mockDbCursor);
-
-        DBCollection mockCommitCollection = EasyMock.createMock(DBCollection.class);
-        EasyMock.expect(mockCommitCollection.find(EasyMock.anyObject(DBObject.class))).andReturn(mockDbCursor);
-        EasyMock.replay(mockCommitCollection);
-
-        MongoConnection mockConnection = EasyMock.createMock(MongoConnection.class);
-        EasyMock.expect(mockConnection.getNodeCollection()).andReturn(mockNodeCollection).times(2);
-        EasyMock.expect(mockConnection.getCommitCollection()).andReturn(mockCommitCollection);
-        EasyMock.replay(mockConnection);
+        GetNodesCommandMongo command = new GetNodesCommandMongo(mongoConnection, "/", firstRevisionId,
-1);
+        Node actual = command.execute();
+        Node expected = NodeBuilder.build(
+                String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" :
{ \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                        firstRevisionId));
+        NodeAssert.assertDeepEquals(expected, actual);
 
-        return mockConnection;
+        command = new GetNodesCommandMongo(mongoConnection, "/", secondRevisionId, -1);
+        actual = command.execute();
+        expected = NodeBuilder.build(
+                String.format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" :
0.123 , \"b#%2$s\" : { \"string\" : \"foo\" , \"e#%2$s\" : { \"array\" : [ 123, null, 123.456,
\"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null
} } } }",
+                        firstRevisionId, secondRevisionId));
+        NodeAssert.assertDeepEquals(expected, actual);
     }
 
-    private MongoConnection createStaleNodeScenario(Node expected, String stalePath) {
-        BasicDBList results1 = new BasicDBList();
-        BasicDBList results2 = new BasicDBList();
-
-        Set<NodeMongo> expectedNodeMongos = NodeMongo.fromNodes(expected.getDescendants(true));
-        for (NodeMongo nodeMongo : expectedNodeMongos) {
-            BasicDBObject groupDbObject = new BasicDBObject();
-            groupDbObject.put("result", nodeMongo);
-            results2.add(groupDbObject);
-
-            if (nodeMongo.getPath().equals(stalePath)) {
-                NodeMongo nodeMongoStale = new NodeMongo();
-                nodeMongoStale.putAll(nodeMongo.toMap());
-                nodeMongoStale.setRevisionId(1L);
-            }
+    @Test
+    public void getNodesAfterDeletion() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String revisionId = scenario.create();
+        revisionId = scenario.delete_A();
 
-            results1.add(groupDbObject);
-        }
+        GetNodesCommandMongo command = new GetNodesCommandMongo(mongoConnection, "/", revisionId,
-1);
+        Node actual = command.execute();
+        Node expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : {} }", revisionId));
+
+        NodeAssert.assertDeepEquals(expected, actual);
+    }
 
-        DBCollection mockNodeCollection = EasyMock.createMock(DBCollection.class);
-        EasyMock.expect(
-                mockNodeCollection.group(EasyMock.anyObject(DBObject.class), EasyMock.anyObject(DBObject.class),
-                        EasyMock.anyObject(DBObject.class), EasyMock.anyObject(String.class))).andReturn(results1)
-                .once();
-        EasyMock.expect(
-                mockNodeCollection.group(EasyMock.anyObject(DBObject.class), EasyMock.anyObject(DBObject.class),
-                        EasyMock.anyObject(DBObject.class), EasyMock.anyObject(String.class))).andReturn(results2)
-                .once();
-        EasyMock.replay(mockNodeCollection);
-
-        CommitMongo firstCommit = new CommitMongo();
-        firstCommit.setAffectedPaths(Arrays.asList(new String[] { "/", "/a", "/a/b", "/a/c"
}));
-        firstCommit.setRevisionId(1L);
-
-        CommitMongo secondCommit = new CommitMongo();
-        secondCommit.setAffectedPaths(Arrays.asList(new String[] { "/a", "/a/d", "/a/b/e"
}));
-        secondCommit.setRevisionId(2L);
-
-        DBCursor mockDbCursor = EasyMock.createMock(DBCursor.class);
-        EasyMock.expect(mockDbCursor.sort(EasyMock.anyObject(DBObject.class))).andReturn(mockDbCursor);
-        EasyMock.expect(mockDbCursor.limit(EasyMock.anyInt())).andReturn(mockDbCursor);
-        EasyMock.expect(mockDbCursor.hasNext()).andReturn(true).once();
-        EasyMock.expect(mockDbCursor.next()).andReturn(firstCommit).once();
-        EasyMock.expect(mockDbCursor.hasNext()).andReturn(true).once();
-        EasyMock.expect(mockDbCursor.next()).andReturn(secondCommit).once();
-        EasyMock.expect(mockDbCursor.hasNext()).andReturn(false).once();
-        EasyMock.replay(mockDbCursor);
-
-        DBCollection mockCommitCollection = EasyMock.createMock(DBCollection.class);
-        EasyMock.expect(mockCommitCollection.find(EasyMock.anyObject(DBObject.class))).andReturn(mockDbCursor);
-        EasyMock.replay(mockCommitCollection);
-
-        MongoConnection mockConnection = EasyMock.createMock(MongoConnection.class);
-        EasyMock.expect(mockConnection.getNodeCollection()).andReturn(mockNodeCollection).times(2);
-        EasyMock.expect(mockConnection.getCommitCollection()).andReturn(mockCommitCollection);
-        EasyMock.replay(mockConnection);
+    @Test
+    public void getNodesInvalidRevisionId() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        scenario.create();
 
-        return mockConnection;
+        GetNodesCommandMongo command = new GetNodesCommandMongo(mongoConnection, "/", String.valueOf(Long.MAX_VALUE),
-1);
+        try {
+            command.execute();
+            fail("Exception expected");
+        } catch (Exception expected) {
+        }
     }
 }



Mime
View raw message