jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1467988 - in /jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk: ./ blob/ impl/
Date Mon, 15 Apr 2013 12:48:56 GMT
Author: mreutegg
Date: Mon Apr 15 12:48:56 2013
New Revision: 1467988

URL: http://svn.apache.org/r1467988
Log:
OAK-619 Lock-free MongoMK implementation
- Restructure tests (use MemoryDocumentStore based MongoMK where possible)
- Remove duplicate code
- Enable more tests

Added:
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitAddTest.java
  (contents, props changed)
      - copied, changed from r1467952, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitCopyTest.java
  (contents, props changed)
      - copied, changed from r1467952, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitCopyTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKTestBase.java
  (with props)
Removed:
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitCopyTest.java
Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMKTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKDiffTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKGetLengthTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKReadTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKWriteTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java?rev=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
Mon Apr 15 12:48:56 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mongomk.util.MongoConnection;
 import org.junit.After;
 import org.junit.Assume;
@@ -30,7 +31,7 @@ import com.mongodb.DB;
  * to a clean test database. Tests in subclasses are automatically
  * skipped if the configured MongoDB connection can not be created.
  */
-public class AbstractMongoConnectionTest {
+public abstract class AbstractMongoConnectionTest extends MongoMKTestBase {
 
     protected static final String HOST =
             System.getProperty("mongo.host", "127.0.0.1");
@@ -47,6 +48,8 @@ public class AbstractMongoConnectionTest
     
     protected MongoConnection mongoConnection;
 
+    protected MongoMK mk;
+
     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
         if (mongoAvailable == null) {
@@ -68,10 +71,12 @@ public class AbstractMongoConnectionTest
     public void setUpConnection() throws Exception {
         mongoConnection = new MongoConnection(HOST, PORT, DB);
         dropCollections(mongoConnection.getDB());
+        mk = new MongoMK.Builder().setMongoDB(mongoConnection.getDB()).open();
     }
 
     @After
     public void tearDownConnection() throws Exception {
+        mk.dispose();
         // the db might already be closed
         mongoConnection.close();
         mongoConnection = new MongoConnection(HOST, PORT, DB);
@@ -79,6 +84,11 @@ public class AbstractMongoConnectionTest
         mongoConnection.close();
     }
 
+    @Override
+    protected MicroKernel getMicroKernel() {
+        return mk;
+    }
+
     protected void dropCollections(DB db) throws Exception {
         for (String name : db.getCollectionNames()) {
             if (!name.startsWith("system.")) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMKTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMKTest.java?rev=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMKTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMKTest.java
Mon Apr 15 12:48:56 2013
@@ -16,25 +16,23 @@
  */
 package org.apache.jackrabbit.mongomk;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.junit.Before;
 
-import com.mongodb.DB;
-
 /**
  * <code>BaseMongoMKTest</code>...
  */
-public class BaseMongoMKTest extends BaseMongoMicroKernelTest {
+public class BaseMongoMKTest extends MongoMKTestBase {
+
+    protected MongoMK mk;
 
     @Before
-    @Override
-    public void setUp() throws Exception {
-        DB db = mongoConnection.getDB();
-        mk = new MongoMK.Builder().setMongoDB(db).open();
+    public void initMongoMK() {
+        mk = new MongoMK.Builder().open();
     }
 
     @Override
-    public void tearDownConnection() throws Exception {
-        ((MongoMK) mk).dispose();
-        super.tearDownConnection();
+    protected MicroKernel getMicroKernel() {
+        return mk;
     }
 }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java?rev=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java
Mon Apr 15 12:48:56 2013
@@ -16,17 +16,7 @@
  */
 package org.apache.jackrabbit.mongomk;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.junit.Before;
 
 import com.mongodb.DB;
 
@@ -35,154 +25,4 @@ import com.mongodb.DB;
  */
 public class BaseMongoMicroKernelTest extends AbstractMongoConnectionTest {
 
-    public MicroKernel mk;
-
-    @Before
-    public void setUp() throws Exception {
-        DB db = mongoConnection.getDB();
-        
-        mk = new MongoMK.Builder().setMongoDB(db).open();
-    }
-
-    protected JSONObject getObjectArrayEntry(JSONArray array, int pos) {
-        assertTrue(pos >= 0 && pos < array.size());
-        Object entry = array.get(pos);
-        if (entry instanceof JSONObject) {
-            return (JSONObject) entry;
-        }
-        throw new AssertionError("failed to resolve JSONObject array entry at pos " + pos
+ ": " + entry);
-    }
-
-    protected JSONArray parseJSONArray(String json) throws AssertionError {
-        JSONParser parser = new JSONParser();
-        try {
-            Object obj = parser.parse(json);
-            assertTrue(obj instanceof JSONArray);
-            return (JSONArray) obj;
-        } catch (Exception e) {
-            throw new AssertionError("not a valid JSON array: " + e.getMessage());
-        }
-    }
-
-    protected JSONObject parseJSONObject(String json) throws AssertionError {
-        JSONParser parser = new JSONParser();
-        try {
-            Object obj = parser.parse(json);
-            assertTrue(obj instanceof JSONObject);
-            return (JSONObject) obj;
-        } catch (Exception e) {
-            throw new AssertionError("not a valid JSON object: " + e.getMessage());
-        }
-    }
-
-    protected void assertNodesExist(String revision, String...paths) {
-        doAssertNodes(true, revision, paths);
-    }
-
-    protected void assertNodesNotExist(String revision, String...paths) {
-        doAssertNodes(false, revision, paths);
-    }
-
-    protected void assertPropExists(String rev, String path, String property) {
-        String nodes = mk.getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
-        JSONObject obj = parseJSONObject(nodes);
-        assertPropertyExists(obj, property);
-    }
-
-    protected void assertPropNotExists(String rev, String path, String property) {
-        String nodes = mk.getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
-        if (nodes == null) {
-            return;
-        }
-        JSONObject obj = parseJSONObject(nodes);
-        assertPropertyNotExists(obj, property);
-    }
-
-    protected void assertPropValue(String rev, String path, String property, String value)
{
-        String nodes = mk.getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
-        JSONObject obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, property, value);
-    }
-
-    protected void assertPropertyExists(JSONObject obj, String relPath, Class<?> type)
-            throws AssertionError {
-        Object val = resolveValue(obj, relPath);
-        assertNotNull("not found: " + relPath, val);
-
-        assertTrue(type.isInstance(val));
-    }
-
-    protected void assertPropertyExists(JSONObject obj, String relPath)
-            throws AssertionError {
-        Object val = resolveValue(obj, relPath);
-        assertNotNull("not found: " + relPath, val);
-    }
-
-    protected void assertPropertyNotExists(JSONObject obj, String relPath)
-            throws AssertionError {
-        Object val = resolveValue(obj, relPath);
-        assertNull(val);
-    }
-
-    protected void assertPropertyValue(JSONObject obj, String relPath, String expected)
-            throws AssertionError {
-        Object val = resolveValue(obj, relPath);
-        assertNotNull("not found: " + relPath, val);
-        assertEquals(expected, val);
-    }
-
-    protected void assertPropertyValue(JSONObject obj, String relPath, Double expected)
-            throws AssertionError {
-        Object val = resolveValue(obj, relPath);
-        assertNotNull("not found: " + relPath, val);
-
-        assertEquals(expected, val);
-    }
-
-    protected void assertPropertyValue(JSONObject obj, String relPath, Long expected)
-            throws AssertionError {
-        Object val = resolveValue(obj, relPath);
-        assertNotNull("not found: " + relPath, val);
-        assertEquals(expected, val);
-    }
-
-    protected void assertPropertyValue(JSONObject obj, String relPath, Boolean expected)
-            throws AssertionError {
-        Object val = resolveValue(obj, relPath);
-        assertNotNull("not found: " + relPath, val);
-
-        assertEquals(expected, val);
-    }
-
-    private void doAssertNodes(boolean checkExists, String revision, String...paths) {
-        for (String path : paths) {
-            boolean exists = mk.nodeExists(path, revision);
-            if (checkExists) {
-                assertTrue(path + " does not exist", exists);
-            } else {
-                assertFalse(path + " should not exist", exists);
-            }
-        }
-    }
-
-    protected JSONObject resolveObjectValue(JSONObject obj, String relPath) {
-        Object val = resolveValue(obj, relPath);
-        if (val instanceof JSONObject) {
-            return (JSONObject) val;
-        }
-        throw new AssertionError("failed to resolve JSONObject value at " + relPath + ":
" + val);
-    }
-
-    private static Object resolveValue(JSONObject obj, String relPath) {
-        String[] names = relPath.split("/");
-        Object val = obj;
-        for (String name : names) {
-            if (!(val instanceof JSONObject)) {
-                throw new AssertionError("not found: " + relPath);
-            }
-            val = ((JSONObject) val).get(name);
-        }
-        return val;
-    }
-
 }
\ No newline at end of file

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitAddTest.java
(from r1467952, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitAddTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitAddTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java&r1=1467952&r2=1467988&rev=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitAddTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitAddTest.java
Mon Apr 15 12:48:56 2013
@@ -14,14 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl;
+package org.apache.jackrabbit.mongomk;
 
-import static org.junit.Assert.assertEquals;
 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.json.simple.JSONObject;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -32,17 +30,13 @@ import com.jamonapi.MonitorFactory;
 /**
  * Tests for add node and property operations.
  */
-public class MongoMKCommitAddTest extends BaseMongoMicroKernelTest {
+public class MongoMKCommitAddTest extends BaseMongoMKTest {
 
     @Test
-    @Ignore    
     public void addSingleNode() throws Exception {
         mk.commit("/", "+\"a\" : {}", null, null);
 
-        long childCount = mk.getChildNodeCount("/", null);
-        assertEquals(1, childCount);
-
-        String nodes = mk.getNodes("/", null, -1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
         assertPropertyValue(obj, ":childNodeCount", 1L);
     }
@@ -81,10 +75,9 @@ public class MongoMKCommitAddTest extend
     }
 
     @Test
-    @Ignore    
     public void addNodeWithParanthesis() throws Exception {
         mk.commit("/", "+\"Test({0})\" : {}", null, null);
-        String nodes = mk.getNodes("/Test({0})", null, 1, 0, -1, null);
+        String nodes = mk.getNodes("/Test({0})", null, 0, 0, -1, null);
         JSONObject obj = parseJSONObject(nodes);
         assertPropertyValue(obj, ":childNodeCount", 0L);
     }
@@ -116,59 +109,54 @@ public class MongoMKCommitAddTest extend
     }
 
     @Test
-    @Ignore    
     public void setSingleProperty() throws Exception {
         mk.commit("/", "+\"a\" : {} ^\"a/key1\" : \"value1\"", null, null);
 
-        long childCount = mk.getChildNodeCount("/", null);
-        assertEquals(1, childCount);
-
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
         assertPropertyValue(obj, ":childNodeCount", 1L);
-        assertPropertyValue(obj, "a/key1", "value1");
+        nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        obj = parseJSONObject(nodes);
+        assertPropertyValue(obj, "key1", "value1");
     }
 
     @Test
-    @Ignore    
     public void setMultipleProperties() throws Exception {
         mk.commit("/", "+\"a\" : {} ^\"a/key1\" : \"value1\"", null, null);
         mk.commit("/", "^\"a/key2\" : 2", null, null);
         mk.commit("/", "^\"a/key3\" : false", null, null);
         mk.commit("/", "^\"a/key4\" : 0.25", null, null);
 
-        long childCount = mk.getChildNodeCount("/", null);
-        assertEquals(1, childCount);
-
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
         assertPropertyValue(obj, ":childNodeCount", 1L);
-        assertPropertyValue(obj, "a/key1", "value1");
-        assertPropertyValue(obj, "a/key2", 2L);
-        assertPropertyValue(obj, "a/key3", false);
-        assertPropertyValue(obj, "a/key4", 0.25);
+        nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        obj = parseJSONObject(nodes);
+        assertPropertyValue(obj, "key1", "value1");
+        assertPropertyValue(obj, "key2", 2L);
+        assertPropertyValue(obj, "key3", false);
+        assertPropertyValue(obj, "key4", 0.25);
     }
 
     // See http://www.mongodb.org/display/DOCS/Legal+Key+Names
     @Test
-    @Ignore    
     public void setPropertyIllegalKey() throws Exception {
         mk.commit("/", "+\"a\" : {}", null, null);
 
         mk.commit("/", "^\"a/ke.y1\" : \"value\"", null, null);
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "a/ke.y1", "value");
+        assertPropertyValue(obj, "ke.y1", "value");
 
         mk.commit("/", "^\"a/ke.y.1\" : \"value\"", null, null);
-        nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/, null
/*filter*/);
+        nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "a/ke.y.1", "value");
+        assertPropertyValue(obj, "ke.y.1", "value");
 
         mk.commit("/", "^\"a/$key1\" : \"value\"", null, null);
-        nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/, null
/*filter*/);
+        nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "a/$key1", "value");
+        assertPropertyValue(obj, "$key1", "value");
     }
 
     @Test
@@ -182,7 +170,6 @@ public class MongoMKCommitAddTest extend
     }
 
     @Test
-    @Ignore        
     public void setOverwritingProperty() throws Exception {
         String rev1 = mk.commit("/", "+\"a\" : {} ^\"a/key1\" : \"value1\"", null, null);
 
@@ -192,9 +179,9 @@ public class MongoMKCommitAddTest extend
         // Commit with rev1 again (to overwrite rev2)
         mk.commit("/", "^\"a/key1\" : \"value3\"", rev1, null);
 
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "a/key1", "value3");
+        assertPropertyValue(obj, "key1", "value3");
    }
 
     // This is a test to make sure commit time stays the same as time goes on.
@@ -221,7 +208,6 @@ public class MongoMKCommitAddTest extend
     }
 
     @Test
-    @Ignore    
     public void existingNodesMerged() throws Exception {
         String rev = mk.commit("/", "+\"a\" : {}", null, null);
         mk.commit("/", "+\"a/b\" : {}", null, null);
@@ -231,10 +217,12 @@ public class MongoMKCommitAddTest extend
         mk.commit("/", "^\"a/key2\" : \"value2\"", rev, null);
 
         // Check that key1 and b were merged
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
         assertPropertyValue(obj, ":childNodeCount", 1L);
-        assertPropertyValue(obj, "a/key1", "value1");
-        assertPropertyValue(obj, "a/key2", "value2");
+        nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        obj = parseJSONObject(nodes);
+        assertPropertyValue(obj, "key1", "value1");
+        assertPropertyValue(obj, "key2", "value2");
     }
 }
\ No newline at end of file

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

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

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitCopyTest.java
(from r1467952, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitCopyTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitCopyTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitCopyTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitCopyTest.java&r1=1467952&r2=1467988&rev=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitCopyTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKCommitCopyTest.java
Mon Apr 15 12:48:56 2013
@@ -14,13 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl;
+package org.apache.jackrabbit.mongomk;
 
 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.json.simple.JSONObject;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -28,7 +27,7 @@ import org.junit.Test;
 /**
  * Tests with emphasis on copy operations.
  */
-public class MongoMKCommitCopyTest extends BaseMongoMicroKernelTest {
+public class MongoMKCommitCopyTest extends BaseMongoMKTest {
 
     @Test
     public void copyNode() throws Exception {

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

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

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKDiffTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKDiffTest.java?rev=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKDiffTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKDiffTest.java
Mon Apr 15 12:48:56 2013
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTru
 /**
  * Tests for MicroKernel#diff
  */
-public class MongoMKDiffTest extends BaseMongoMKTest {
+public class MongoMKDiffTest extends BaseMongoMicroKernelTest {
 
     @Test
     public void oak596() {

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKTestBase.java?rev=1467988&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKTestBase.java
(added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoMKTestBase.java
Mon Apr 15 12:48:56 2013
@@ -0,0 +1,177 @@
+/*
+ * 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;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * <code>MongoMKTestBase</code> provides utility methods for MongoMK tests.
+ */
+public abstract class MongoMKTestBase {
+
+    protected abstract MicroKernel getMicroKernel();
+
+    protected JSONObject getObjectArrayEntry(JSONArray array, int pos) {
+        assertTrue(pos >= 0 && pos < array.size());
+        Object entry = array.get(pos);
+        if (entry instanceof JSONObject) {
+            return (JSONObject) entry;
+        }
+        throw new AssertionError("failed to resolve JSONObject array entry at pos " + pos
+ ": " + entry);
+    }
+
+    protected JSONArray parseJSONArray(String json) throws AssertionError {
+        JSONParser parser = new JSONParser();
+        try {
+            Object obj = parser.parse(json);
+            assertTrue(obj instanceof JSONArray);
+            return (JSONArray) obj;
+        } catch (Exception e) {
+            throw new AssertionError("not a valid JSON array: " + e.getMessage());
+        }
+    }
+
+    protected JSONObject parseJSONObject(String json) throws AssertionError {
+        JSONParser parser = new JSONParser();
+        try {
+            Object obj = parser.parse(json);
+            assertTrue(obj instanceof JSONObject);
+            return (JSONObject) obj;
+        } catch (Exception e) {
+            throw new AssertionError("not a valid JSON object: " + e.getMessage());
+        }
+    }
+
+    protected void assertNodesExist(String revision, String...paths) {
+        doAssertNodes(true, revision, paths);
+    }
+
+    protected void assertNodesNotExist(String revision, String...paths) {
+        doAssertNodes(false, revision, paths);
+    }
+
+    protected void assertPropExists(String rev, String path, String property) {
+        String nodes = getMicroKernel().getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1
/*maxChildNodes*/, null /*filter*/);
+        JSONObject obj = parseJSONObject(nodes);
+        assertPropertyExists(obj, property);
+    }
+
+    protected void assertPropNotExists(String rev, String path, String property) {
+        String nodes = getMicroKernel().getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1
/*maxChildNodes*/, null /*filter*/);
+        if (nodes == null) {
+            return;
+        }
+        JSONObject obj = parseJSONObject(nodes);
+        assertPropertyNotExists(obj, property);
+    }
+
+    protected void assertPropValue(String rev, String path, String property, String value)
{
+        String nodes = getMicroKernel().getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1
/*maxChildNodes*/, null /*filter*/);
+        JSONObject obj = parseJSONObject(nodes);
+        assertPropertyValue(obj, property, value);
+    }
+
+    protected void assertPropertyExists(JSONObject obj, String relPath, Class<?> type)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+
+        assertTrue(type.isInstance(val));
+    }
+
+    protected void assertPropertyExists(JSONObject obj, String relPath)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+    }
+
+    protected void assertPropertyNotExists(JSONObject obj, String relPath)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNull(val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, String expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+        assertEquals(expected, val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, Double expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+
+        assertEquals(expected, val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, Long expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+        assertEquals(expected, val);
+    }
+
+    protected void assertPropertyValue(JSONObject obj, String relPath, Boolean expected)
+            throws AssertionError {
+        Object val = resolveValue(obj, relPath);
+        assertNotNull("not found: " + relPath, val);
+
+        assertEquals(expected, val);
+    }
+
+    private void doAssertNodes(boolean checkExists, String revision, String...paths) {
+        for (String path : paths) {
+            boolean exists = getMicroKernel().nodeExists(path, revision);
+            if (checkExists) {
+                assertTrue(path + " does not exist", exists);
+            } else {
+                assertFalse(path + " should not exist", exists);
+            }
+        }
+    }
+
+    protected JSONObject resolveObjectValue(JSONObject obj, String relPath) {
+        Object val = resolveValue(obj, relPath);
+        if (val instanceof JSONObject) {
+            return (JSONObject) val;
+        }
+        throw new AssertionError("failed to resolve JSONObject value at " + relPath + ":
" + val);
+    }
+
+    private static Object resolveValue(JSONObject obj, String relPath) {
+        String[] names = relPath.split("/");
+        Object val = obj;
+        for (String name : names) {
+            if (!(val instanceof JSONObject)) {
+                throw new AssertionError("not found: " + relPath);
+            }
+            val = ((JSONObject) val).get(name);
+        }
+        return val;
+    }
+}

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

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

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKGetLengthTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKGetLengthTest.java?rev=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKGetLengthTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKGetLengthTest.java
Mon Apr 15 12:48:56 2013
@@ -22,26 +22,13 @@ import static org.junit.Assert.fail;
 import java.io.ByteArrayInputStream;
 
 import org.apache.jackrabbit.mongomk.AbstractMongoConnectionTest;
-import org.apache.jackrabbit.mongomk.MongoMK;
-import org.junit.Before;
 import org.junit.Test;
 
-import com.mongodb.DB;
-
 /**
  * Tests for {@code MongoMicroKernel#getLength(String)}
  */
 public class MongoMKGetLengthTest extends AbstractMongoConnectionTest {
 
-    private MongoMK mk;
-
-    @Before
-    public void setUp() throws Exception {
-        DB db = mongoConnection.getDB();
-
-        mk = new MongoMK.Builder().setMongoDB(db).open();
-    }
-
     @Test
     public void nonExistent() throws Exception {
         try {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKReadTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKReadTest.java?rev=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKReadTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKReadTest.java
Mon Apr 15 12:48:56 2013
@@ -23,28 +23,16 @@ import junit.framework.Assert;
 
 import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
 import org.apache.jackrabbit.mongomk.AbstractMongoConnectionTest;
-import org.apache.jackrabbit.mongomk.MongoMK;
-import org.junit.Before;
 import org.junit.Test;
 
-import com.mongodb.DB;
-
 /**
  * Tests for {@code MongoMicroKernel#read(String, long, byte[], int, int)}
  */
 public class MongoMKReadTest extends AbstractMongoConnectionTest {
 
-    private MongoMK mk;
     private byte[] blob;
     private String blobId;
 
-    @Before
-    public void setUp() throws Exception {
-        DB db = mongoConnection.getDB();
-
-        mk = new MongoMK.Builder().setMongoDB(db).open();
-    }
-
     @Test
     public void small() throws Exception {
         read(1024, false);

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKWriteTest.java?rev=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKWriteTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/blob/MongoMKWriteTest.java
Mon Apr 15 12:48:56 2013
@@ -24,8 +24,6 @@ import java.util.Arrays;
 
 import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
 import org.apache.jackrabbit.mongomk.AbstractMongoConnectionTest;
-import org.apache.jackrabbit.mongomk.MongoMK;
-import org.junit.Before;
 import org.junit.Test;
 
 import com.mongodb.DB;
@@ -35,15 +33,6 @@ import com.mongodb.DB;
  */
 public class MongoMKWriteTest extends AbstractMongoConnectionTest {
 
-    private MongoMK mk;
-
-    @Before
-    public void setUp() throws Exception {
-        DB db = mongoConnection.getDB();
-
-        mk = new MongoMK.Builder().setMongoDB(db).open();
-    }
-
     @Test
     public void small() throws Exception {
         write(1024);

Modified: 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=1467988&r1=1467987&r2=1467988&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKWaitForCommitTest.java
Mon Apr 15 12:48:56 2013
@@ -44,10 +44,10 @@ public class MongoMKWaitForCommitTest ex
     private MicroKernel mk2;
 
     @Before
-    public void setUp() throws Exception {
-        super.setUp();
+    @Override
+    public void setUpConnection() throws Exception {
+        super.setUpConnection();
         DB db = mongoConnection.getDB();
-        
         mk2 = new MongoMK.Builder().setMongoDB(db).open();
     }
 



Mime
View raw message