Index: oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongo.java =================================================================== --- oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongo.java (revision 1388461) +++ oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongo.java (working copy) @@ -16,13 +16,11 @@ */ package org.apache.jackrabbit.mongomk.command; -import java.util.List; +import java.util.Set; import org.apache.jackrabbit.mongomk.MongoConnection; import org.apache.jackrabbit.mongomk.api.command.AbstractCommand; -import org.apache.jackrabbit.mongomk.model.NodeMongo; -import org.apache.jackrabbit.mongomk.query.FetchNodeByPathQuery; -import org.apache.jackrabbit.mongomk.util.MongoUtil; +import org.apache.jackrabbit.mongomk.api.model.Node; import org.apache.jackrabbit.oak.commons.PathUtils; /** @@ -31,10 +29,12 @@ * @author instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "1")); - Commit commit = new CommitImpl("This is the 1st commit", "/", "+1 : {}", instructions); + Commit commit = new CommitImpl("/", "+1 : {}", "This is the 1st commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String firstRevisionId = command.execute(); instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "2")); - commit = new CommitImpl("This is the 2nd commit", "/", "+2 : {}", instructions); + commit = new CommitImpl("/", "+2 : {}", "This is the 2nd commit", instructions); command = new CommitCommandMongo(mongoConnection, commit); String secondRevisionId = command.execute(); instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "3")); - commit = new CommitImpl("This is the 3rd commit", "/", "+3 : {}", instructions); + commit = new CommitImpl("/", "+3 : {}", "This is the 3rd commit", instructions); command = new CommitCommandMongo(mongoConnection, commit); String thirdRevisionId = command.execute(); @@ -76,13 +77,14 @@ } @Test - public void testCommitAddNodes() throws Exception { + public void commitAddNodes() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "a")); instructions.add(new AddNodeInstructionImpl("/a", "b")); instructions.add(new AddNodeInstructionImpl("/a", "c")); - Commit commit = new CommitImpl("This is a simple commit", "/", "+a : { b : {} , c : {} }", instructions); + Commit commit = new CommitImpl("/", "+a : { b : {} , c : {} }", + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -97,7 +99,7 @@ } @Test - public void testCommitAddNodesAndPropertiesOutOfOrder() throws Exception { + public void commitAddNodesAndPropertiesOutOfOrder() throws Exception { List instructions = new LinkedList(); instructions.add(new AddPropertyInstructionImpl("/a", "key1", "value1")); instructions.add(new AddNodeInstructionImpl("/", "a")); @@ -106,8 +108,9 @@ instructions.add(new AddPropertyInstructionImpl("/a/c", "key3", "value3")); instructions.add(new AddNodeInstructionImpl("/a", "c")); - Commit commit = new CommitImpl("This is a simple commit", "/", - "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", instructions); + Commit commit = new CommitImpl("/", + "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -126,7 +129,7 @@ } @Test - public void testCommitAddNodesWhichAlreadyExist() throws Exception { + public void commitAddNodesWhichAlreadyExist() throws Exception { SimpleNodeScenario scenario1 = new SimpleNodeScenario(mongoConnection); scenario1.create(); @@ -138,8 +141,9 @@ instructions.add(new AddNodeInstructionImpl("/a", "c")); instructions.add(new AddPropertyInstructionImpl("/a/c", "key3", "value3")); - Commit commit = new CommitImpl("This is a simple commit", "/", - "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", instructions); + Commit commit = new CommitImpl("/", + "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -158,7 +162,7 @@ } @Test - public void testCommitAndMergeNodes() throws Exception { + public void commitAndMergeNodes() throws Exception { SimpleNodeScenario scenario1 = new SimpleNodeScenario(mongoConnection); String firstRevisionId = scenario1.create(); String secondRevisionId = scenario1.update_A_and_add_D_and_E(); @@ -188,7 +192,7 @@ } @Test - public void testCommitContainsAllAffectedNodes() throws Exception { + public void commitContainsAllAffectedNodes() throws Exception { SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection); String firstRevisionId = scenario.create(); String secondRevisionId = scenario.update_A_and_add_D_and_E(); @@ -198,13 +202,14 @@ } @Test - public void testRemoveNode() throws Exception { + public void removeNode() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "a")); instructions.add(new AddNodeInstructionImpl("/a", "b")); instructions.add(new AddNodeInstructionImpl("/a", "c")); - Commit commit = new CommitImpl("This is a simple commit", "/", "+a : { b : {} , c : {} }", instructions); + Commit commit = new CommitImpl("/", "+a : { b : {} , c : {} }", + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); Assert.assertNotNull(revisionId); @@ -212,7 +217,7 @@ instructions = new LinkedList(); instructions.add(new RemoveNodeInstructionImpl("/", "a")); - commit = new CommitImpl("This is a simple commit", "/", "-a", instructions); + commit = new CommitImpl("/", "-a", "This is a simple commit", instructions); command = new CommitCommandMongo(mongoConnection, commit); revisionId = command.execute(); Assert.assertNotNull(revisionId); @@ -226,19 +231,19 @@ @Test @Ignore // FIXME - public void testRemoveNonExistentNode() throws Exception { + public void removeNonExistentNode() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "a")); instructions.add(new AddNodeInstructionImpl("/a", "b")); - Commit commit = new CommitImpl("Add nodes", "/", "+a : { b : {} }", instructions); + Commit commit = new CommitImpl("/", "+a : { b : {} }", "Add nodes", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); command.execute(); instructions = new LinkedList(); instructions.add(new RemoveNodeInstructionImpl("/a", "c")); - commit = new CommitImpl("Non-existent node delete", "/a", "-c", instructions); + commit = new CommitImpl("/a", "-c", "Non-existent node delete", instructions); command = new CommitCommandMongo(mongoConnection, commit); try { command.execute(); @@ -249,13 +254,14 @@ } @Test - public void testExistingParentContainsChildren() throws Exception { + public void existingParentContainsChildren() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "a")); instructions.add(new AddNodeInstructionImpl("/", "b")); instructions.add(new AddNodeInstructionImpl("/", "c")); - Commit commit = new CommitImpl("This is a simple commit", "/", "+a : { b : {} , c : {} }", instructions); + Commit commit = new CommitImpl("/", "+a : { b : {} , c : {} }", + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -269,15 +275,16 @@ } @Test - public void testMergePropertiesAndChildren_noneExistedAndNewAdded() throws Exception { + public void mergePropertiesAndChildren_noneExistedAndNewAdded() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "a")); instructions.add(new AddPropertyInstructionImpl("/a", "key1", "value1")); instructions.add(new AddPropertyInstructionImpl("/a", "key2", "value2")); instructions.add(new AddPropertyInstructionImpl("/a", "key3", "value3")); - Commit commit = new CommitImpl("This is a simple commit", "/", - "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", instructions); + Commit commit = new CommitImpl("/", + "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -291,18 +298,16 @@ } @Test - public void testMergePropertiesAndChildren_someExistedAndNewAdded() throws Exception { + public void mergePropertiesAndChildren_someExistedAndNewAdded() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "a")); instructions.add(new AddPropertyInstructionImpl("/a", "existed_key1", "value1")); instructions.add(new AddPropertyInstructionImpl("/a", "existed_key2", "value2")); instructions.add(new AddPropertyInstructionImpl("/a", "existed_key3", "value3")); - Commit commit = new CommitImpl( - "This is a simple commit", - "/", + Commit commit = new CommitImpl("/", "+a : { \"existed_key1\" : \"value1\" , \"existed_key2\" : \"value2\" , \"existed_key3\" : \"value3\" }", - instructions); + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -312,8 +317,9 @@ instructions.add(new AddPropertyInstructionImpl("/a", "key2", "value2")); instructions.add(new AddPropertyInstructionImpl("/a", "key3", "value3")); - commit = new CommitImpl("This is a simple commit", "/", - "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", instructions); + commit = new CommitImpl("/", + "+a : { \"key1\" : \"value1\" , \"key2\" : \"value2\" , \"key3\" : \"value3\" }", + "This is a simple commit", instructions); command = new CommitCommandMongo(mongoConnection, commit); revisionId = command.execute(); @@ -327,13 +333,14 @@ } @Test - public void testNoOtherNodesTouched() throws Exception { + public void noOtherNodesTouched() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", "a")); instructions.add(new AddNodeInstructionImpl("/", "b")); instructions.add(new AddNodeInstructionImpl("/", "c")); - Commit commit = new CommitImpl("This is a simple commit", "/", "+a : { b : {} , c : {} }", instructions); + Commit commit = new CommitImpl("/", "+a : { b : {} , c : {} }", + "This is a simple commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String firstRevisionId = command.execute(); @@ -341,7 +348,7 @@ instructions.add(new AddNodeInstructionImpl("/a", "d")); instructions.add(new AddNodeInstructionImpl("/a", "e")); - commit = new CommitImpl("This is a simple commit", "/a", "+d: {} \n+e : {}", instructions); + commit = new CommitImpl("/a", "+d: {} \n+e : {}", "This is a simple commit", instructions); command = new CommitCommandMongo(mongoConnection, commit); String secondRevisionId = command.execute(); @@ -362,11 +369,11 @@ @Test @Ignore /// FIXME - public void testRootNodeHasEmptyRootPath() throws Exception { + public void rootNodeHasEmptyRootPath() throws Exception { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("", "/")); - Commit commit = new CommitImpl("This is the root commit", "", "+/ : {}", instructions); + Commit commit = new CommitImpl("", "+/ : {}", "This is the root commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -374,4 +381,29 @@ MongoAssert.assertNodesExist("", NodeBuilder.build(String.format("{ \"/#%1$s\" : {} }", revisionId))); } + + @Test + @Ignore + // FIXME - This currently fails due to some limit in property sizes in Mongo + // which affects path property. + public void bigCommit() throws Exception { + String path = "/"; + String baseNodeName = "test"; + int numberOfCommits = 1000; + + List instructions = new LinkedList(); + for (int i = 0; i < numberOfCommits; i++) { + instructions.clear(); + instructions.add(new AddNodeInstructionImpl(path, baseNodeName + i)); + Commit commit = new CommitImpl(path, "+" + baseNodeName + i + " : {}", + "Add node n" + i, instructions); + CommitCommandMongo command = new CommitCommandMongo( + mongoConnection, commit); + command.execute(); + if (!PathUtils.denotesRoot(path)) { + path += "/"; + } + path += baseNodeName + i; + } + } } Index: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ConcurrentCommitCommandMongoTest.java =================================================================== --- oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ConcurrentCommitCommandMongoTest.java (revision 1388461) +++ oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ConcurrentCommitCommandMongoTest.java (working copy) @@ -52,7 +52,8 @@ for (int i = 0; i < numOfConcurrentThreads; ++i) { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/", String.valueOf(i))); - Commit commit = new CommitImpl("This is a concurrent commit", "/", "+" + i + " : {}", instructions); + Commit commit = new CommitImpl("/", "+" + i + " : {}", + "This is a concurrent commit", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit) { @Override protected boolean saveAndSetHeadRevision() throws Exception { Index: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java =================================================================== --- oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java (revision 1388461) +++ oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java (working copy) @@ -30,7 +30,6 @@ import org.apache.jackrabbit.mongomk.impl.model.CommitImpl; import org.apache.jackrabbit.mongomk.impl.model.RemoveNodeInstructionImpl; import org.apache.jackrabbit.mongomk.scenario.SimpleNodeScenario; -import org.junit.Ignore; import org.junit.Test; @SuppressWarnings("javadoc") @@ -119,7 +118,7 @@ instructions.add(new AddNodeInstructionImpl("/a/b", "c")); instructions.add(new AddNodeInstructionImpl("/a/b/c", "d")); - Commit commit = new CommitImpl("Add nodes", "/", "TODO", instructions); + Commit commit = new CommitImpl("/", "TODO", "Add nodes", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); command.execute(); @@ -127,7 +126,7 @@ // Remove b. instructions = new LinkedList(); instructions.add(new RemoveNodeInstructionImpl("/a", "b")); - commit = new CommitImpl("Delete /b", "/a", "-b", instructions); + commit = new CommitImpl("/a", "-b", "Delete /b", instructions); command = new CommitCommandMongo(mongoConnection, commit); command.execute(); @@ -139,6 +138,34 @@ } @Test + public void existsInHeadRevision() throws Exception { + + List instructions = new LinkedList(); + + // Add /a + instructions.add(new AddNodeInstructionImpl("/", "a")); + Commit commit1 = new CommitImpl("/", "+a : {}", "Add node a", + instructions); + CommitCommandMongo command = new CommitCommandMongo(mongoConnection, + commit1); + command.execute(); + + // Add /a/b + instructions = new LinkedList(); + instructions.add(new AddNodeInstructionImpl("/a", "b")); + Commit commit2 = new CommitImpl("/a", "+b : {}", "Add node a/b", + instructions); + command = new CommitCommandMongo(mongoConnection, commit2); + command.execute(); + + // Verify /a is visible in the head revision + NodeExistsCommandMongo command2 = new NodeExistsCommandMongo( + mongoConnection, "/a", null); + boolean exists = command2.execute(); + assertTrue("The node a is not found in the head revision!", exists); + } + + @Test public void existsInOldRevNotInNewRev() throws Exception { SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection); String rev1 = scenario.create(); @@ -169,66 +196,4 @@ exists = command.execute(); assertTrue(exists); } - - @Test - @Ignore - public void testNodeNotFound() throws Exception { - - // adds nodes /a,/a/b,/a/b/c , checks if node a exists - List instructions = new LinkedList(); - - // commit node /a - instructions.add(new AddNodeInstructionImpl("/", "a")); - Commit commit1 = new CommitImpl("/", "+a : {}", "Add node a", - instructions); - CommitCommandMongo command = new CommitCommandMongo(mongoConnection, - commit1); - command.execute(); - - // commit node /a/b - instructions = new LinkedList(); - instructions.add(new AddNodeInstructionImpl("/a", "b")); - Commit commit2 = new CommitImpl("/a", "+b : {}", "Add node a/b", - instructions); - command = new CommitCommandMongo(mongoConnection, commit2); - command.execute(); - - // commit node /a/b/c - instructions = new LinkedList(); - instructions.add(new AddNodeInstructionImpl("/a/b", "c")); - Commit commit3 = new CommitImpl("a/b", "+c : {}", "Add node a/b/c", - instructions); - command = new CommitCommandMongo(mongoConnection, commit3); - command.execute(); - - // verify if node a is visible in the head revision - NodeExistsCommandMongo isNodeVisible = new NodeExistsCommandMongo( - mongoConnection, "/a", null); - boolean exists = isNodeVisible.execute(); - assertTrue("The node a is not found in the head revision!", exists); - - } - - @Test - @Ignore - public void testTreeDepth() throws Exception { - - String path = "/"; - List instructions = new LinkedList(); - - for (int i = 0; i < 1000; i++) { - instructions.clear(); - instructions.add(new AddNodeInstructionImpl(path, "N" + i)); - Commit commit1 = new CommitImpl(path, "+N" + i + " : {}", - "Add node N" + i, instructions); - CommitCommandMongo command = new CommitCommandMongo( - mongoConnection, commit1); - command.execute(); - path = (path.endsWith("/")) ? (path = path + "N" + i) - : (path = path + "/N" + i); - //System.out.println("*********" + path.length() + "*****"); - } - - } - -} +} \ No newline at end of file Index: oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java =================================================================== --- oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java (revision 1388461) +++ oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java (working copy) @@ -67,8 +67,9 @@ instructions.add(new AddPropertyInstructionImpl("/a/b", "string", "foo")); instructions.add(new AddPropertyInstructionImpl("/a/c", "bool", true)); - Commit commit = new CommitImpl("This is the simple node scenario with nodes /, /a, /a/b, /a/c", "/", - "+a : { \"int\" : 1 , \"b\" : { \"string\" : \"foo\" } , \"c\" : { \"bool\" : true } } }", instructions); + Commit commit = new CommitImpl("/", + "+a : { \"int\" : 1 , \"b\" : { \"string\" : \"foo\" } , \"c\" : { \"bool\" : true } } }", + "This is the simple node scenario with nodes /, /a, /a/b, /a/c", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -80,7 +81,7 @@ for (int i = 1; i <= count; i++) { List instructions = new LinkedList(); instructions.add(new AddNodeInstructionImpl("/a", "child" + i)); - Commit commit = new CommitImpl("Add child" + i, "/a", "TODO", instructions); + Commit commit = new CommitImpl("/a", "TODO", "Add child" + i, instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); revisionId = command.execute(); } @@ -102,7 +103,8 @@ List instructions = new LinkedList(); instructions.add(new RemoveNodeInstructionImpl("/", "a")); - Commit commit = new CommitImpl("This is a commit with deleted /a", "/", "-a", instructions); + Commit commit = new CommitImpl("/", "-a", "This is a commit with deleted /a", + instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute(); @@ -112,7 +114,8 @@ public String delete_B() throws Exception { List instructions = new LinkedList(); instructions.add(new RemoveNodeInstructionImpl("/a", "b")); - Commit commit = new CommitImpl("This is a commit with deleted /a/b", "/a", "-b", instructions); + Commit commit = new CommitImpl("/a", "-b", "This is a commit with deleted /a/b", + instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); return command.execute(); } @@ -137,7 +140,7 @@ instructions.add(new AddPropertyInstructionImpl("/a/b/e", "array", new Object[] { 123, null, 123.456D, "for:bar", Boolean.TRUE })); - Commit commit = new CommitImpl("This is a commit with updated /a and added /a/d and /a/b/e", "", "TODO", + Commit commit = new CommitImpl("", "TODO", "This is a commit with updated /a and added /a/d and /a/b/e", instructions); CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit); String revisionId = command.execute();