jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1336167 - in /jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test: AbstractMicroKernelIT.java MicroKernelIT.java
Date Wed, 09 May 2012 13:02:41 GMT
Author: stefan
Date: Wed May  9 13:02:40 2012
New Revision: 1336167

URL: http://svn.apache.org/viewvc?rev=1336167&view=rev
Log:
OAK-12: Implement a test suite for the MicroKernel (WIP)

Modified:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java?rev=1336167&r1=1336166&r2=1336167&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
Wed May  9 13:02:40 2012
@@ -18,7 +18,10 @@ package org.apache.jackrabbit.mk.test;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
 import java.util.ServiceLoader;
+import java.util.Set;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.json.simple.JSONArray;
@@ -179,6 +182,28 @@ public abstract class AbstractMicroKerne
         }
     }
 
+    protected Set<String> getNodeNames(JSONObject obj) {
+        Set<String> names = new HashSet<String>();
+        Set<Map.Entry> entries = obj.entrySet();
+        for (Map.Entry entry : entries) {
+            if (entry.getValue() instanceof JSONObject) {
+                names.add((String) entry.getKey());
+            }
+        }
+        return names;
+    }
+
+    protected Set<String> getPropertyNames(JSONObject obj) {
+        Set<String> names = new HashSet<String>();
+        Set<Map.Entry> entries = obj.entrySet();
+        for (Map.Entry entry : entries) {
+            if (! (entry.getValue() instanceof JSONObject)) {
+                names.add((String) entry.getKey());
+            }
+        }
+        return names;
+    }
+
     protected void assertPropertyExists(JSONObject obj, String relPath)
             throws AssertionError {
         Object val = resolveValue(obj, relPath);

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java?rev=1336167&r1=1336166&r2=1336167&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
Wed May  9 13:02:40 2012
@@ -23,6 +23,12 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -146,8 +152,6 @@ public class MicroKernelIT extends Abstr
 
         // diff of rev0->rev2 should be empty
         assertEquals(mk.diff(rev0, rev2, null), "");
-
-
     }
 
     @Test
@@ -379,6 +383,65 @@ public class MicroKernelIT extends Abstr
     }
 
     @Test
+    public void getNodesOffset() {
+        // number of siblings (multiple of 10)
+        final int NUM_SIBLINGS = 1000;
+        // set of all sibling names
+        final Set<String> siblingNames = new HashSet<String>(NUM_SIBLINGS);
+
+        // populate siblings
+        Random rand = new Random();
+        StringBuffer sb = new StringBuffer("+\"/testRoot\":{");
+        for (int i = 0; i < NUM_SIBLINGS; i++) {
+            String name = "n" + rand.nextLong();
+            siblingNames.add(name);
+            sb.append("\n\"");
+            sb.append(name);
+            sb.append("\":{}");
+            if (i < NUM_SIBLINGS - 1) {
+                sb.append(',');
+            }
+        }
+        sb.append("\n}");
+        String head = mk.commit("", sb.toString(), null, "");
+
+        // get all siblings in one call
+        JSONObject obj = parseJSONObject(mk.getNodes("/testRoot", head, 0, 0, -1, null));
+        assertPropertyValue(obj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertEquals(siblingNames, getNodeNames(obj));
+
+        // list of sibling names in iteration order
+        final List<String> orderedSiblingNames = new ArrayList<String>(NUM_SIBLINGS);
+
+        // get siblings one by one
+        for (int i = 0; i < NUM_SIBLINGS; i++) {
+            obj = parseJSONObject(mk.getNodes("/testRoot", head, 0, i, 1, null));
+            assertPropertyValue(obj, ":childNodeCount", (long) NUM_SIBLINGS);
+            Set<String> set = getNodeNames(obj);
+            assertEquals(set.size(), 1);
+            orderedSiblingNames.add(set.iterator().next());
+        }
+
+        // check completeness
+        Set<String> names = new HashSet<String>(siblingNames);
+        names.removeAll(orderedSiblingNames);
+        assertTrue(names.isEmpty());
+
+        // we've now established the expected iteration order
+
+        // get siblings in 10 chunks
+        for (int i = 0; i < 10; i++) {
+            obj = parseJSONObject(mk.getNodes("/testRoot", head, 0, i * 10, NUM_SIBLINGS
/ 10, null));
+            assertPropertyValue(obj, ":childNodeCount", (long) NUM_SIBLINGS);
+            names = getNodeNames(obj);
+            assertEquals(names.size(), NUM_SIBLINGS / 10);
+            List<String> subList = orderedSiblingNames.subList(i * 10, (i * 10) + (NUM_SIBLINGS
/ 10));
+            names.removeAll(subList);
+            assertTrue(names.isEmpty());
+        }
+    }
+
+    @Test
     public void getNodesRevision() {
         // 1st pass
         long tst = System.currentTimeMillis();



Mime
View raw message