jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1342796 - in /jackrabbit/oak/trunk: oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
Date Fri, 25 May 2012 20:20:25 GMT
Author: stefan
Date: Fri May 25 20:20:25 2012
New Revision: 1342796

URL: http://svn.apache.org/viewvc?rev=1342796&view=rev
Log:
OAK-75: specify format and semantics of 'filter' parameter in MicroKernel API
OAK-116: MicroKernel API: clarify semantics of getNodes depth, offset and count parameters

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

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=1342796&r1=1342795&r2=1342796&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
Fri May 25 20:20:25 2012
@@ -331,12 +331,12 @@ public class MicroKernelIT extends Abstr
         String head = mk.getHeadRevision();
         head = mk.commit("",
                 "+\"/root\":{}\n" +
-                "+\"/root/a\":{}\n",
+                        "+\"/root/a\":{}\n",
                 head, "");
 
         head = mk.commit("",
                 "+\"/root/a/b\":{}\n" +
-                ">\"/root/a\":\"/root/c\"\n",
+                        ">\"/root/a\":\"/root/c\"\n",
                 head, "");
 
         assertFalse(mk.nodeExists("/root/a", head));
@@ -375,7 +375,7 @@ public class MicroKernelIT extends Abstr
     public void copyToDescendant() {
         mk.commit("/",
                 "+\"test/child\":{}\n" +
-                "*\"test\":\"test/copy\"\n",
+                        "*\"test\":\"test/copy\"\n",
                 null, "");
 
         assertTrue(mk.nodeExists("/test/child", null));
@@ -435,7 +435,8 @@ public class MicroKernelIT extends Abstr
 
         assertFalse(hash0.equals(hash1));
 
-        // undo property modification and verify that the hash of the root node changed
+        // undo property modification and verify that the hash
+        // of the root node is now the same as before the modification
         mk.commit("/test", "^\"booleanProp\":true", null, null);
         obj = parseJSONObject(mk.getNodes("/", null, 1, 0, -1, "{properties:[\"*\",\":hash\"]}"));
         assertPropertyValue(obj, "test/booleanProp", true);
@@ -599,6 +600,7 @@ public class MicroKernelIT extends Abstr
         // get all siblings in one call
         JSONObject obj = parseJSONObject(mk.getNodes("/testRoot", head, 0, 0, -1, null));
         assertPropertyValue(obj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertEquals(mk.getChildNodeCount("/testRoot", head), (long) NUM_SIBLINGS);
         assertEquals(siblingNames, getNodeNames(obj));
 
         // list of sibling names in iteration order
@@ -630,6 +632,80 @@ public class MicroKernelIT extends Abstr
             names.removeAll(subList);
             assertTrue(names.isEmpty());
         }
+
+        // test offset with filter
+        try {
+            parseJSONObject(mk.getNodes("/testRoot", head, 0, 10, NUM_SIBLINGS / 10, "{nodes:[\"n0*\"]}"));
+            fail();
+        } catch (Throwable e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void getNodesMaxNodeCount() {
+        // number of siblings
+        final int NUM_SIBLINGS = 100;
+
+        // populate siblings
+        StringBuffer sb = new StringBuffer("+\"/testRoot\":{");
+        for (int i = 0; i < NUM_SIBLINGS; i++) {
+            String name = "n" + i;
+            sb.append("\n\"");
+            sb.append(name);
+            sb.append("\":{");
+
+            for (int n = 0; n < NUM_SIBLINGS; n++) {
+                String childName = "n" + n;
+                sb.append("\n\"");
+                sb.append(childName);
+                sb.append("\":{}");
+                if (n < NUM_SIBLINGS - 1) {
+                    sb.append(',');
+                }
+            }
+            sb.append("}");
+            if (i < NUM_SIBLINGS - 1) {
+                sb.append(',');
+            }
+        }
+        sb.append("\n}");
+        String head = mk.commit("", sb.toString(), null, "");
+
+        // get all siblings
+        JSONObject obj = parseJSONObject(mk.getNodes("/testRoot", head, 1, 0, -1, null));
+        assertPropertyValue(obj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertEquals(mk.getChildNodeCount("/testRoot", head), (long) NUM_SIBLINGS);
+        Set<String> names = getNodeNames(obj);
+        assertTrue(names.size() == NUM_SIBLINGS);
+        String childName = names.iterator().next();
+        JSONObject childObj = resolveObjectValue(obj, childName);
+        assertPropertyValue(childObj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertTrue(getNodeNames(childObj).size() == NUM_SIBLINGS);
+
+        // get max 10 siblings
+        int maxSiblings = 10;
+        obj = parseJSONObject(mk.getNodes("/testRoot", head, 1, 0, maxSiblings, null));
+        assertPropertyValue(obj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertEquals(mk.getChildNodeCount("/testRoot", head), (long) NUM_SIBLINGS);
+        names = getNodeNames(obj);
+        assertTrue(names.size() == maxSiblings);
+        childName = names.iterator().next();
+        childObj = resolveObjectValue(obj, childName);
+        assertPropertyValue(childObj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertTrue(getNodeNames(childObj).size() == maxSiblings);
+
+        // get max 5 siblings using filter
+        maxSiblings = 5;
+        obj = parseJSONObject(mk.getNodes("/testRoot", head, 1, 0, maxSiblings, "{nodes:[\"n1*\"]}"));
+        assertPropertyValue(obj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertEquals(mk.getChildNodeCount("/testRoot", head), (long) NUM_SIBLINGS);
+        names = getNodeNames(obj);
+        assertTrue(names.size() == maxSiblings);
+        childName = names.iterator().next();
+        childObj = resolveObjectValue(obj, childName);
+        assertPropertyValue(childObj, ":childNodeCount", (long) NUM_SIBLINGS);
+        assertTrue(getNodeNames(childObj).size() == maxSiblings);
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java?rev=1342796&r1=1342795&r2=1342796&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
Fri May 25 20:20:25 2012
@@ -599,16 +599,17 @@ public class MicroKernelImpl implements 
                 }
             }
 
-            int count = maxChildNodes == -1 ? Integer.MAX_VALUE : maxChildNodes;
-            if (maxChildNodes != -1
+            int count = maxChildNodes;
+            if (count != -1
                     && filter != null
                     && filter.getChildNodeFilter() != null) {
                 // specific maxChildNodes limit and child node filter
-                maxChildNodes = -1;
+                count = -1;
             }
-            for (ChildNodeEntry entry : node.getChildNodeEntries(offset, maxChildNodes))
{
+            int numSiblings = 0;
+            for (ChildNodeEntry entry : node.getChildNodeEntries(offset, count)) {
                 if (filter == null || filter.includeNode(entry.getName())) {
-                    if (count-- <= 0) {
+                    if (maxChildNodes != -1 && ++numSiblings > maxChildNodes)
{
                         break;
                     }
                     builder.key(entry.getName()).object();



Mime
View raw message