jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1386591 [7/7] - in /jackrabbit/oak/trunk: ./ oak-mongomk-api/ oak-mongomk-api/src/ oak-mongomk-api/src/main/ oak-mongomk-api/src/main/java/ oak-mongomk-api/src/main/java/org/ oak-mongomk-api/src/main/java/org/apache/ oak-mongomk-api/src/ma...
Date Mon, 17 Sep 2012 12:54:06 GMT
Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetBlobLengthCommandMongoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetBlobLengthCommandMongoTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetBlobLengthCommandMongoTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetBlobLengthCommandMongoTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+import org.apache.jackrabbit.mongomk.command.GetBlobLengthCommandMongo;
+import org.junit.Test;
+
+import com.mongodb.gridfs.GridFS;
+import com.mongodb.gridfs.GridFSInputFile;
+
+public class GetBlobLengthCommandMongoTest extends BaseMongoTest {
+
+    @Test
+    public void testGetBlobLength() throws Exception {
+        int blobLength = 100;
+        String blobId = createAndWriteBlob(blobLength);
+
+        GetBlobLengthCommandMongo command = new GetBlobLengthCommandMongo(mongoConnection, blobId);
+        long length = command.execute();
+        assertEquals(blobLength, length);
+    }
+
+    @Test
+    public void testNonExistantBlobLength() throws Exception {
+        GetBlobLengthCommandMongo command = new GetBlobLengthCommandMongo(mongoConnection,
+                "nonExistantBlobId");
+        try {
+            command.execute();
+            fail("Exception expected");
+        } catch (Exception expected) {
+        }
+    }
+
+    private String createAndWriteBlob(int blobLength) {
+        byte[] blob = createBlob(blobLength);
+        return writeBlob(blob);
+    }
+
+    private byte[] createBlob(int blobLength) {
+        byte[] blob = new byte[blobLength];
+        for (int i = 0; i < blob.length; i++) {
+            blob[i] = (byte)i;
+        }
+        return blob;
+    }
+
+    private String writeBlob(byte[] blob) {
+        GridFS gridFS = mongoConnection.getGridFS();
+        GridFSInputFile gridFSInputFile = gridFS.createFile(new ByteArrayInputStream(blob), true);
+        gridFSInputFile.save();
+        return gridFSInputFile.getMD5();
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetBlobLengthCommandMongoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetHeadRevisionCommandMongoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetHeadRevisionCommandMongoTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetHeadRevisionCommandMongoTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetHeadRevisionCommandMongoTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+import org.apache.jackrabbit.mongomk.command.GetHeadRevisionCommandMongo;
+import org.apache.jackrabbit.mongomk.scenario.SimpleNodeScenario;
+import org.junit.Test;
+
+
+@SuppressWarnings("javadoc")
+public class GetHeadRevisionCommandMongoTest extends BaseMongoTest {
+
+    @Test
+    public void testGeadHeadRevisionSimple() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String revisionId = scenario.create();
+
+        GetHeadRevisionCommandMongo command = new GetHeadRevisionCommandMongo(mongoConnection);
+        String revisionId2 = command.execute();
+        assertTrue(revisionId.equals(revisionId2));
+
+        scenario.delete_A();
+        String revisionId3 = command.execute();
+        assertFalse(revisionId3.equals(revisionId2));
+    }}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetHeadRevisionCommandMongoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,300 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.Set;
+
+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>
+ */
+@SuppressWarnings("javadoc")
+public class GetNodesCommandMongoTest extends BaseMongoTest {
+
+    @Test
+    public void testGetNodesAfterDeletion() 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");
+
+        GetNodesCommandMongo command = new GetNodesCommandMongo(mockConnection, "/", "2", -1);
+        Node actual = command.execute();
+
+        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();
+
+        NodeAssert.assertDeepEquals(expected, actual);
+    }
+
+    @Test
+    public void testSimpleGetNodes() 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);
+        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));
+        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));
+        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));
+        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));
+        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#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                                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#%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 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);
+        }
+
+        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);
+
+        return mockConnection;
+    }
+
+    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);
+            }
+
+            results1.add(groupDbObject);
+        }
+
+        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);
+
+        return mockConnection;
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/GetNodesCommandMongoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,231 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+import org.apache.jackrabbit.mongomk.api.model.Commit;
+import org.apache.jackrabbit.mongomk.api.model.Instruction;
+import org.apache.jackrabbit.mongomk.impl.model.AddNodeInstructionImpl;
+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.Test;
+
+@SuppressWarnings("javadoc")
+public class NodeExistsCommandMongoTest extends BaseMongoTest {
+
+	@Test
+	public void simple() throws Exception {
+		SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+		String revisionId = scenario.create();
+
+		NodeExistsCommandMongo command = new NodeExistsCommandMongo(
+				mongoConnection, "/a", revisionId);
+		boolean exists = command.execute();
+		assertTrue(exists);
+
+		command = new NodeExistsCommandMongo(mongoConnection, "/a/b",
+				revisionId);
+		exists = command.execute();
+		assertTrue(exists);
+
+		revisionId = scenario.delete_A();
+
+		command = new NodeExistsCommandMongo(mongoConnection, "/a", revisionId);
+		exists = command.execute();
+		assertFalse(exists);
+
+		command = new NodeExistsCommandMongo(mongoConnection, "/a/b",
+				revisionId);
+		exists = command.execute();
+		assertFalse(exists);
+	}
+
+	@Test
+	public void withoutRevisionId() throws Exception {
+		SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+		scenario.create();
+
+		NodeExistsCommandMongo command = new NodeExistsCommandMongo(
+				mongoConnection, "/a", null /* revisionId */);
+		boolean exists = command.execute();
+		assertTrue(exists);
+
+		scenario.delete_A();
+
+		command = new NodeExistsCommandMongo(mongoConnection, "/a", null /* revisionId */);
+		exists = command.execute();
+		assertFalse(exists);
+	}
+
+	@Test
+	public void withInvalidRevisionId() throws Exception {
+		SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+		scenario.create();
+
+		NodeExistsCommandMongo command = new NodeExistsCommandMongo(
+				mongoConnection, "/a", "123456789");
+		try {
+			command.execute();
+			fail("Expected: Invalid revision id exception");
+		} catch (Exception expected) {
+		}
+	}
+
+	@Test
+	public void parentDelete() throws Exception {
+		SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+		scenario.create();
+
+		NodeExistsCommandMongo command = new NodeExistsCommandMongo(
+				mongoConnection, "/a/b", null);
+		boolean exists = command.execute();
+		assertTrue(exists);
+
+		scenario.delete_A();
+		command = new NodeExistsCommandMongo(mongoConnection, "/a/b", null);
+		exists = command.execute();
+		assertFalse(exists);
+	}
+
+	@Test
+	public void grandParentDelete() throws Exception {
+		// Add a->b->c->d.
+		List<Instruction> instructions = new LinkedList<Instruction>();
+		instructions.add(new AddNodeInstructionImpl("/", "a"));
+		instructions.add(new AddNodeInstructionImpl("/a", "b"));
+		instructions.add(new AddNodeInstructionImpl("/a/b", "c"));
+		instructions.add(new AddNodeInstructionImpl("/a/b/c", "d"));
+
+		Commit commit = new CommitImpl("Add nodes", "/", "TODO", instructions);
+		CommitCommandMongo command = new CommitCommandMongo(mongoConnection,
+				commit);
+		command.execute();
+
+		// Remove b.
+		instructions = new LinkedList<Instruction>();
+		instructions.add(new RemoveNodeInstructionImpl("/a", "b"));
+		commit = new CommitImpl("Delete /b", "/a", "-b", instructions);
+		command = new CommitCommandMongo(mongoConnection, commit);
+		command.execute();
+
+		// Check for d.
+		NodeExistsCommandMongo existsCommand = new NodeExistsCommandMongo(
+				mongoConnection, "/a/b/c/d", null);
+		boolean exists = existsCommand.execute();
+		assertFalse(exists);
+	}
+
+	@Test
+	public void existsInOldRevNotInNewRev() throws Exception {
+		SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+		String rev1 = scenario.create();
+		String rev2 = scenario.delete_A();
+
+		NodeExistsCommandMongo command = new NodeExistsCommandMongo(
+				mongoConnection, "/a", rev1);
+		boolean exists = command.execute();
+		assertTrue(exists);
+
+		command = new NodeExistsCommandMongo(mongoConnection, "/a", rev2);
+		exists = command.execute();
+		assertFalse(exists);
+	}
+
+	@Test
+	public void siblingDelete() throws Exception {
+		SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+		scenario.create();
+
+		scenario.delete_B();
+		NodeExistsCommandMongo command = new NodeExistsCommandMongo(
+				mongoConnection, "/a/b", null);
+		boolean exists = command.execute();
+		assertFalse(exists);
+
+		command = new NodeExistsCommandMongo(mongoConnection, "/a/c", null);
+		exists = command.execute();
+		assertTrue(exists);
+	}
+
+	@Test
+	public void testNodeNotFound() throws Exception {
+
+		// adds nodes /a,/a/b,/a/b/c , checks if node a exists
+		List<Instruction> instructions = new LinkedList<Instruction>();
+
+		// 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<Instruction>();
+		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<Instruction>();
+		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
+	public void testTreeDepth() throws Exception {
+
+		String path = "/";
+		List<Instruction> instructions = new LinkedList<Instruction>();
+
+		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() + "*****");
+		}
+		
+	}
+
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/NodeExistsCommandMongoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ReadBlobCommandMongoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ReadBlobCommandMongoTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ReadBlobCommandMongoTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ReadBlobCommandMongoTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+
+import junit.framework.Assert;
+
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+import org.apache.jackrabbit.mongomk.command.ReadBlobCommandMongo;
+import org.junit.Test;
+
+import com.mongodb.gridfs.GridFS;
+import com.mongodb.gridfs.GridFSInputFile;
+
+public class ReadBlobCommandMongoTest extends BaseMongoTest {
+
+    private byte[] blob;
+    private String blobId;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        blob = new byte[100];
+        for (int i = 0; i < blob.length; i++) {
+            blob[i] = (byte) i;
+        }
+        ByteArrayInputStream is = new ByteArrayInputStream(blob);
+        GridFS gridFS = mongoConnection.getGridFS();
+        GridFSInputFile gridFSInputFile = gridFS.createFile(is, true);
+        gridFSInputFile.save();
+        blobId = gridFSInputFile.getMD5();
+    }
+
+    @Test
+    public void testReadBlobComplete() throws Exception {
+        byte[] buffer = new byte[blob.length];
+        ReadBlobCommandMongo command = new ReadBlobCommandMongo(mongoConnection, blobId, 0, buffer, 0, blob.length);
+        int totalBytes = command.execute();
+
+        Assert.assertEquals(blob.length, totalBytes);
+        Assert.assertTrue(Arrays.equals(blob, buffer));
+    }
+
+    @Test
+    public void testReadBlobRangeFromEnd() throws Exception {
+        byte[] buffer = new byte[blob.length / 2];
+        ReadBlobCommandMongo command = new ReadBlobCommandMongo(mongoConnection, blobId, (blob.length / 2) - 1,
+                buffer, 0, blob.length / 2);
+        int totalBytes = command.execute();
+
+        Assert.assertEquals(blob.length / 2, totalBytes);
+        for (int i = 0; i < buffer.length; i++) {
+            Assert.assertEquals(blob[((blob.length / 2) - 1) + i], buffer[i]);
+        }
+    }
+
+    @Test
+    public void testReadBlobRangeFromStart() throws Exception {
+        byte[] buffer = new byte[blob.length / 2];
+        ReadBlobCommandMongo command = new ReadBlobCommandMongo(mongoConnection, blobId, 0, buffer, 0,
+                blob.length / 2);
+        int totalBytes = command.execute();
+
+        Assert.assertEquals(blob.length / 2, totalBytes);
+        for (int i = 0; i < buffer.length; i++) {
+            Assert.assertEquals(blob[i], buffer[i]);
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ReadBlobCommandMongoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/WriteBlobCommandMongoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/WriteBlobCommandMongoTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/WriteBlobCommandMongoTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/WriteBlobCommandMongoTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.jackrabbit.mk.util.IOUtils;
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+import org.apache.jackrabbit.mongomk.command.WriteBlobCommandMongo;
+import org.junit.Test;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.gridfs.GridFS;
+import com.mongodb.gridfs.GridFSDBFile;
+
+public class WriteBlobCommandMongoTest extends BaseMongoTest {
+
+    @Test
+    public void testWriteBlobComplete() throws Exception {
+        int blobLength = 100;
+        byte[] blob = createBlob(blobLength);
+
+        WriteBlobCommandMongo command = new WriteBlobCommandMongo(mongoConnection,
+                new ByteArrayInputStream(blob));
+        String blobId = command.execute();
+        assertNotNull(blobId);
+
+        byte[] readBlob = new byte[blobLength];
+        readBlob(blobId, readBlob);
+        assertTrue(Arrays.equals(blob, readBlob));
+    }
+
+    private byte[] createBlob(int blobLength) {
+        byte[] blob = new byte[blobLength];
+        for (int i = 0; i < blob.length; i++) {
+            blob[i] = (byte)i;
+        }
+        return blob;
+    }
+
+    private void readBlob(String blobId, byte[] readBlob) throws IOException {
+        GridFS gridFS = mongoConnection.getGridFS();
+        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
+        IOUtils.readFully(gridFile.getInputStream(), readBlob, 0, readBlob.length);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/WriteBlobCommandMongoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesByPathAndDepthQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesByPathAndDepthQueryTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesByPathAndDepthQueryTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesByPathAndDepthQueryTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,218 @@
+/*
+ * 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.query;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+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.query.FetchNodesByPathAndDepthQuery;
+import org.apache.jackrabbit.mongomk.scenario.SimpleNodeScenario;
+import org.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.QueryBuilder;
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+@SuppressWarnings("all")
+public class FetchNodesByPathAndDepthQueryTest extends BaseMongoTest {
+
+    @Test
+    @Ignore
+    public void testFetchWithInvalidFirstRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+        SimpleNodeScenario scenario2 = new SimpleNodeScenario(mongoConnection);
+        String thirdRevisionId = scenario.update_A_and_add_D_and_E();
+
+        DBCollection commitCollection = mongoConnection.getCommitCollection();
+        DBObject q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID)
+                .is(MongoUtil.toMongoRepresentation(firstRevisionId)).get();
+        DBObject u = new BasicDBObject("$set", new BasicDBObject(CommitMongo.KEY_FAILED, Boolean.TRUE));
+        commitCollection.update(q, u);
+
+        q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID).is(MongoUtil.toMongoRepresentation(secondRevisionId))
+                .get();
+        u = new BasicDBObject("$set", new BasicDBObject(CommitMongo.KEY_BASE_REVISION_ID, 0L));
+        commitCollection.update(q, u);
+
+        FetchNodesByPathAndDepthQuery query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", thirdRevisionId,
+                -1);
+        List<NodeMongo> result = query.execute();
+        List<Node> actuals = NodeMongo.toNode(result);
+        Node expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%0$s\" : { \"a#%3$s\" : { \"int\" : 1 , \"double\" : 0.123 , \"b#%3$s\" : { \"string\" : \"foo\" , \"e#%3$s\" : { \"array\" : [ 123, null, 123.456, \"for:bar\", true ] } } , \"d#%3$s\" : { \"null\" : null } } } }",
+                                firstRevisionId, secondRevisionId,
+                                thirdRevisionId));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void testFetchWithInvalidLastRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+        SimpleNodeScenario scenario2 = new SimpleNodeScenario(mongoConnection);
+        String thirdRevisionId = scenario.update_A_and_add_D_and_E();
+
+        DBCollection commitCollection = mongoConnection.getCommitCollection();
+        DBObject q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID)
+                .is(MongoUtil.toMongoRepresentation(thirdRevisionId)).get();
+        DBObject u = new BasicDBObject();
+        u.put("$set", new BasicDBObject(CommitMongo.KEY_FAILED, Boolean.TRUE));
+        commitCollection.update(q, u);
+
+        FetchNodesByPathAndDepthQuery query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", thirdRevisionId,
+                -1);
+        List<NodeMongo> result = query.execute();
+        List<Node> actuals = NodeMongo.toNode(result);
+        Node 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));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void testFetchWithInvalidMiddleRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+        SimpleNodeScenario scenario2 = new SimpleNodeScenario(mongoConnection);
+        String thirdRevisionId = scenario.update_A_and_add_D_and_E();
+
+        DBCollection commitCollection = mongoConnection.getCommitCollection();
+        DBObject q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID)
+                .is(MongoUtil.toMongoRepresentation(secondRevisionId)).get();
+        DBObject u = new BasicDBObject("$set", new BasicDBObject(CommitMongo.KEY_FAILED, Boolean.TRUE));
+        commitCollection.update(q, u);
+
+        q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID).is(MongoUtil.toMongoRepresentation(thirdRevisionId))
+                .get();
+        u = new BasicDBObject();
+        u.put("$set",
+                new BasicDBObject(CommitMongo.KEY_BASE_REVISION_ID, MongoUtil
+                        .toMongoRepresentation(firstRevisionId)));
+        commitCollection.update(q, u);
+
+        FetchNodesByPathAndDepthQuery query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", thirdRevisionId,
+                -1);
+        List<NodeMongo> result = query.execute();
+        List<Node> actuals = NodeMongo.toNode(result);
+        Node expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%3$s\" : { \"int\" : 1 , \"double\" : 0.123 , \"b#%3$s\" : { \"string\" : \"foo\" , \"e#%3$s\" : { \"array\" : [ 123, null, 123.456, \"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%3$s\" : { \"null\" : null } } } }",
+                                firstRevisionId, secondRevisionId,
+                                thirdRevisionId));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void testSimpleFetchRootAndAllDepths() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+
+        FetchNodesByPathAndDepthQuery query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId,
+                0);
+        List<NodeMongo> result = query.execute();
+        List<Node> actuals = NodeMongo.toNode(result);
+        Node expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : {} }", firstRevisionId));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, 0);
+        result = query.execute();
+        actuals = NodeMongo.toNode(result);
+        expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : {} }", firstRevisionId));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId, 1);
+        result = query.execute();
+        actuals = NodeMongo.toNode(result);
+        expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 } } }",
+                firstRevisionId));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, 1);
+        result = query.execute();
+        actuals = NodeMongo.toNode(result);
+        expected = NodeBuilder.build(String.format(
+                "{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" : 0.123 } } }", firstRevisionId,
+                secondRevisionId));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId, 2);
+        result = query.execute();
+        actuals = NodeMongo.toNode(result);
+        expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1, \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                                firstRevisionId));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, 2);
+        result = query.execute();
+        actuals = NodeMongo.toNode(result);
+        expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" : 0.123 , \"b#%2$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true }, \"d#%2$s\" : { \"null\" : null } } } }",
+                                firstRevisionId, secondRevisionId));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", firstRevisionId, -1);
+        result = query.execute();
+        actuals = NodeMongo.toNode(result);
+        expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                                firstRevisionId));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesByPathAndDepthQuery(mongoConnection, "/", secondRevisionId, -1);
+        result = query.execute();
+        actuals = NodeMongo.toNode(result);
+        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));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesByPathAndDepthQueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesForRevisionQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesForRevisionQueryTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesForRevisionQueryTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesForRevisionQueryTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,188 @@
+/*
+ * 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.query;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+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.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.QueryBuilder;
+
+/**
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+@SuppressWarnings("all")
+public class FetchNodesForRevisionQueryTest extends BaseMongoTest {
+
+    @Test
+    @Ignore
+    public void testFetchWithInvalidFirstRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+        SimpleNodeScenario scenario2 = new SimpleNodeScenario(mongoConnection);
+        String thirdRevisionId = scenario.update_A_and_add_D_and_E();
+
+        DBCollection commitCollection = mongoConnection.getCommitCollection();
+        DBObject q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID)
+                .is(MongoUtil.toMongoRepresentation(secondRevisionId)).get();
+        DBObject u = new BasicDBObject();
+        u.put("$set", new BasicDBObject(CommitMongo.KEY_FAILED, Boolean.TRUE));
+        commitCollection.update(q, u);
+
+        FetchNodesForRevisionQuery query = new FetchNodesForRevisionQuery(mongoConnection, new String[] { "/", "/a",
+                "/a/b", "/a/c", "/a/d", "/a/b/e", "not_existing" }, thirdRevisionId);
+        List<NodeMongo> nodeMongos = query.execute();
+        List<Node> actuals = NodeMongo.toNode(nodeMongos);
+        Node expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%3$s\" : { \"int\" : 1 , \"double\" : 0.123 , \"b#%3$s\" : { \"string\" : \"foo\" , \"e#%3$s\" : { \"array\" : [ 123, null, 123.456, \"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%3$s\" : { \"null\" : null } } } }",
+                                firstRevisionId, secondRevisionId,
+                                thirdRevisionId));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void testFetchWithInvalidLastRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+        SimpleNodeScenario scenario2 = new SimpleNodeScenario(mongoConnection);
+        String thirdRevisionId = scenario.update_A_and_add_D_and_E();
+
+        DBCollection commitCollection = mongoConnection.getCommitCollection();
+        DBObject q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID)
+                .is(MongoUtil.toMongoRepresentation(thirdRevisionId)).get();
+        DBObject u = new BasicDBObject();
+        u.put("$set", new BasicDBObject(CommitMongo.KEY_FAILED, Boolean.TRUE));
+        commitCollection.update(q, u);
+
+        FetchNodesForRevisionQuery query = new FetchNodesForRevisionQuery(mongoConnection, new String[] { "/", "/a",
+                "/a/b", "/a/c", "/a/d", "/a/b/e", "not_existing" }, thirdRevisionId);
+        List<NodeMongo> nodeMongos = query.execute();
+        List<Node> actuals = NodeMongo.toNode(nodeMongos);
+        Node 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));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void testFetchWithInvalidMiddleRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+        SimpleNodeScenario scenario2 = new SimpleNodeScenario(mongoConnection);
+        String thirdRevisionId = scenario.update_A_and_add_D_and_E();
+
+        DBCollection commitCollection = mongoConnection.getCommitCollection();
+        DBObject q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID)
+                .is(MongoUtil.toMongoRepresentation(secondRevisionId)).get();
+        DBObject u = new BasicDBObject("$set", new BasicDBObject(CommitMongo.KEY_FAILED, Boolean.TRUE));
+        commitCollection.update(q, u);
+
+        q = QueryBuilder.start(CommitMongo.KEY_REVISION_ID).is(MongoUtil.toMongoRepresentation(thirdRevisionId))
+                .get();
+        u = new BasicDBObject();
+        u.put("$set",
+                new BasicDBObject(CommitMongo.KEY_BASE_REVISION_ID, MongoUtil
+                        .toMongoRepresentation(firstRevisionId)));
+        commitCollection.update(q, u);
+
+        FetchNodesForRevisionQuery query = new FetchNodesForRevisionQuery(mongoConnection, new String[] { "/", "/a",
+                "/a/b", "/a/c", "/a/d", "/a/b/e", "not_existing" }, thirdRevisionId);
+        List<NodeMongo> nodeMongos = query.execute();
+        List<Node> actuals = NodeMongo.toNode(nodeMongos);
+        Node expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%3$s\" : { \"int\" : 1 , \"double\" : 0.123 , \"b#%3$s\" : { \"string\" : \"foo\" , \"e#%3$s\" : { \"array\" : [ 123, null, 123.456, \"for:bar\", true ] } } , \"c#%1$s\" : { \"bool\" : true }, \"d#%3$s\" : { \"null\" : null } } } }",
+                                firstRevisionId, secondRevisionId,
+                                thirdRevisionId));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void testFetchWithOneRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String revisionId = scenario.create();
+
+        FetchNodesForRevisionQuery query = new FetchNodesForRevisionQuery(mongoConnection, new String[] { "/", "/a",
+                "/a/b", "/a/c", "not_existing" }, revisionId);
+        List<NodeMongo> nodeMongos = query.execute();
+        List<Node> actuals = NodeMongo.toNode(nodeMongos);
+        Node expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                                revisionId));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesForRevisionQuery(mongoConnection, new String[] { "/", "/a", "not_existing" }, revisionId);
+        nodeMongos = query.execute();
+        actuals = NodeMongo.toNode(nodeMongos);
+        expected = NodeBuilder.build(String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 } } }",
+                revisionId));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void testFetchWithTwoRevisions() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        String firstRevisionId = scenario.create();
+        String secondRevisionId = scenario.update_A_and_add_D_and_E();
+
+        FetchNodesForRevisionQuery query = new FetchNodesForRevisionQuery(mongoConnection, new String[] { "/", "/a",
+                "/a/b", "/a/c", "/a/d", "/a/b/e", "not_existing" }, firstRevisionId);
+        List<NodeMongo> nodeMongos = query.execute();
+        List<Node> actuals = NodeMongo.toNode(nodeMongos);
+        Node expected = NodeBuilder
+                .build(String
+                        .format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                                firstRevisionId));
+        Set<Node> expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesForRevisionQuery(mongoConnection, new String[] { "/", "/a", "/a/b", "/a/c", "/a/d",
+                "/a/b/e", "not_existing" }, secondRevisionId);
+        nodeMongos = query.execute();
+        actuals = NodeMongo.toNode(nodeMongos);
+        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));
+        expecteds = expected.getDescendants(true);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchNodesForRevisionQueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQueryTest.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQueryTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQueryTest.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,125 @@
+/*
+ * 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.query;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.jackrabbit.mongomk.BaseMongoTest;
+import org.apache.jackrabbit.mongomk.model.CommitMongo;
+import org.apache.jackrabbit.mongomk.query.FetchValidCommitsQuery;
+import org.apache.jackrabbit.mongomk.scenario.SimpleNodeScenario;
+import org.junit.Test;
+
+
+public class FetchValidCommitsQueryTest extends BaseMongoTest {
+
+    private static final int MIN_COMMITS = 1;
+    private static final int SIMPLE_SCENARIO_COMMITS = MIN_COMMITS + 1;
+
+    @Test
+    public void simple() throws Exception {
+        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection,
+                String.valueOf(Integer.MAX_VALUE) /*maxRevisionId*/);
+        List<CommitMongo> commits = query.execute();
+        assertEquals(MIN_COMMITS, commits.size());
+
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        scenario.create();
+        commits = query.execute();
+        assertEquals(SIMPLE_SCENARIO_COMMITS, commits.size());
+
+        int numberOfChildren = 3;
+        scenario.addChildrenToA(numberOfChildren);
+        commits = query.execute();
+        assertEquals(SIMPLE_SCENARIO_COMMITS + numberOfChildren, commits.size());
+    }
+
+    @Test
+    public void revisionId() throws Exception {
+        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection,
+                String.valueOf(Integer.MAX_VALUE) /*maxRevisionId*/);
+        List<CommitMongo> commits = query.execute();
+        CommitMongo commit0 = commits.get(0);
+
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        scenario.create();
+        commits = query.execute();
+        CommitMongo commit1 = commits.get(0);
+        assertTrue(commit0.getRevisionId() < commit1.getRevisionId());
+
+        int numberOfChildren = 3;
+        scenario.addChildrenToA(numberOfChildren);
+        commits = query.execute();
+        CommitMongo commit2 = commits.get(0);
+        assertTrue(commit1.getRevisionId() < commit2.getRevisionId());
+    }
+
+    @Test
+    public void time() throws Exception {
+        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection,
+                String.valueOf(Integer.MAX_VALUE) /*maxRevisionId*/);
+        List<CommitMongo> commits = query.execute();
+        CommitMongo commit0 = commits.get(0);
+
+        Thread.sleep(1000);
+
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        scenario.create();
+        commits = query.execute();
+        CommitMongo commit1 = commits.get(0);
+        assertTrue(commit0.getTimestamp() < commit1.getTimestamp());
+
+        Thread.sleep(1000);
+
+        int numberOfChildren = 3;
+        scenario.addChildrenToA(numberOfChildren);
+        commits = query.execute();
+        CommitMongo commit2 = commits.get(0);
+        assertTrue(commit1.getTimestamp() < commit2.getTimestamp());
+    }
+
+    @Test
+    public void maxEntriesDefaultLimitless() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        scenario.create();
+
+        int numberOfChildren = 2;
+        scenario.addChildrenToA(numberOfChildren);
+
+        int maxEntries = 0;
+        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection, maxEntries);
+        List<CommitMongo> commits = query.execute();
+        assertEquals(SIMPLE_SCENARIO_COMMITS + numberOfChildren, commits.size());
+    }
+
+    @Test
+    public void maxEntries() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        scenario.create();
+
+        int numberOfChildren = 2;
+        scenario.addChildrenToA(numberOfChildren);
+
+        int maxEntries = 2;
+        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection, maxEntries);
+        List<CommitMongo> commits = query.execute();
+        assertEquals(maxEntries, commits.size());
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java Mon Sep 17 12:54:01 2012
@@ -0,0 +1,147 @@
+/*
+ * 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.scenario;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jackrabbit.mongomk.MongoConnection;
+import org.apache.jackrabbit.mongomk.api.model.Commit;
+import org.apache.jackrabbit.mongomk.api.model.Instruction;
+import org.apache.jackrabbit.mongomk.command.CommitCommandMongo;
+import org.apache.jackrabbit.mongomk.impl.model.AddNodeInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.model.AddPropertyInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.model.CommitImpl;
+import org.apache.jackrabbit.mongomk.impl.model.RemoveNodeInstructionImpl;
+
+/**
+ * Creates a defined scenario in {@code MongoDB}.
+ *
+ * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ */
+public class SimpleNodeScenario { // TODO this should be refactored to use class rules
+
+    private final MongoConnection mongoConnection;
+
+    /**
+     * Constructs a new {@code SimpleNodeScenario}.
+     *
+     * @param mongoConnection
+     *            The {@link MongoConnection}.
+     */
+    public SimpleNodeScenario(MongoConnection mongoConnection) {
+        this.mongoConnection = mongoConnection;
+    }
+
+    /**
+     * Creates the following nodes:
+     *
+     * <pre>
+     * &quot;+a : { \&quot;int\&quot; : 1 , \&quot;b\&quot; : { \&quot;string\&quot; : \&quot;foo\&quot; } , \&quot;c\&quot; : { \&quot;bool\&quot; : true } } }&quot;
+     * </pre>
+     *
+     * @return The {@link RevisionId}.
+     * @throws Exception
+     *             If an error occurred.
+     */
+    public String create() throws Exception {
+        List<Instruction> instructions = new LinkedList<Instruction>();
+        instructions.add(new AddNodeInstructionImpl("/", "a"));
+        instructions.add(new AddNodeInstructionImpl("/a", "b"));
+        instructions.add(new AddNodeInstructionImpl("/a", "c"));
+        instructions.add(new AddPropertyInstructionImpl("/a", "int", 1));
+        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);
+        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
+        String revisionId = command.execute();
+
+        return revisionId;
+    }
+
+    public String addChildrenToA(int count) throws Exception {
+        String revisionId = null;
+        for (int i = 1; i <= count; i++) {
+            List<Instruction> instructions = new LinkedList<Instruction>();
+            instructions.add(new AddNodeInstructionImpl("/a", "child" + i));
+            Commit commit = new CommitImpl("Add child" + i, "/a", "TODO", instructions);
+            CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
+            revisionId = command.execute();
+        }
+        return revisionId;
+    }
+
+    /**
+     * Deletes the a node.
+     *
+     * <pre>
+     * &quot;-a&quot;
+     * </pre>
+     *
+     * @return The {@link RevisionId}.
+     * @throws Exception
+     *             If an error occurred.
+     */
+    public String delete_A() throws Exception {
+        List<Instruction> instructions = new LinkedList<Instruction>();
+        instructions.add(new RemoveNodeInstructionImpl("/", "a"));
+
+        Commit commit = new CommitImpl("This is a commit with deleted /a", "/", "-a", instructions);
+        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
+        String revisionId = command.execute();
+
+        return revisionId;
+    }
+
+    public String delete_B() throws Exception {
+        List<Instruction> instructions = new LinkedList<Instruction>();
+        instructions.add(new RemoveNodeInstructionImpl("/a", "b"));
+        Commit commit = new CommitImpl("This is a commit with deleted /a/b", "/a", "-b", instructions);
+        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
+        return command.execute();
+    }
+
+    /**
+     * Updates the following nodes:
+     *
+     * <pre>
+     * TBD
+     * </pre>
+     *
+     * @return The {@link RevisionId}.
+     * @throws Exception
+     *             If an error occurred.
+     */
+    public String update_A_and_add_D_and_E() throws Exception {
+        List<Instruction> instructions = new LinkedList<Instruction>();
+        instructions.add(new AddNodeInstructionImpl("/a", "d"));
+        instructions.add(new AddNodeInstructionImpl("/a/b", "e"));
+        instructions.add(new AddPropertyInstructionImpl("/a", "double", 0.123D));
+        instructions.add(new AddPropertyInstructionImpl("/a/d", "null", null));
+        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",
+                instructions);
+        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
+        String revisionId = command.execute();
+
+        return revisionId;
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/resources/config.cfg
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/resources/config.cfg?rev=1386591&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/resources/config.cfg (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/resources/config.cfg Mon Sep 17 12:54:01 2012
@@ -0,0 +1,28 @@
+# 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.
+
+# This file contains configuration properties for the MongoDB related services. These properties are
+# required for the SharedCloud MicroKernel integration tests.
+#
+# Please be cautious with any blanklines and whitespaces!
+
+# The host of the running mongodb or mongos process
+host = 127.0.0.1
+
+# The port of the running mongodb or mongos process
+port = 27017
+
+# The database to use
+db = MongoMicroKernelTest
\ No newline at end of file

Modified: jackrabbit/oak/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/pom.xml?rev=1386591&r1=1386590&r2=1386591&view=diff
==============================================================================
--- jackrabbit/oak/trunk/pom.xml (original)
+++ jackrabbit/oak/trunk/pom.xml Mon Sep 17 12:54:01 2012
@@ -88,6 +88,16 @@
 
   <profiles>
     <profile>
+      <id>mongomk</id>
+      <modules>
+        <module>oak-mongomk-api</module>
+        <module>oak-mongomk-impl</module>
+        <module>oak-mongomk</module>
+        <module>oak-mongomk-test</module>
+        <module>oak-mongomk-perf</module>
+      </modules>
+    </profile>
+    <profile>
       <id>apache-release</id>
       <properties>
         <apache.username>${user.name}</apache.username>



Mime
View raw message