jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1464417 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKDiffTest.java
Date Thu, 04 Apr 2013 10:20:49 GMT
Author: mreutegg
Date: Thu Apr  4 10:20:48 2013
New Revision: 1464417

URL: http://svn.apache.org/r1464417
Log:
OAK-619 Lock-free MongoMK implementation
- more MongoMK.diff() fixes
- Copied over and adapted MongoMKDiffTest from initial MongoDB based MicroKernel implementation

Added:
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKDiffTest.java
      - copied, changed from r1464339, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKDiffTest.java
Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java?rev=1464417&r1=1464416&r2=1464417&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
Thu Apr  4 10:20:48 2013
@@ -573,6 +573,9 @@ public class MongoMK implements MicroKer
         if (depth != 0) {
             throw new MicroKernelException("Only depth 0 is supported, depth is " + depth);
         }
+        if (path == null || path.equals("")) {
+            path = "/";
+        }
         fromRevisionId = stripBranchRevMarker(fromRevisionId);
         toRevisionId = stripBranchRevMarker(toRevisionId);
         Node from = getNode(path, Revision.fromString(fromRevisionId));
@@ -587,13 +590,18 @@ public class MongoMK implements MicroKer
             String fromValue = from.getProperty(p);
             String toValue = to.getProperty(p);
             if (!fromValue.equals(toValue)) {
-                w.tag('^').key(p).value(toValue).newline();
+                w.tag('^').key(p);
+                if (toValue == null) {
+                    w.value(toValue);
+                } else {
+                    w.encodedValue(toValue).newline();
+                }
             }
         }
         for (String p : to.getPropertyNames()) {
             // added properties
             if (from.getProperty(p) == null) {
-                w.tag('^').key(p).value(to.getProperty(p)).newline();
+                w.tag('^').key(p).encodedValue(to.getProperty(p)).newline();
             }
         }
         Revision fromRev = Revision.fromString(fromRevisionId);
