jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1433302 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/impl/action/ test/java/org/apache/jackrabbit/mongomk/impl/action/
Date Tue, 15 Jan 2013 07:54:36 GMT
Author: meteatamel
Date: Tue Jan 15 07:54:35 2013
New Revision: 1433302

URL: http://svn.apache.org/viewvc?rev=1433302&view=rev
Log:
OAK-555 - FetchNodesAction with unlimited depth and same path prefix returns wrong nodes 

Fixed the regex for fetching nodes with depth = -1

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesAction.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesAction.java?rev=1433302&r1=1433301&r2=1433302&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesAction.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesAction.java
Tue Jan 15 07:54:35 2013
@@ -161,24 +161,19 @@ public class FetchNodesAction extends Ba
     }
 
     private Pattern createPrefixRegExp(String path) {
-        StringBuilder sb = new StringBuilder();
-        String quotedPath = Pattern.quote(path);
-
-        if (depth < 0) {
-            sb.append("^");
-            sb.append(quotedPath);
-        } else if (depth > 0) {
-            sb.append("^");
-            if (!"/".equals(path)) {
-                sb.append(quotedPath);
-            }
-            sb.append("(/[^/]*)");
-            sb.append("{0,");
-            sb.append(depth);
-            sb.append("}$");
+        StringBuilder regex = new StringBuilder();
+        regex.append("^");
+        if (!"/".equals(path)) {
+            regex.append(Pattern.quote(path));
+        }
+        regex.append("(/[^/]*)");
+        regex.append("{0,");
+        if (depth > 0) {
+            regex.append(depth);
         }
+        regex.append("}$");
 
-        return Pattern.compile(sb.toString());
+        return Pattern.compile(regex.toString());
     }
 
     private Map<String, MongoNode> getMostRecentValidNodes(DBCursor dbCursor) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java?rev=1433302&r1=1433301&r2=1433302&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionNew.java
Tue Jan 15 07:54:35 2013
@@ -166,24 +166,19 @@ public class FetchNodesActionNew extends
     }
 
     private Pattern createPrefixRegExp(String path) {
-        StringBuilder sb = new StringBuilder();
-        String quotedPath = Pattern.quote(path);
-
-        if (depth < 0) {
-            sb.append("^");
-            sb.append(quotedPath);
-        } else if (depth > 0) {
-            sb.append("^");
-            if (!"/".equals(path)) {
-                sb.append(quotedPath);
-            }
-            sb.append("(/[^/]*)");
-            sb.append("{0,");
-            sb.append(depth);
-            sb.append("}$");
+        StringBuilder regex = new StringBuilder();
+        regex.append("^");
+        if (!"/".equals(path)) {
+            regex.append(Pattern.quote(path));
+        }
+        regex.append("(/[^/]*)");
+        regex.append("{0,");
+        if (depth > 0) {
+            regex.append(depth);
         }
+        regex.append("}$");
 
-        return Pattern.compile(sb.toString());
+        return Pattern.compile(regex.toString());
     }
 
     private Map<String, MongoNode> getMostRecentValidNodes(DBCursor dbCursor) {

Modified: 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=1433302&r1=1433301&r2=1433302&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/action/FetchNodesActionTest.java
Tue Jan 15 07:54:35 2013
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.mongomk.impl.action;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -90,6 +94,36 @@ public class FetchNodesActionTest extend
         NodeAssert.assertEquals(expecteds, actuals);
     }
 
+    @Test
+    public void samePrefix() throws Exception {
+        addNode("a");
+        addNode("a/b");
+        addNode("a/bb");
+        long rev = addNode("a/b/c");
+
+        int depth = 0;
+        FetchNodesActionNew action = new FetchNodesActionNew(getNodeStore(),
+                "/a/b", depth, rev);
+        Map<String, MongoNode> nodes = action.execute();
+        assertEquals(1, nodes.size());
+        assertNotNull(nodes.get("/a/b"));
+
+        depth = 1;
+        action = new FetchNodesActionNew(getNodeStore(), "/a/b", depth, rev);
+        nodes = action.execute();
+        assertEquals(2, nodes.size());
+        assertNotNull(nodes.get("/a/b"));
+        assertNotNull(nodes.get("/a/b/c"));
+
+        depth = FetchNodesActionNew.LIMITLESS_DEPTH;
+        action = new FetchNodesActionNew(getNodeStore(), "/a/b", depth, rev);
+        nodes = action.execute();
+        assertEquals(2, nodes.size());
+        assertNotNull(nodes.get("/a/b"));
+        assertNotNull(nodes.get("/a/b/c"));
+        assertNull(nodes.get("/a/bb"));
+    }
+
     // FIXME - Revisit this test.
     @Test
     public void fetchRootAndAllDepths() throws Exception {



Mime
View raw message