jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1443367 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/impl/command/ main/java/org/apache/jackrabbit/mongomk/impl/json/ test/java/org/apache/jackrabbit/mongomk/impl/
Date Thu, 07 Feb 2013 09:35:39 GMT
Author: meteatamel
Date: Thu Feb  7 09:35:39 2013
New Revision: 1443367

URL: http://svn.apache.org/viewvc?rev=1443367&view=rev
Log:
OAK-611 - GetJournalCommand does not take path into account

-Added path to NormalizingJsopHandler so it can normalize against any path not just root path.
-Updated GetJournalCommand to normalize diffs
-Added tests in MongoMKGetJournalTest

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/NormalizingJsopHandler.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKGetJournalTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java?rev=1443367&r1=1443366&r2=1443367&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/GetJournalCommand.java
Thu Feb  7 09:35:39 2013
@@ -25,6 +25,8 @@ import org.apache.jackrabbit.mongomk.api
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
 import org.apache.jackrabbit.mongomk.impl.action.FetchCommitsAction;
 import org.apache.jackrabbit.mongomk.impl.action.FetchHeadRevisionIdAction;
+import org.apache.jackrabbit.mongomk.impl.json.JsopParser;
+import org.apache.jackrabbit.mongomk.impl.json.NormalizingJsopHandler;
 import org.apache.jackrabbit.mongomk.impl.model.MongoCommit;
 import org.apache.jackrabbit.mongomk.impl.model.tree.SimpleMongoNodeStore;
 import org.apache.jackrabbit.mongomk.util.MongoUtil;
@@ -106,7 +108,10 @@ public class GetJournalCommand extends B
                 } catch (Exception e) {
                     throw new MicroKernelException(e);
                 }
+            } else {
+                diff = normalizeDiff(commit.getPath(), diff);
             }
+
             commitBuff.object()
             .key("id").value(MongoUtil.fromMongoRepresentation(commit.getRevisionId()))
             .key("ts").value(commit.getTimestamp())
@@ -135,4 +140,11 @@ public class GetJournalCommand extends B
     private Node getNode(String path, long revisionId) throws Exception {
         return new GetNodesCommand(nodeStore, path, revisionId).execute();
     }
+
+    private String normalizeDiff(String path, String diff) throws Exception {
+        // Need to normalize against empty path in journal diffs.
+        NormalizingJsopHandler handler = new NormalizingJsopHandler("");
+        new JsopParser(path, diff, handler).parse();
+        return handler.getDiff();
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/NormalizingJsopHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/NormalizingJsopHandler.java?rev=1443367&r1=1443366&r2=1443367&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/NormalizingJsopHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/NormalizingJsopHandler.java
Thu Feb  7 09:35:39 2013
@@ -29,15 +29,21 @@ import org.apache.jackrabbit.oak.commons
 public class NormalizingJsopHandler extends DefaultJsopHandler {
 
     private final StringBuilder builder = new StringBuilder();
+    private final Deque<String> commaStack = new ArrayDeque<String>(Collections.singleton(""));
+    private final Deque<String> pathStack;
+    private final String path;
 
-    private Deque<String> commaStack = new ArrayDeque<String>(
-            Collections.singleton(""));
+    public NormalizingJsopHandler() {
+        this("/");
+    }
 
-    private Deque<String> pathStack = new ArrayDeque<String>(
-            Collections.singleton("/"));
+    public NormalizingJsopHandler(String path) {
+        this.path = path;
+        pathStack = new ArrayDeque<String>(Collections.singleton(path));
+    }
 
     public String getDiff() {
-        scopeFor("/");
+        scopeFor(path);
         return builder.toString();
     }
 
@@ -62,27 +68,27 @@ public class NormalizingJsopHandler exte
     public void nodeCopied(String rootPath,
                            String oldPath,
                            String newPath) {
-        scopeFor("/");
+        scopeFor(path);
         builder.append("*");
-        builder.append(JsopBuilder.encode(PathUtils.relativize("/", oldPath)));
+        builder.append(JsopBuilder.encode(relativize(path, oldPath)));
         builder.append(":");
-        builder.append(JsopBuilder.encode(PathUtils.relativize("/", newPath)));
+        builder.append(JsopBuilder.encode(relativize(path, newPath)));
     }
 
     @Override
     public void nodeMoved(String rootPath, String oldPath, String newPath) {
-        scopeFor("/");
+        scopeFor(path);
         builder.append(">");
-        builder.append(JsopBuilder.encode(PathUtils.relativize("/", oldPath)));
+        builder.append(JsopBuilder.encode(relativize(path, oldPath)));
         builder.append(":");
-        builder.append(JsopBuilder.encode(PathUtils.relativize("/", newPath)));
+        builder.append(JsopBuilder.encode(relativize(path, newPath)));
     }
 
     @Override
     public void nodeRemoved(String parentPath, String name) {
-        scopeFor("/");
+        scopeFor(path);
         builder.append("-");
-        builder.append(JsopBuilder.encode(PathUtils.relativize("/", concatPath(parentPath,
name))));
+        builder.append(JsopBuilder.encode(relativize(path, concatPath(parentPath, name))));
     }
 
     @Override
@@ -114,7 +120,7 @@ public class NormalizingJsopHandler exte
             builder.append("}");
         }
         // remaining path for scope
-        return PathUtils.relativize(getCurrentPath(), path);
+        return relativize(getCurrentPath(), path);
     }
 
     private String getCurrentPath() {
@@ -142,4 +148,8 @@ public class NormalizingJsopHandler exte
         builder.append(commaStack.removeLast());
         commaStack.addLast(",");
     }