@@ -605,7 +613,7 @@ public class MongoMK implements MicroKer
         Set<String> childrenSet = new HashSet<String>(toChildren.children);
         for (String n : fromChildren.children) {
             if (!childrenSet.contains(n)) {
-                w.tag('-').key(n).newline();
+                w.tag('-').value(n).newline();
             } else {
                 Node n1 = getNode(n, fromRev);
                 Node n2 = getNode(n, toRev);

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKDiffTest.java
(from r1464339, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKDiffTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKDiffTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKDiffTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKDiffTest.java&r1=1464339&r2=1464417&rev=1464417&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKDiffTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKDiffTest.java
Thu Apr  4 10:20:48 2013
@@ -14,10 +14,10 @@
  * 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.prototype;
 
-import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
 import org.json.simple.JSONObject;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertFalse;
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTru
 /**
  * Tests for MicroKernel#diff
  */
-public class MongoMKDiffTest extends BaseMongoMicroKernelTest {
+public class MongoMKDiffTest extends BaseMongoMKTest {
 
     @Test
     public void oak_596() {
@@ -35,8 +35,8 @@ public class MongoMKDiffTest extends Bas
         String rev2 = mk.commit("/", "^\"node1/node2/prop1\":\"val1 new\" ^\"node1/node2/prop2\":null",
null, null);
 
         String diff = mk.diff(rev1, rev2, "/node1/node2", 0);
-        assertTrue(diff.contains("^\"/node1/node2/prop2\":null"));
-        assertTrue(diff.contains("^\"/node1/node2/prop1\":\"val1 new\""));
+        assertTrue(diff.contains("^\"prop2\":null"));
+        assertTrue(diff.contains("^\"prop1\":\"val1 new\""));
     }
 
     @Test
@@ -46,7 +46,7 @@ public class MongoMKDiffTest extends Bas
         String rev1 = mk.commit("/", "+\"level1\":{}", null, null);
         assertTrue(mk.nodeExists("/level1", null));
 
-        String reverseDiff = mk.diff(rev1, rev0, null, -1);
+        String reverseDiff = mk.diff(rev1, rev0, null, 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -63,7 +63,7 @@ public class MongoMKDiffTest extends Bas
         assertTrue(mk.nodeExists("/level1", null));
         assertTrue(mk.nodeExists("/level1/level2", null));
 
-        String reverseDiff = mk.diff(rev1, rev0, null, -1);
+        String reverseDiff = mk.diff(rev1, rev0, null, 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -81,7 +81,7 @@ public class MongoMKDiffTest extends Bas
         assertTrue(mk.nodeExists("/level1a", null));
         assertTrue(mk.nodeExists("/level1b", null));
 
-        String reverseDiff = mk.diff(rev1, rev0, null, -1);
+        String reverseDiff = mk.diff(rev1, rev0, null, 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -91,6 +91,7 @@ public class MongoMKDiffTest extends Bas
     }
 
     @Test
+    @Ignore("New MongoMK only supports depth 0")
     public void removePath() {
         // Add level1 & level1/level2
         String rev0 = mk.commit("/","+\"level1\":{}" +
@@ -104,7 +105,7 @@ public class MongoMKDiffTest extends Bas
         assertFalse(mk.nodeExists("/level1/level2", null));
 
         // Generate reverseDiff from rev1 to rev0
-        String reverseDiff = mk.diff(rev1, rev0, null, -1);
+        String reverseDiff = mk.diff(rev1, rev0, "/level1", 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -113,13 +114,13 @@ public class MongoMKDiffTest extends Bas
         assertTrue(mk.nodeExists("/level1", null));
         assertTrue(mk.nodeExists("/level1/level2", null));
 
-        // Remove level1 at rev0
-        String rev2 = mk.commit("/", "-\"level1\"", rev0, null);
+        // Remove level1
+        String rev2 = mk.commit("/", "-\"level1\"", null, null);
         assertFalse(mk.nodeExists("/level1", null));
         assertFalse(mk.nodeExists("/level1/level2", null));
 
         // Generate reverseDiff from rev2 to rev0
-        reverseDiff = mk.diff(rev2, rev0, null, -1);
+        reverseDiff = mk.diff(rev2, rev0, null, 1);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -130,6 +131,7 @@ public class MongoMKDiffTest extends Bas
     }
 
     @Test
+    @Ignore("New MongoMK only supports depth 0")
     public void movePath() {
         String rev1 = mk.commit("/", "+\"level1\":{}", null, null);
         rev1 = mk.commit("/", "+\"level1/level2\":{}", null, null);
@@ -141,7 +143,7 @@ public class MongoMKDiffTest extends Bas
         assertTrue(mk.nodeExists("/level1new", null));
         assertTrue(mk.nodeExists("/level1new/level2", null));
 
-        String reverseDiff = mk.diff(rev2, rev1, null, -1);
+        String reverseDiff = mk.diff(rev2, rev1, null, 1);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -164,7 +166,7 @@ public class MongoMKDiffTest extends Bas
         assertTrue(mk.nodeExists("/level1new", null));
         assertTrue(mk.nodeExists("/level1new/level2", null));
 
-        String reverseDiff = mk.diff(rev2, rev1, null, -1);
+        String reverseDiff = mk.diff(rev2, rev1, null, 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -182,18 +184,18 @@ public class MongoMKDiffTest extends Bas
 
         // Add property.
         String rev1 = mk.commit("/", "^\"level1/prop1\": \"value1\"", null, null);
-        JSONObject obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        JSONObject obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyExists(obj, "prop1");
 
         // Generate reverseDiff from rev1 to rev0
-        String reverseDiff = mk.diff(rev1, rev0, null, -1);
+        String reverseDiff = mk.diff(rev1, rev0, "/level1", 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
         // Commit the reverseDiff and check property is gone.
-        mk.commit("", reverseDiff, null, null);
+        mk.commit("/level1", reverseDiff, null, null);
         assertTrue(mk.nodeExists("/level1", null));
-        obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyNotExists(obj, "prop1");
     }
 
@@ -201,23 +203,23 @@ public class MongoMKDiffTest extends Bas
     public void removeProperty() {
         String rev0 = mk.commit("/", "+\"level1\":{ \"prop1\" : \"value\"}", null, null);
         assertTrue(mk.nodeExists("/level1", null));
-        JSONObject obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        JSONObject obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyExists(obj, "prop1");
 
         // Remove property
         String rev1 = mk.commit("/", "^\"level1/prop1\" : null", null, null);
         assertTrue(mk.nodeExists("/level1", null));
-        obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyNotExists(obj, "prop1");
 
         // Generate reverseDiff from rev1 to rev0
-        String reverseDiff = mk.diff(rev1, rev0, null, -1);
+        String reverseDiff = mk.diff(rev1, rev0, "/level1", 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
         // Commit the reverseDiff and check property is added back.
-        mk.commit("", reverseDiff, null, null);
-        obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        mk.commit("/level1", reverseDiff, null, null);
+        obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyExists(obj, "prop1");
     }
 
@@ -225,22 +227,22 @@ public class MongoMKDiffTest extends Bas
     public void changeProperty() {
         String rev0 = mk.commit("/", "+\"level1\":{ \"prop1\" : \"value1\"}", null, null);
         assertTrue(mk.nodeExists("/level1", null));
-        JSONObject obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        JSONObject obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyValue(obj, "prop1", "value1");
 
         // Change property
         String rev1 = mk.commit("/", "^\"level1/prop1\" : \"value2\"", null, null);
-        obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyValue(obj, "prop1", "value2");
 
         // Generate reverseDiff from rev1 to rev0
-        String reverseDiff = mk.diff(rev1, rev0, null, -1);
+        String reverseDiff = mk.diff(rev1, rev0, "/level1", 0);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
         // Commit the reverseDiff and check property is set back.
-        mk.commit("", reverseDiff, null, null);
-        obj = parseJSONObject(mk.getNodes("/level1", null, 1, 0, -1, null));
+        mk.commit("/level1", reverseDiff, null, null);
+        obj = parseJSONObject(mk.getNodes("/level1", null, 0, 0, -1, null));
         assertPropertyValue(obj, "prop1", "value1");
     }
 }
\ No newline at end of file



Mime
View raw message