jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1407119 [8/9] - in /jackrabbit/oak/trunk: ./ oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/ oak-mk-perf/ oak-mk-perf/src/main/java/org/apache/jackrabbit/mk/tasks/ oak-...
Date Thu, 08 Nov 2012 15:18:02 GMT
Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKNodeExistsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKNodeExistsTest.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKNodeExistsTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKNodeExistsTest.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,135 @@
+/*
+ * 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.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.junit.Test;
+
+/**
+ * Tests for {@code MongoMicroKernel#nodeExists(String, String)}
+ */
+public class MongoMKNodeExistsTest extends BaseMongoMicroKernelTest {
+
+    @Test
+    public void simple() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mk);
+        String revisionId = scenario.create();
+
+        boolean exists = mk.nodeExists("/a", revisionId);
+        assertTrue(exists);
+
+        exists = mk.nodeExists("/a/b", revisionId);
+        assertTrue(exists);
+
+        revisionId = scenario.delete_A();
+
+        exists = mk.nodeExists("/a", revisionId);
+        assertFalse(exists);
+
+        exists = mk.nodeExists("/a/b", revisionId);
+        assertFalse(exists);
+    }
+
+    @Test
+    public void withoutRevisionId() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mk);
+        scenario.create();
+
+        boolean exists = mk.nodeExists("/a", null);
+        assertTrue(exists);
+
+        scenario.delete_A();
+
+        exists = mk.nodeExists("/a", null);
+        assertFalse(exists);
+    }
+
+    @Test
+    public void withInvalidRevisionId() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mk);
+        scenario.create();
+
+        try {
+            mk.nodeExists("/a", "123456789");
+            fail("Expected: Invalid revision id exception");
+        } catch (Exception expected) {
+        }
+    }
+
+    @Test
+    public void parentDelete() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mk);
+        scenario.create();
+
+        boolean exists = mk.nodeExists("/a/b", null);
+        assertTrue(exists);
+
+        scenario.delete_A();
+        exists = mk.nodeExists("/a/b", null);
+        assertFalse(exists);
+    }
+
+    @Test
+    public void grandParentDelete() throws Exception {
+        mk.commit("/", "+\"a\" : { \"b\" : { \"c\" : { \"d\" : {} } } }", null,
+                "Add /a/b/c/d");
+
+        mk.commit("/a", "-\"b\"", null, "Remove /b");
+
+        boolean exists = mk.nodeExists("/a/b/c/d", null);
+        assertFalse(exists);
+    }
+
+    @Test
+    public void existsInHeadRevision() throws Exception {
+        mk.commit("/", "+\"a\" : {}", null, "Add /a");
+        mk.commit("/a", "+\"b\" : {}", null, "Add /a/b");
+
+        boolean exists = mk.nodeExists("/a", null);
+        assertTrue("The node a is not found in the head revision!", exists);
+    }
+
+    @Test
+    public void existsInOldRevNotInNewRev() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mk);
+        String rev1 = scenario.create();
+        String rev2 = scenario.delete_A();
+
+        boolean exists = mk.nodeExists("/a", rev1);
+        assertTrue(exists);
+
+        exists = mk.nodeExists("/a", rev2);
+        assertFalse(exists);
+    }
+
+    @Test
+    public void siblingDelete() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mk);
+        scenario.create();
+
+        scenario.delete_B();
+        boolean exists = mk.nodeExists("/a/b", null);
+        assertFalse(exists);
+
+        exists = mk.nodeExists("/a/c", null);
+        assertTrue(exists);
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKNodeExistsTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadGridFSTest.java (from r1407101, 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/impl/MongoMKReadGridFSTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadGridFSTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ReadBlobCommandMongoTest.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ReadBlobCommandMongoTest.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadGridFSTest.java Thu Nov  8 15:17:50 2012
@@ -14,73 +14,70 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.command;
+package org.apache.jackrabbit.mongomk.impl;
 
 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.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
 import org.junit.Test;
 
-import com.mongodb.gridfs.GridFS;
-import com.mongodb.gridfs.GridFSInputFile;
-
-public class ReadBlobCommandMongoTest extends BaseMongoTest {
+/**
+ * Tests for {@code MongoMicroKernel#read(String, long, byte[], int, int)}
+ */
+public class MongoMKReadGridFSTest extends BaseMongoMicroKernelTest {
 
     private byte[] blob;
     private String blobId;
 
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
+    @Test
+    public void small() throws Exception {
+        read(1024);
+    }
 
-        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 medium() throws Exception {
+        read(1024 * 1024);
     }
 
     @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();
+    public void large() throws Exception {
+        read(20 * 1024 * 1024);
+    }
 
+    private void read(int blobLength) throws Exception {
+        createAndWriteBlob(blobLength);
+
+        // Complete read.
+        byte[] buffer = new byte[blob.length];
+        int totalBytes = mk.read(blobId, 0, buffer, 0, blob.length);
         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();
 
+        // Range end from end.
+        buffer = new byte[blob.length / 2];
+        totalBytes = mk.read(blobId, (blob.length / 2) - 1, buffer, 0, blob.length / 2);
         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();
 
+        // Range from start.
+        buffer = new byte[blob.length / 2];
+        totalBytes = mk.read(blobId, 0, buffer, 0, blob.length / 2);
         Assert.assertEquals(blob.length / 2, totalBytes);
         for (int i = 0; i < buffer.length; i++) {
             Assert.assertEquals(blob[i], buffer[i]);
         }
     }
-}
+
+    private void createAndWriteBlob(int blobLength) throws Exception {
+        blob = new byte[blobLength];
+        for (int i = 0; i < blob.length; i++) {
+            blob[i] = (byte)i;
+        }
+        blobId = mk.write(new ByteArrayInputStream(blob));
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadGridFSTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadTest.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadTest.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,102 @@
+/*
+ * 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.impl;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+
+import junit.framework.Assert;
+
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.impl.blob.MongoBlobStore;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.mongodb.DB;
+
+/**
+ * Tests for {@code MongoMicroKernel#read(String, long, byte[], int, int)}
+ */
+public class MongoMKReadTest extends BaseMongoMicroKernelTest {
+
+    private byte[] blob;
+    private String blobId;
+
+    // Override to set the right blob store.
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        DB db = mongoConnection.getDB();
+        dropCollections(db);
+
+        MongoNodeStore nodeStore = new MongoNodeStore(db);
+        BlobStore blobStore = new MongoBlobStore(db);
+        mk = new MongoMicroKernel(mongoConnection, nodeStore, blobStore);
+    }
+
+    @Test
+    public void small() throws Exception {
+        read(1024);
+    }
+
+    @Test
+    public void medium() throws Exception {
+        read(1024 * 1024);
+    }
+
+    @Test
+    @Ignore // FIXME - Add it back when OAK-430 is fixed.
+    public void large() throws Exception {
+        read(20 * 1024 * 1024);
+    }
+
+    private void read(int blobLength) throws Exception {
+        createAndWriteBlob(blobLength);
+
+        // Complete read.
+        byte[] buffer = new byte[blob.length];
+        int totalBytes = mk.read(blobId, 0, buffer, 0, blob.length);
+        Assert.assertEquals(blob.length, totalBytes);
+        Assert.assertTrue(Arrays.equals(blob, buffer));
+
+        // Range end from end.
+        buffer = new byte[blob.length / 2];
+        totalBytes = mk.read(blobId, (blob.length / 2) - 1, buffer, 0, blob.length / 2);
+        Assert.assertEquals(blob.length / 2, totalBytes);
+        for (int i = 0; i < buffer.length; i++) {
+            Assert.assertEquals(blob[((blob.length / 2) - 1) + i], buffer[i]);
+        }
+
+        // Range from start.
+        buffer = new byte[blob.length / 2];
+        totalBytes = mk.read(blobId, 0, buffer, 0, blob.length / 2);
+        Assert.assertEquals(blob.length / 2, totalBytes);
+        for (int i = 0; i < buffer.length; i++) {
+            Assert.assertEquals(blob[i], buffer[i]);
+        }
+    }
+
+    private void createAndWriteBlob(int blobLength) throws Exception {
+        blob = new byte[blobLength];
+        for (int i = 0; i < blob.length; i++) {
+            blob[i] = (byte)1;
+        }
+        blobId = mk.write(new ByteArrayInputStream(blob));
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKReadTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,122 @@
+package org.apache.jackrabbit.mongomk.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.api.NodeStore;
+import org.apache.jackrabbit.mongomk.impl.blob.MongoGridFSBlobStore;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.mongodb.DB;
+
+/**
+ * Tests for {@code MongoMicroKernel#waitForCommit(String, long)}
+ */
+public class MongoMKWaitForCommitTest extends BaseMongoMicroKernelTest {
+
+    private MicroKernel mk2;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        DB db = mongoConnection.getDB();
+        NodeStore nodeStore = new MongoNodeStore(db);
+        BlobStore blobStore = new MongoGridFSBlobStore(db);
+        mk2 = new MongoMicroKernel(mongoConnection, nodeStore, blobStore);
+    }
+
+    @Test
+    public void timeoutNonPositiveNoCommit() throws Exception {
+        String headRev = mk.commit("/", "+\"a\" : {}", null, null);
+        long before = System.currentTimeMillis();
+        String rev = mk2.waitForCommit(null, -1);
+        long after = System.currentTimeMillis();
+        assertEquals(headRev, rev);
+        assertTrue(after - before < 100); // Basically no wait.
+    }
+
+    @Test
+    public void timeoutNoCommit() throws Exception {
+        int timeout = 500;
+        String headRev = mk.commit("/", "+\"a\" : {}", null, null);
+        long before = System.currentTimeMillis();
+        String rev = mk2.waitForCommit(headRev, timeout);
+        long after = System.currentTimeMillis();
+        assertEquals(headRev, rev);
+        assertTrue(after - before >= timeout);
+    }
+
+    @Test
+    public void timeoutWithCommit1() throws Exception {
+        String headRev = mk.commit("/", "+\"a\" : {}", null, null);
+        ScheduledFuture<String> future = scheduleCommit(1000, null);
+        int timeout = 500;
+        long before = System.currentTimeMillis();
+        String rev = mk2.waitForCommit(headRev, timeout);
+        long after = System.currentTimeMillis();
+        headRev = future.get();
+        assertFalse(headRev.equals(rev));
+        assertTrue(after - before >= timeout);
+    }
+
+    @Test
+    public void timeoutWithCommit2() throws Exception {
+        String headRev = mk.commit("/", "+\"a\" : {}", null, null);
+        ScheduledFuture<String> future = scheduleCommit(500, null);
+        int timeout = 2000;
+        long before = System.currentTimeMillis();
+        String rev = mk2.waitForCommit(headRev, timeout);
+        long after = System.currentTimeMillis();
+        headRev = future.get();
+        assertTrue(headRev.equals(rev));
+        assertTrue(after - before < timeout);
+    }
+
+    @Test
+    public void branchIgnored() throws Exception {
+        String headRev = mk.commit("/", "+\"a\" : {}", null, null);
+        String branchRev = mk.branch(headRev);
+        ScheduledFuture<String> future = scheduleCommit(500, branchRev);
+        int timeout = 2000;
+        long before = System.currentTimeMillis();
+        String rev = mk2.waitForCommit(headRev, timeout);
+        long after = System.currentTimeMillis();
+        headRev = future.get();
+        assertFalse(headRev.equals(rev));
+        assertTrue(after - before >= timeout);
+    }
+
+    @Test
+    public void nullOldHeadRevisionId() throws Exception {
+        String headRev = mk.commit("/", "+\"a\" : {}", null, null);
+        long before = System.currentTimeMillis();
+        String rev = mk2.waitForCommit(null, 500);
+        long after = System.currentTimeMillis();
+        assertEquals(headRev, rev);
+        assertEquals(headRev, rev);
+        assertTrue(after - before < 10); // Basically no wait.
+    }
+
+    private ScheduledFuture<String> scheduleCommit(long delay, final String revisionId) {
+        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+        ScheduledFuture<String> future = executorService.schedule(new Callable<String>(){
+            @Override
+            public String call() throws Exception {
+                return mk.commit("/", "+\"b\" : {}", revisionId, null);
+            }
+        }, delay, TimeUnit.MILLISECONDS);
+        executorService.shutdown();
+        return future;
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteGridFSTest.java (from r1407101, 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/impl/MongoMKWriteGridFSTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteGridFSTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/WriteBlobCommandMongoTest.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/WriteBlobCommandMongoTest.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteGridFSTest.java Thu Nov  8 15:17:50 2012
@@ -14,38 +14,49 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.command;
+package org.apache.jackrabbit.mongomk.impl;
 
 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.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
 import org.junit.Test;
 
-import com.mongodb.BasicDBObject;
-import com.mongodb.gridfs.GridFS;
-import com.mongodb.gridfs.GridFSDBFile;
+/**
+ * Tests for {@code MongoMicroKernel#write(java.io.InputStream)}
+ */
+public class MongoMKWriteGridFSTest extends BaseMongoMicroKernelTest {
 
-public class WriteBlobCommandMongoTest extends BaseMongoTest {
+    @Test
+    public void small() throws Exception {
+        write(1024);
+    }
 
     @Test
-    public void testWriteBlobComplete() throws Exception {
-        int blobLength = 100;
-        byte[] blob = createBlob(blobLength);
+    public void medium() throws Exception {
+        write(1024 * 1024);
+    }
 
-        WriteBlobCommandMongo command = new WriteBlobCommandMongo(mongoConnection,
-                new ByteArrayInputStream(blob));
-        String blobId = command.execute();
+    @Test
+    public void large() throws Exception {
+        write(20 * 1024 * 1024);
+    }
+
+    private void write(int blobLength) throws Exception {
+        byte[] blob = createBlob(blobLength);
+        String blobId = mk.write(new ByteArrayInputStream(blob));
         assertNotNull(blobId);
 
         byte[] readBlob = new byte[blobLength];
-        readBlob(blobId, readBlob);
+        mk.read(blobId, 0, readBlob, 0, readBlob.length);
+        for (int i = 0; i < blob.length; i++) {
+            if (blob[i] != readBlob[i]) {
+                System.out.println(i + " " + blob[i] + "==>" + readBlob[i]);
+            }
+        }
         assertTrue(Arrays.equals(blob, readBlob));
     }
 
@@ -56,10 +67,4 @@ public class WriteBlobCommandMongoTest e
         }
         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);
-    }
-}
+}
\ No newline at end of file

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteGridFSTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteTest.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteTest.java Thu Nov  8 15:17:50 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.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.MongoAssert;
+import org.apache.jackrabbit.mongomk.impl.blob.MongoBlobStore;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.mongodb.DB;
+
+/**
+ * Tests for {@code MongoMicroKernel#write(java.io.InputStream)}
+ */
+public class MongoMKWriteTest extends BaseMongoMicroKernelTest {
+
+    // Override to set the right blob store.
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        DB db = mongoConnection.getDB();
+        dropCollections(db);
+
+        MongoNodeStore nodeStore = new MongoNodeStore(db);
+        MongoAssert.setNodeStore(nodeStore);
+        BlobStore blobStore = new MongoBlobStore(db);
+        mk = new MongoMicroKernel(mongoConnection, nodeStore, blobStore);
+    }
+
+    @Test
+    public void small() throws Exception {
+        write(1024);
+    }
+
+    @Test
+    public void medium() throws Exception {
+        write(1024 * 1024);
+    }
+
+    @Test
+    @Ignore // FIXME - Add it back when OAK-430 is fixed.
+    public void large() throws Exception {
+        write(20 * 1024 * 1024);
+    }
+
+    private void write(int blobLength) throws Exception {
+        byte[] blob = createBlob(blobLength);
+        String blobId = mk.write(new ByteArrayInputStream(blob));
+        assertNotNull(blobId);
+
+        byte[] readBlob = new byte[blobLength];
+        mk.read(blobId, 0, readBlob, 0, readBlob.length);
+        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;
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWriteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/NodeAssert.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/NodeAssert.java?rev=1407119&r1=1407118&r2=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/NodeAssert.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/NodeAssert.java Thu Nov  8 15:17:50 2012
@@ -17,45 +17,54 @@
 package org.apache.jackrabbit.mongomk.impl;
 
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
-
-import org.apache.jackrabbit.mongomk.api.model.Node;
 
 import junit.framework.Assert;
 
+import org.apache.jackrabbit.mongomk.api.model.Node;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 
-/**
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
- */
-@SuppressWarnings("javadoc")
 public class NodeAssert {
 
     public static void assertDeepEquals(Node expected, Node actual) {
         assertEquals(expected, actual);
 
-        Set<Node> expectedChildren = expected.getChildren();
-        Set<Node> actualChildren = actual.getChildren();
+        int expectedCount = expected.getChildNodeCount();
+        int actualCount = actual.getChildNodeCount();
+        Assert.assertEquals(expectedCount, actualCount);
+
+        for (Iterator<Node> it = expected.getChildNodeEntries(0, -1); it.hasNext(); ) {
+            Node expectedChild = it.next();
+            String expectedChildName = PathUtils.getName(expectedChild.getPath());
+            boolean valid = false;
+            for (Iterator<Node> it2 = actual.getChildNodeEntries(0, -1); it2.hasNext(); ) {
+                Node actualChild = it2.next();
+                String actualChildName = PathUtils.getName(actualChild.getPath());
+                if (expectedChildName.equals(actualChildName)) {
+                    assertDeepEquals(expectedChild, actualChild);
+                    valid = true;
+                    break;
+                }
+            }
 
-        if (expectedChildren == null) {
-            Assert.assertNull(actualChildren);
-        } else {
-            Assert.assertNotNull(actualChildren);
-            Assert.assertEquals(expectedChildren.size(), actualChildren.size());
-
-            for (Node expectedChild : expectedChildren) {
-                boolean valid = false;
-                for (Node actualChild : actualChildren) {
-                    if (expectedChild.getName().equals(actualChild.getName())) {
-                        assertDeepEquals(expectedChild, actualChild);
-                        valid = true;
+            Assert.assertTrue(valid);
+        }
+    }
 
-                        break;
-                    }
+    public static void assertEquals(Iterator<Node> expecteds, Collection<Node> actuals) {
+        for (Iterator<Node> iter1 = expecteds; iter1.hasNext();) {
+            Node expected = iter1.next();
+            boolean valid = false;
+            for (Iterator<Node> iter2 = actuals.iterator(); iter2.hasNext();) {
+                Node actual = iter2.next();
+                if (expected.getPath().equals(actual.getPath())) {
+                    assertEquals(expected, actual);
+                    valid = true;
+                    break;
                 }
-
-                Assert.assertTrue(valid);
             }
+            Assert.assertTrue(valid);
         }
     }
 
@@ -78,7 +87,6 @@ public class NodeAssert {
     }
 
     public static void assertEquals(Node expected, Node actual) {
-        Assert.assertEquals(expected.getName(), actual.getName());
         Assert.assertEquals(expected.getPath(), actual.getPath());
 
         Long expectedRevisionId = expected.getRevisionId();
@@ -95,8 +103,8 @@ public class NodeAssert {
             Assert.assertEquals(expectedRevisionId, actualRevisionId);
         }
 
-        Map<String, Object> expectedProperties = expected.getProperties();
-        Map<String, Object> actualProperties = actual.getProperties();
+        Map<String, String> expectedProperties = expected.getProperties();
+        Map<String, String> actualProperties = actual.getProperties();
 
         if (expectedProperties == null) {
             Assert.assertNull(actualProperties);
@@ -110,8 +118,4 @@ public class NodeAssert {
             Assert.assertEquals(expectedProperties, actualProperties);
         }
     }
-
-    private NodeAssert() {
-        // no instantiation
-    }
 }

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/SimpleNodeScenario.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/SimpleNodeScenario.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/SimpleNodeScenario.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/SimpleNodeScenario.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,62 @@
+/*
+ * 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.impl;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+public class SimpleNodeScenario {
+
+    private final MicroKernel mk;
+
+    public SimpleNodeScenario(MicroKernel mk) {
+        this.mk = mk;
+    }
+
+    public String create() throws Exception {
+        return mk.commit("/",
+                "+\"a\" : { \"int\" : 1 , \"b\" : { \"string\" : \"foo\" } , \"c\" : { \"bool\" : true } }",
+                null,
+                "Simple node scenario with nodes /, /a, /a/b, /a/c");
+    }
+
+    public String addChildrenToA(int count) throws Exception {
+        String revisionId = null;
+        for (int i = 1; i <= count; i++) {
+            revisionId = mk.commit("/a", "+\"child" + i + "\" : {}", null, "Add child" + i);
+        }
+        return revisionId;
+    }
+
+    public String delete_A() throws Exception {
+        return mk.commit("/", "-\"a\"", null, "Commit with deleted /a");
+    }
+
+    public String delete_B() throws Exception {
+        return mk.commit("/a", "-\"b\"", null, "Commit with deleted /a/b");
+    }
+
+    public String update_A_and_add_D_and_E() throws Exception {
+        StringBuilder diff = new StringBuilder();
+        diff.append("+\"a/d\" : {}");
+        diff.append("+\"a/b/e\" : {}");
+        diff.append("^\"a/double\" : 0.123");
+        diff.append("^\"a/d/int\" :  2");
+        diff.append("^\"a/b/e/array\" : [ 123, null, 123.456, \"for:bar\", true ]");
+        return mk.commit("/", diff.toString(), null,
+                "Commit with updated /a and added /a/d and /a/b/e");
+    }
+}

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/SimpleNodeScenario.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,278 @@
+/*
+ * 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.impl.action;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.api.model.Commit;
+import org.apache.jackrabbit.mongomk.api.model.Node;
+import org.apache.jackrabbit.mongomk.impl.NodeAssert;
+import org.apache.jackrabbit.mongomk.impl.command.CommitCommand;
+import org.apache.jackrabbit.mongomk.impl.model.CommitBuilder;
+import org.apache.jackrabbit.mongomk.impl.model.MongoCommit;
+import org.apache.jackrabbit.mongomk.impl.model.MongoNode;
+import org.apache.jackrabbit.mongomk.util.NodeBuilder;
+import org.junit.Test;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.QueryBuilder;
+
+public class FetchNodesActionTest extends BaseMongoMicroKernelTest {
+
+    @Test
+    public void invalidFirstRevision() throws Exception {
+        Long revisionId1 = addNode("a");
+        Long revisionId2 = addNode("b");
+        Long revisionId3 = addNode("c");
+
+        invalidateCommit(revisionId1);
+        updateBaseRevisionId(revisionId2, 0L);
+
+        FetchNodesAction query = new FetchNodesAction(getNodeStore(),
+                "/", true, revisionId3);
+        List<Node> actuals = toNode(query.execute());
+
+        String json = String.format("{\"/#%2$s\" : { \"b#%1$s\" : {}, \"c#%2$s\" : {} }}",
+                revisionId2, revisionId3);
+        Iterator<Node> expecteds = NodeBuilder.build(json).getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void invalidLastRevision() throws Exception {
+        Long revisionId1 = addNode("a");
+        Long revisionId2 = addNode("b");
+        Long revisionId3 = addNode("c");
+
+        invalidateCommit(revisionId3);
+
+        FetchNodesAction query = new FetchNodesAction(getNodeStore(),
+                "/", true, revisionId3);
+        List<Node> actuals = toNode(query.execute());
+
+        String json = String.format("{\"/#%2$s\" : { \"a#%1$s\" : {}, \"b#%2$s\" : {} }}",
+                revisionId1, revisionId2);
+        Iterator<Node> expecteds = NodeBuilder.build(json).getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void invalidMiddleRevision() throws Exception {
+        Long revisionId1 = addNode("a");
+        Long revisionId2 = addNode("b");
+        Long revisionId3 = addNode("c");
+
+        invalidateCommit(revisionId2);
+        updateBaseRevisionId(revisionId3, revisionId1);
+
+        FetchNodesAction query = new FetchNodesAction(getNodeStore(),
+                "/", true, revisionId3);
+        List<Node> actuals = toNode(query.execute());
+
+        String json = String.format("{\"/#%2$s\" : { \"a#%1$s\" : {}, \"c#%2$s\" : {} }}",
+                revisionId1, revisionId3);
+        Iterator<Node> expecteds = NodeBuilder.build(json).getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    // FIXME - Revisit this test.
+    @Test
+    public void fetchRootAndAllDepths() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
+        Long firstRevisionId = scenario.create();
+        Long secondRevisionId = scenario.update_A_and_add_D_and_E();
+
+        FetchNodesAction query = new FetchNodesAction(getNodeStore(),
+                "/", true, firstRevisionId);
+        query.setDepth(0);
+        List<MongoNode> result = query.execute();
+        List<Node> actuals = toNode(result);
+        String json = String.format("{ \"/#%1$s\" : {} }", firstRevisionId);
+        Node expected = NodeBuilder.build(json);
+        Iterator<Node> expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(), "/", true, secondRevisionId);
+        query.setDepth(0);
+        result = query.execute();
+        actuals = toNode(result);
+        json = String.format("{ \"/#%1$s\" : {} }", firstRevisionId);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(), "/", true, firstRevisionId);
+        query.setDepth(1);
+        result = query.execute();
+        actuals = toNode(result);
+        json = String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 } } }", firstRevisionId);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(), "/", true, secondRevisionId);
+        query.setDepth(1);
+        result = query.execute();
+        actuals = toNode(result);
+        json = String.format("{ \"/#%1$s\" : { \"a#%2$s\" : { \"int\" : 1 , \"double\" : 0.123 } } }",
+                firstRevisionId, secondRevisionId);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(), "/", true, firstRevisionId);
+        query.setDepth(2);
+        result = query.execute();
+        actuals = toNode(result);
+        json = String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1, \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                firstRevisionId);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(), "/", true, secondRevisionId);
+        query.setDepth(2);
+        result = query.execute();
+        actuals = toNode(result);
+        json = 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);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(), "/", true, firstRevisionId);
+        result = query.execute();
+        actuals = toNode(result);
+        json = String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                firstRevisionId);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(), "/", true, secondRevisionId);
+        result = query.execute();
+        actuals = toNode(result);
+        json = 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);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    private Long addNode(String nodeName) throws Exception {
+        Commit commit = CommitBuilder.build("/", "+\"" + nodeName + "\" : {}", "Add /" + nodeName);
+        CommitCommand command = new CommitCommand(getNodeStore(), commit);
+        return command.execute();
+    }
+
+    @Test
+    public void fetchWithCertainPathsOneRevision() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
+        Long revisionId = scenario.create();
+
+        FetchNodesAction query = new FetchNodesAction(getNodeStore(),
+                getPathSet("/a", "/a/b", "/a/c", "not_existing"), revisionId);
+        List<MongoNode> nodeMongos = query.execute();
+        List<Node> actuals = toNode(nodeMongos);
+        String json = String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                revisionId);
+        Node expected = NodeBuilder.build(json);
+        Iterator<Node> expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(),
+                getPathSet("/a", "not_existing"), revisionId);
+        nodeMongos = query.execute();
+        actuals = toNode(nodeMongos);
+        json = String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 } } }",
+                revisionId);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    @Test
+    public void fetchWithCertainPathsTwoRevisions() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
+        Long firstRevisionId = scenario.create();
+        Long secondRevisionId = scenario.update_A_and_add_D_and_E();
+
+        FetchNodesAction query = new FetchNodesAction(getNodeStore(),
+                getPathSet("/a", "/a/b", "/a/c", "/a/d", "/a/b/e", "not_existing"),
+                firstRevisionId);
+        List<MongoNode> nodeMongos = query.execute();
+        List<Node> actuals = toNode(nodeMongos);
+        String json = String.format("{ \"/#%1$s\" : { \"a#%1$s\" : { \"int\" : 1 , \"b#%1$s\" : { \"string\" : \"foo\" } , \"c#%1$s\" : { \"bool\" : true } } } }",
+                firstRevisionId);
+        Node expected = NodeBuilder.build(json);
+        Iterator<Node> expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+
+        query = new FetchNodesAction(getNodeStore(),
+                getPathSet("/a", "/a/b", "/a/c", "/a/d", "/a/b/e", "not_existing"),
+                secondRevisionId);
+        nodeMongos = query.execute();
+        actuals = toNode(nodeMongos);
+        json = 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);
+        expected = NodeBuilder.build(json);
+        expecteds = expected.getChildNodeEntries(0, -1);
+        NodeAssert.assertEquals(expecteds, actuals);
+    }
+
+    private Set<String> getPathSet(String... paths) {
+        return new HashSet<String>(Arrays.asList(paths));
+    }
+
+    private void invalidateCommit(Long revisionId) {
+        DBCollection commitCollection = getNodeStore().getCommitCollection();
+        DBObject query = QueryBuilder.start(MongoCommit.KEY_REVISION_ID)
+                .is(revisionId).get();
+        DBObject update = new BasicDBObject();
+        update.put("$set", new BasicDBObject(MongoCommit.KEY_FAILED, Boolean.TRUE));
+        commitCollection.update(query, update);
+    }
+
+    private void updateBaseRevisionId(Long revisionId2, Long baseRevisionId) {
+        DBCollection commitCollection = getNodeStore().getCommitCollection();
+        DBObject query = QueryBuilder.start(MongoCommit.KEY_REVISION_ID)
+                .is(revisionId2)
+                .get();
+        DBObject update = new BasicDBObject("$set",
+                new BasicDBObject(MongoCommit.KEY_BASE_REVISION_ID, baseRevisionId));
+        commitCollection.update(query, update);
+    }
+
+    private List<Node> toNode(Collection<MongoNode> nodeMongos) {
+        List<Node> nodes = new ArrayList<Node>(nodeMongos.size());
+        for (MongoNode nodeMongo : nodeMongos) {
+            Node node = MongoNode.toNode(nodeMongo);
+            nodes.add(node);
+        }
+
+        return nodes;
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchValidCommitsActionTest.java (from r1407101, 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/impl/action/FetchValidCommitsActionTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchValidCommitsActionTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQueryTest.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/query/FetchValidCommitsQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchValidCommitsActionTest.java Thu Nov  8 15:17:50 2012
@@ -14,111 +14,108 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.query;
+package org.apache.jackrabbit.mongomk.impl.action;
 
 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.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.impl.model.MongoCommit;
 import org.junit.Test;
 
-public class FetchValidCommitsQueryTest extends BaseMongoTest {
+public class FetchValidCommitsActionTest extends BaseMongoMicroKernelTest {
 
     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,
-                Long.MAX_VALUE);
-        List<CommitMongo> commits = query.execute();
+        FetchCommitsAction action = new FetchCommitsAction(getNodeStore());
+        List<MongoCommit> commits = action.execute();
         assertEquals(MIN_COMMITS, commits.size());
 
-        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
         scenario.create();
-        commits = query.execute();
+        commits = action.execute();
         assertEquals(SIMPLE_SCENARIO_COMMITS, commits.size());
 
         int numberOfChildren = 3;
         scenario.addChildrenToA(numberOfChildren);
-        commits = query.execute();
+        commits = action.execute();
         assertEquals(SIMPLE_SCENARIO_COMMITS + numberOfChildren, commits.size());
     }
 
     @Test
     public void revisionId() throws Exception {
-        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection,
-                Long.MAX_VALUE);
-        List<CommitMongo> commits = query.execute();
-        CommitMongo commit0 = commits.get(0);
+        FetchCommitsAction action = new FetchCommitsAction(getNodeStore());
+        List<MongoCommit> commits = action.execute();
+        MongoCommit commit0 = commits.get(0);
 
-        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
         scenario.create();
-        commits = query.execute();
-        CommitMongo commit1 = commits.get(0);
+        commits = action.execute();
+        MongoCommit commit1 = commits.get(0);
         assertTrue(commit0.getRevisionId() < commit1.getRevisionId());
 
         int numberOfChildren = 3;
         scenario.addChildrenToA(numberOfChildren);
-        commits = query.execute();
-        CommitMongo commit2 = commits.get(0);
+        commits = action.execute();
+        MongoCommit commit2 = commits.get(0);
         assertTrue(commit1.getRevisionId() < commit2.getRevisionId());
     }
 
     @Test
     public void time() throws Exception {
-        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection,
-                Long.MAX_VALUE);
-        List<CommitMongo> commits = query.execute();
-        CommitMongo commit0 = commits.get(0);
+        FetchCommitsAction action = new FetchCommitsAction(getNodeStore());
+        List<MongoCommit> commits = action.execute();
+        MongoCommit commit0 = commits.get(0);
 
         Thread.sleep(1000);
 
-        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
         scenario.create();
-        commits = query.execute();
-        CommitMongo commit1 = commits.get(0);
+        commits = action.execute();
+        MongoCommit 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);
+        commits = action.execute();
+        MongoCommit commit2 = commits.get(0);
         assertTrue(commit1.getTimestamp() < commit2.getTimestamp());
     }
 
     @Test
     public void maxEntriesDefaultLimitless() throws Exception {
-        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
         scenario.create();
 
         int numberOfChildren = 2;
         scenario.addChildrenToA(numberOfChildren);
 
-        int maxEntries = 0;
-        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection, maxEntries);
-        List<CommitMongo> commits = query.execute();
+        FetchCommitsAction query = new FetchCommitsAction(getNodeStore(),
+                0L, Long.MAX_VALUE);
+        List<MongoCommit> commits = query.execute();
         assertEquals(SIMPLE_SCENARIO_COMMITS + numberOfChildren, commits.size());
     }
 
     @Test
     public void maxEntries() throws Exception {
-        SimpleNodeScenario scenario = new SimpleNodeScenario(mongoConnection);
+        SimpleNodeScenario scenario = new SimpleNodeScenario(getNodeStore());
         scenario.create();
 
         int numberOfChildren = 2;
         scenario.addChildrenToA(numberOfChildren);
 
         int maxEntries = 2;
-        FetchValidCommitsQuery query = new FetchValidCommitsQuery(mongoConnection, maxEntries);
-        List<CommitMongo> commits = query.execute();
+        FetchCommitsAction query = new FetchCommitsAction(getNodeStore(),
+                0L, Long.MAX_VALUE);
+        query.setMaxEntries(maxEntries);
+        List<MongoCommit> commits = query.execute();
         assertEquals(maxEntries, commits.size());
     }
 }

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchValidCommitsActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchValidCommitsActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/SimpleNodeScenario.java (from r1407101, 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/impl/action/SimpleNodeScenario.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/SimpleNodeScenario.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/scenario/SimpleNodeScenario.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/SimpleNodeScenario.java Thu Nov  8 15:17:50 2012
@@ -14,35 +14,27 @@
  * 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;
+package org.apache.jackrabbit.mongomk.impl.action;
 
 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.MongoConnection;
-import org.apache.jackrabbit.mongomk.impl.builder.CommitBuilder;
-import org.apache.jackrabbit.mongomk.impl.model.AddNodeInstructionImpl;
-import org.apache.jackrabbit.mongomk.impl.model.AddPropertyInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
+import org.apache.jackrabbit.mongomk.impl.command.CommitCommand;
+import org.apache.jackrabbit.mongomk.impl.model.CommitBuilder;
 
 /**
  * Creates a defined scenario in {@code MongoDB}.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
  */
 public class SimpleNodeScenario {
 
-    private final MongoConnection mongoConnection;
+    private final MongoNodeStore nodeStore;
 
     /**
      * Constructs a new {@code SimpleNodeScenario}.
      *
-     * @param mongoConnection The {@link MongoConnection}.
+     * @param nodeStore Node store.
      */
-    public SimpleNodeScenario(MongoConnection mongoConnection) {
-        this.mongoConnection = mongoConnection;
+    public SimpleNodeScenario(MongoNodeStore nodeStore) {
+        this.nodeStore = nodeStore;
     }
 
     /**
@@ -59,51 +51,37 @@ public class SimpleNodeScenario {
         Commit commit = CommitBuilder.build("/",
                 "+\"a\" : { \"int\" : 1 , \"b\" : { \"string\" : \"foo\" } , \"c\" : { \"bool\" : true } }",
                 "This is the simple node scenario with nodes /, /a, /a/b, /a/c");
-        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
-        return command.execute();
+        return new CommitCommand(nodeStore, commit).execute();
     }
 
     public Long addChildrenToA(int count) throws Exception {
         Long revisionId = null;
         for (int i = 1; i <= count; i++) {
             Commit commit = CommitBuilder.build("/a", "+\"child" + i + "\" : {}", "Add child" + i);
-            CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
-            revisionId = command.execute();
+            revisionId = new CommitCommand(nodeStore, commit).execute();
         }
         return revisionId;
     }
 
     public Long delete_A() throws Exception {
         Commit commit = CommitBuilder.build("/", "-\"a\"", "This is a commit with deleted /a");
-        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
-        return command.execute();
+        return new CommitCommand(nodeStore, commit).execute();
     }
 
     public Long delete_B() throws Exception {
         Commit commit = CommitBuilder.build("/a", "-\"b\"", "This is a commit with deleted /a/b");
-        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
-        return command.execute();
+        return new CommitCommand(nodeStore, commit).execute();
     }
 
     public Long 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 }));
-
         StringBuilder diff = new StringBuilder();
         diff.append("+\"a/d\" : {}");
         diff.append("+\"a/b/e\" : {}");
-        diff.append("+\"a/double\" : 0.123");
-        diff.append("+\"a/d/null\" :  null");
-        diff.append("+\"a/b/e/array\" : [ 123, null, 123.456, \"for:bar\", true ]");
+        diff.append("^\"a/double\" : 0.123");
+        diff.append("^\"a/d/int\" :  2");
+        diff.append("^\"a/b/e/array\" : [ 123, null, 123.456, \"for:bar\", true ]");
         Commit commit = CommitBuilder.build("/", diff.toString(),
                 "This is a commit with updated /a and added /a/d and /a/b/e");
-
-        CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit);
-        return command.execute();
+        return new CommitCommand(nodeStore, commit).execute();
     }
 }

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/SimpleNodeScenario.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandTest.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandTest.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,79 @@
+/*
+ * 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.impl.command;
+
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.MongoAssert;
+import org.apache.jackrabbit.mongomk.api.model.Commit;
+import org.apache.jackrabbit.mongomk.impl.SimpleNodeScenario;
+import org.apache.jackrabbit.mongomk.impl.model.CommitBuilder;
+import org.apache.jackrabbit.mongomk.util.MongoUtil;
+import org.apache.jackrabbit.mongomk.util.NodeBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for {@code CommitCommandMongo}
+ */
+public class CommitCommandTest extends BaseMongoMicroKernelTest {
+
+    @Test
+    public void initialCommit() throws Exception {
+        Commit commit = CommitBuilder.build("/", "+\"a\" : { \"b\" : {} , \"c\" : {} }", null);
+        CommitCommand command = new CommitCommand(getNodeStore(), commit);
+        Long revisionId = command.execute();
+
+        Assert.assertNotNull(revisionId);
+        MongoAssert.assertNodesExist(NodeBuilder.build(String.format(
+                "{ \"/#%1$s\" : { \"a#%1$s\" : { \"b#%1$s\" : {} , \"c#%1$s\" : {} } } }", revisionId)));
+
+        MongoAssert.assertCommitExists(commit);
+        MongoAssert.assertCommitContainsAffectedPaths(MongoUtil.fromMongoRepresentation(commit.getRevisionId()),
+                "/", "/a", "/a/b", "/a/c");
+        MongoAssert.assertHeadRevision(1);
+        MongoAssert.assertNextRevision(2);
+    }
+
+    @Test
+    public void ontainsAllAffectedNodes() throws Exception {
+        SimpleNodeScenario scenario = new SimpleNodeScenario(mk);
+        String rev1 = scenario.create();
+        String rev2 = scenario.update_A_and_add_D_and_E();
+        MongoAssert.assertCommitContainsAffectedPaths(rev1, "/", "/a", "/a/b", "/a/c");
+        MongoAssert.assertCommitContainsAffectedPaths(rev2, "/a", "/a/b", "/a/d", "/a/b/e");
+    }
+
+    @Test
+    public void noOtherNodesTouched() throws Exception {
+        String rev1 = mk.commit("/", "+\"a\" : {} +\"b\" : {} +\"c\" : {}", null, null);
+        String rev2 = mk.commit("/a", "+\"d\": {} +\"e\" : {}", null, null);
+
+        MongoAssert.assertNodeRevisionId("/", rev1, true);
+        MongoAssert.assertNodeRevisionId("/a", rev1, true);
+        MongoAssert.assertNodeRevisionId("/b", rev1, true);
+        MongoAssert.assertNodeRevisionId("/c", rev1, true);
+        MongoAssert.assertNodeRevisionId("/a/d", rev1, false);
+        MongoAssert.assertNodeRevisionId("/a/e", rev1, false);
+
+        MongoAssert.assertNodeRevisionId("/", rev2, false);
+        MongoAssert.assertNodeRevisionId("/a", rev2, true);
+        MongoAssert.assertNodeRevisionId("/b", rev2, false);
+        MongoAssert.assertNodeRevisionId("/c", rev2, false);
+        MongoAssert.assertNodeRevisionId("/a/d", rev2, true);
+        MongoAssert.assertNodeRevisionId("/a/e", rev2, true);
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/CommitCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentCommitCommandTest.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ConcurrentCommitCommandMongoTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentCommitCommandTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentCommitCommandTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ConcurrentCommitCommandMongoTest.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/command/ConcurrentCommitCommandMongoTest.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentCommitCommandTest.java Thu Nov  8 15:17:50 2012
@@ -14,34 +14,31 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.command;
+package org.apache.jackrabbit.mongomk.impl.command;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-import org.apache.jackrabbit.mongomk.BaseMongoTest;
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
 import org.apache.jackrabbit.mongomk.api.command.CommandExecutor;
 import org.apache.jackrabbit.mongomk.api.model.Commit;
-import org.apache.jackrabbit.mongomk.api.model.Instruction;
 import org.apache.jackrabbit.mongomk.api.model.Node;
-import org.apache.jackrabbit.mongomk.impl.builder.CommitBuilder;
-import org.apache.jackrabbit.mongomk.impl.command.CommandExecutorImpl;
-import org.apache.jackrabbit.mongomk.impl.model.AddNodeInstructionImpl;
-import org.apache.jackrabbit.mongomk.impl.model.CommitImpl;
-import org.junit.Assert;
+import org.apache.jackrabbit.mongomk.impl.action.FetchCommitsAction;
+import org.apache.jackrabbit.mongomk.impl.model.CommitBuilder;
+import org.apache.jackrabbit.mongomk.impl.model.MongoCommit;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.junit.Test;
 
-/**
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
- */
-@SuppressWarnings("javadoc")
-public class ConcurrentCommitCommandMongoTest extends BaseMongoTest {
+public class ConcurrentCommitCommandTest extends BaseMongoMicroKernelTest {
 
     @Test
     public void testConflictingConcurrentUpdate() throws Exception {
@@ -49,11 +46,11 @@ public class ConcurrentCommitCommandMong
         final Object waitLock = new Object();
 
         // create the commands
-        List<CommitCommandMongo> commands = new ArrayList<CommitCommandMongo>(numOfConcurrentThreads);
+        List<CommitCommand> commands = new ArrayList<CommitCommand>(numOfConcurrentThreads);
         for (int i = 0; i < numOfConcurrentThreads; ++i) {
             Commit commit = CommitBuilder.build("/", "+\"" + i + "\" : {}",
                     "This is a concurrent commit");
-            CommitCommandMongo command = new CommitCommandMongo(mongoConnection, commit) {
+            CommitCommand command = new CommitCommand(getNodeStore(), commit) {
                 @Override
                 protected boolean saveAndSetHeadRevision() throws Exception {
                     try {
@@ -72,11 +69,11 @@ public class ConcurrentCommitCommandMong
         }
 
         // execute the commands
-        final CommandExecutor commandExecutor = new CommandExecutorImpl();
+        final CommandExecutor commandExecutor = new DefaultCommandExecutor();
         ExecutorService executorService = Executors.newFixedThreadPool(numOfConcurrentThreads);
         final List<Long> revisionIds = new LinkedList<Long>();
         for (int i = 0; i < numOfConcurrentThreads; ++i) {
-            final CommitCommandMongo command = commands.get(i);
+            final CommitCommand command = commands.get(i);
             Runnable runnable = new Runnable() {
 
                 @Override
@@ -85,6 +82,7 @@ public class ConcurrentCommitCommandMong
                         Long revisionId = commandExecutor.execute(command);
                         revisionIds.add(revisionId);
                     } catch (Exception e) {
+                        e.printStackTrace();
                         revisionIds.add(null);
                     }
                 }
@@ -111,25 +109,32 @@ public class ConcurrentCommitCommandMong
         List<String> lastChildren = new LinkedList<String>();
         for (int i = 0; i < numOfConcurrentThreads; ++i) {
             Long revisionId = revisionIds.get(i);
-            GetNodesCommandMongo command2 = new GetNodesCommandMongo(mongoConnection, "/", revisionId, 0);
+            GetNodesCommand command2 = new GetNodesCommand(getNodeStore(),
+                    "/", revisionId);
             Node root = command2.execute();
-            Set<Node> children = root.getChildren();
+
             for (String lastChild : lastChildren) {
                 boolean contained = false;
-                for (Node childNode : children) {
-                    if (childNode.getName().equals(lastChild)) {
+                for (Iterator<Node> it = root.getChildNodeEntries(0, -1); it.hasNext(); ) {
+                    Node childNode = it.next();
+                    String childName = PathUtils.getName(childNode.getPath());
+                    if (childName.equals(lastChild)) {
                         contained = true;
                         break;
                     }
                 }
-                Assert.assertTrue(contained);
+                assertTrue(contained);
             }
             lastChildren.clear();
-            for (Node childNode : children) {
-                lastChildren.add(childNode.getName());
+            for (Iterator<Node> it = root.getChildNodeEntries(0, -1); it.hasNext(); ) {
+                Node childNode = it.next();
+                String childName = PathUtils.getName(childNode.getPath());
+                lastChildren.add(childName);
             }
         }
 
-        // TODO Assert the number of commits
+        // Assert number of successful commits.
+        List<MongoCommit> commits = new FetchCommitsAction(getNodeStore()).execute();
+        assertEquals(numOfConcurrentThreads + 1, commits.size());
     }
 }

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentCommitCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentWriteMultipleMkMongoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentWriteMultipleMkMongoTest.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentWriteMultipleMkMongoTest.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentWriteMultipleMkMongoTest.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,126 @@
+package org.apache.jackrabbit.mongomk.impl.command;
+
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
+import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
+import org.apache.jackrabbit.mongomk.impl.blob.MongoGridFSBlobStore;
+import org.junit.Test;
+
+import com.mongodb.DB;
+
+public class ConcurrentWriteMultipleMkMongoTest extends BaseMongoMicroKernelTest {
+
+    @Test
+    public void testConcurrency() throws NumberFormatException, Exception {
+
+        String diff1 = buildPyramidDiff("/", 0, 10, 100, "N",
+                new StringBuilder()).toString();
+        String diff2 = buildPyramidDiff("/", 0, 10, 100, "P",
+                new StringBuilder()).toString();
+        String diff3 = buildPyramidDiff("/", 0, 10, 100, "R",
+                new StringBuilder()).toString();
+
+        // System.out.println(diff1);
+        // System.out.println(diff2);
+        // System.out.println(diff3);
+
+        InputStream is = BaseMongoMicroKernelTest.class.getResourceAsStream("/config.cfg");
+        Properties properties = new Properties();
+        properties.load(is);
+
+        DB db = mongoConnection.getDB();
+        MongoMicroKernel mongo1 = new MongoMicroKernel(mongoConnection,
+                new MongoNodeStore(db), new MongoGridFSBlobStore(db));
+        MongoMicroKernel mongo2 = new MongoMicroKernel(mongoConnection,
+                new MongoNodeStore(db), new MongoGridFSBlobStore(db));
+        MongoMicroKernel mongo3 = new MongoMicroKernel(mongoConnection,
+                new MongoNodeStore(db), new MongoGridFSBlobStore(db));
+
+        GenericWriteTask task1 = new GenericWriteTask(mongo1, diff1, 0);
+        GenericWriteTask task2 = new GenericWriteTask(mongo2, diff2, 0);
+        GenericWriteTask task3 = new GenericWriteTask(mongo3, diff3, 0);
+
+        ExecutorService threadExecutor = Executors.newFixedThreadPool(3);
+        threadExecutor.execute(task1);
+        threadExecutor.execute(task2);
+        threadExecutor.execute(task3);
+        threadExecutor.shutdown();
+        threadExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
+    }
+
+    private static StringBuilder buildPyramidDiff(String startingPoint,
+            int index, int numberOfChildren, long nodesNumber,
+            String nodePrefixName, StringBuilder diff) {
+        if (numberOfChildren == 0) {
+            for (long i = 0; i < nodesNumber; i++)
+                diff.append(addNodeToDiff(startingPoint, nodePrefixName + i));
+            return diff;
+        }
+        if (index >= nodesNumber)
+            return diff;
+        diff.append(addNodeToDiff(startingPoint, nodePrefixName + index));
+        for (int i = 1; i <= numberOfChildren; i++) {
+            if (!startingPoint.endsWith("/"))
+                startingPoint = startingPoint + "/";
+            buildPyramidDiff(startingPoint + nodePrefixName + index, index
+                    * numberOfChildren + i, numberOfChildren, nodesNumber,
+                    nodePrefixName, diff);
+        }
+        return diff;
+    }
+
+    private static String addNodeToDiff(String startingPoint, String nodeName) {
+        if (!startingPoint.endsWith("/"))
+            startingPoint = startingPoint + "/";
+
+        return ("+\"" + startingPoint + nodeName + "\" : {\"key\":\"00000000000000000000\"} \n");
+    }
+}
+
+class GenericWriteTask implements Runnable {
+
+    MicroKernel mk;
+    String diff;
+    int nodesPerCommit;
+
+    public GenericWriteTask(MongoMicroKernel mk, String diff, int nodesPerCommit) {
+
+        this.diff = diff;
+        this.mk = mk;
+    }
+
+    @Override
+    public void run() {
+        commit(mk, diff, 10);
+    }
+
+    private void commit(MicroKernel mk, String diff, int nodesPerCommit) {
+
+        if (nodesPerCommit == 0) {
+            mk.commit("", diff.toString(), null, "");
+            return;
+        }
+        String[] string = diff.split(System.getProperty("line.separator"));
+        int i = 0;
+        StringBuilder finalCommit = new StringBuilder();
+        for (String line : string) {
+            finalCommit.append(line);
+            i++;
+            if (i == nodesPerCommit) {
+                mk.commit("", finalCommit.toString(), null, "");
+                finalCommit.setLength(0);
+                i = 0;
+            }
+        }
+        // commit remaining nodes
+        if (finalCommit.length() > 0)
+            mk.commit("", finalCommit.toString(), null, "");
+    }
+}

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

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/command/ConcurrentWriteMultipleMkMongoTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message