-}
+
+    private String relativize(String parentPath, String path) {
+        return parentPath.isEmpty()? path : PathUtils.relativize(parentPath, path);
+    }
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKGetJournalTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKGetJournalTest.java?rev=1443367&r1=1443366&r2=1443367&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKGetJournalTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKGetJournalTest.java
Thu Feb  7 09:35:39 2013
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertEqu
 import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -31,11 +30,11 @@ public class MongoMKGetJournalTest exten
 
     @Test
     public void simple() throws Exception {
-        String fromDiff = "+\"/a\" : {}";
+        String fromDiff = "+\"/a\":{}";
         String fromMsg = "Add /a";
         String fromRev = mk.commit("", fromDiff, null, fromMsg);
 
-        String toDiff = "+\"/b\" : {}";
+        String toDiff = "+\"/b\":{}";
         String toMsg = "Add /b";
         String toRev = mk.commit("", toDiff, null, toMsg);
 
@@ -56,9 +55,8 @@ public class MongoMKGetJournalTest exten
     }
 
     @Test
-    @Ignore("OAK-611")
-    public void emptyAndRootPath() {
-        // Commit with empty path
+    public void commitAddWithDiffPaths() {
+        // Commit with empty path and retrieve with root path
         String rev = mk.commit("", "+\"/a\":{}", null, "");
         String journalStr = mk.getJournal(rev, rev, "/");
         JSONArray array = parseJSONArray(journalStr);
@@ -66,12 +64,152 @@ public class MongoMKGetJournalTest exten
         String expected = "+\"/a\":{}";
         assertPropertyValue(entry, "changes", expected);
 
-        // Commit with root path
+        // Commit with root path and retrieve with root path
         rev = mk.commit("/", "+\"b\":{}", null, "");
         journalStr = mk.getJournal(rev, rev, "/");
         array = parseJSONArray(journalStr);
         entry = getObjectArrayEntry(array, 0);
         expected = "+\"/b\":{}";
         assertPropertyValue(entry, "changes", expected);
+
+        // Commit with /b path and retrieve with root path
+        rev = mk.commit("/b", "+\"c\":{}", null, "");
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "+\"/b/c\":{}";
+        assertPropertyValue(entry, "changes", expected);
+
+        // Commit with /b/c path and retrieve with root path
+        rev = mk.commit("/b/c", "+\"d\":{}", null, "");
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "+\"/b/c/d\":{}";
+        assertPropertyValue(entry, "changes", expected);
+    }
+
+    @Test
+    public void commitCopyWithDiffPaths() {
+        mk.commit("", "+\"/a\":{}", null, "");
+
+        // Commit with empty path and retrieve with root path
+        String rev = mk.commit("", "*\"/a\" : \"/b\"", null, null);
+        String journalStr = mk.getJournal(rev, rev, "/");
+        JSONArray array = parseJSONArray(journalStr);
+        JSONObject entry = getObjectArrayEntry(array, 0);
+        String expected = "*\"/a\":\"/b\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        // Commit with root path and retrieve with root path
+        rev = mk.commit("/", "*\"b\" : \"c\"", null, null);
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "*\"/b\":\"/c\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        mk.commit("", "+\"/b/d\":{}", null, "");
+
+        // Commit with /b path and retrieve with root path
+        rev = mk.commit("/b", "*\"d\" : \"e\"", null, null);
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "*\"/b/d\":\"/b/e\"";
+        assertPropertyValue(entry, "changes", expected);
+    }
+
+    @Test
+    public void commitMoveWithDiffPaths() {
+        mk.commit("", "+\"/a\":{}", null, "");
+
+        // Commit with empty path and retrieve with root path
+        String rev = mk.commit("", ">\"/a\" : \"/b\"", null, null);
+        String journalStr = mk.getJournal(rev, rev, "/");
+        JSONArray array = parseJSONArray(journalStr);
+        JSONObject entry = getObjectArrayEntry(array, 0);
+        String expected = ">\"/a\":\"/b\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        // Commit with root path and retrieve with root path
+        rev = mk.commit("/", ">\"b\" : \"c\"", null, null);
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = ">\"/b\":\"/c\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        mk.commit("", "+\"/b/d\":{}", null, "");
+
+        // Commit with /b path and retrieve with root path
+        rev = mk.commit("/b", ">\"d\" : \"e\"", null, null);
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = ">\"/b/d\":\"/b/e\"";
+        assertPropertyValue(entry, "changes", expected);
+    }
+
+    @Test
+    public void commitRemoveMoveWithDiffPaths() {
+        mk.commit("", "+\"/a\":{}", null, "");
+
+        // Commit with empty path and retrieve with root path
+        String rev = mk.commit("", "-\"/a\"", null, null);
+        String journalStr = mk.getJournal(rev, rev, "/");
+        JSONArray array = parseJSONArray(journalStr);
+        JSONObject entry = getObjectArrayEntry(array, 0);
+        String expected = "-\"/a\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        mk.commit("", "+\"/b\":{}", null, "");
+
+        // Commit with root path and retrieve with root path
+        rev = mk.commit("", "-\"/b\"", null, null);
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "-\"/b\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        mk.commit("", "+\"/b\":{\"c\" : {}}", null, "");
+
+        // Commit with /b path and retrieve with root path
+        rev = mk.commit("/b", "-\"c\"", null, null);
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "-\"/b/c\"";
+        assertPropertyValue(entry, "changes", expected);
+    }
+
+    @Test
+    public void commitSetPropertyWithDiffPaths() {
+        mk.commit("", "+\"/a\":{}", null, "");
+
+        // Commit with empty path and retrieve with root path
+        String rev = mk.commit("", "^\"/a/key1\" : \"value1\"", null, null);
+        String journalStr = mk.getJournal(rev, rev, "/");
+        JSONArray array = parseJSONArray(journalStr);
+        JSONObject entry = getObjectArrayEntry(array, 0);
+        String expected = "^\"/a/key1\":\"value1\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        // Commit with root path and retrieve with root path
+        rev = mk.commit("/", "^\"a/key2\" : \"value2\"", null, null);
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "^\"/a/key2\":\"value2\"";
+        assertPropertyValue(entry, "changes", expected);
+
+        // Commit with /a path and retrieve with root path
+        rev = mk.commit("/a", "^\"key3\": \"value3\"", null, "");
+        journalStr = mk.getJournal(rev, rev, "/");
+        array = parseJSONArray(journalStr);
+        entry = getObjectArrayEntry(array, 0);
+        expected = "^\"/a/key3\":\"value3\"";
+        assertPropertyValue(entry, "changes", expected);
     }
 }
\ No newline at end of file



Mime
View raw message