You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2013/03/28 12:24:59 UTC

svn commit: r1462046 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java test/java/org/apache/jackrabbit/mongomk/prototype/RandomizedTest.java

Author: thomasm
Date: Thu Mar 28 11:24:59 2013
New Revision: 1462046

URL: http://svn.apache.org/r1462046
Log:
OAK-619 MongoMK: a simple randomized test case and related bugfixes

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/RandomizedTest.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=1462046&r1=1462045&r2=1462046&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 Mar 28 11:24:59 2013
@@ -721,6 +721,12 @@ public class MongoMK implements MicroKer
                 if (!PathUtils.isAbsolute(targetPath)) {
                     targetPath = PathUtils.concat(rootPath, targetPath);
                 }
+                if (!nodeExists(sourcePath, baseRevId)) {
+                    throw new MicroKernelException("Node not found: " + sourcePath + " in revision " + baseRevId);
+                }
+                if (nodeExists(targetPath, baseRevId)) {
+                    throw new MicroKernelException("Node already exists: " + targetPath + " in revision " + baseRevId);
+                }
                 commit.moveNode(sourcePath, targetPath);
                 moveNode(sourcePath, targetPath, baseRev, commit);
                 break;
@@ -733,6 +739,9 @@ public class MongoMK implements MicroKer
                 if (!PathUtils.isAbsolute(targetPath)) {
                     targetPath = PathUtils.concat(rootPath, targetPath);
                 }
+                if (!nodeExists(sourcePath, baseRevId)) {
+                    throw new MicroKernelException("Node not found: " + sourcePath + " in revision " + baseRevId);
+                }
                 commit.copyNode(sourcePath, targetPath);
                 copyNode(sourcePath, targetPath, baseRev, commit);
                 break;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/RandomizedTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/RandomizedTest.java?rev=1462046&r1=1462045&r2=1462046&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/RandomizedTest.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/RandomizedTest.java Thu Mar 28 11:24:59 2013
@@ -44,40 +44,67 @@ public class RandomizedTest {
     private MicroKernelImpl mkGold;
     
     @Test
-    public void addRemoveSet() throws Exception {
+    public void addRemoveSetMoveCopy() throws Exception {
         mk = createMK();
         mkGold = new MicroKernelImpl();
         Random r = new Random(1);
-        int opCount = 1000, nodeCount = 10;
+        int operations = 1000, nodeCount = 10;
         int propertyCount = 5, valueCount = 10;
         StringBuilder log = new StringBuilder();
         try {
-            for (int i = 0; i < opCount; i++) {
+            int maskOk = 0, maskFail = 0;
+            int opCount = 5;
+            for (int i = 0; i < operations; i++) {
                 String node = "t" + r.nextInt(nodeCount);
+                String node2 = "t" + r.nextInt(nodeCount);
                 String property = "p" + r.nextInt(propertyCount);
                 String value = "" + r.nextInt(valueCount);
                 String diff;
-                int op = r.nextInt(3);
+                int op = r.nextInt(opCount);
+                boolean result;
                 switch(op) {
                 case 0:
                     diff = "+ \"" + node + "\": { \"" + property + "\": " + value + "}";
                     log.append(diff).append('\n');
-                    commit(diff);
+                    result = commit(diff);
                     break;
                 case 1:
                     diff = "- \"" + node + "\"";
                     log.append(diff).append('\n');
-                    commit(diff);
+                    result = commit(diff);
                     break;
                 case 2:
                     diff = "^ \"" + node + "/" + property + "\": " + value;
                     log.append(diff).append('\n');
-                    commit(diff);
+                    result = commit(diff);
                     break;
                 case 3:
+                    diff = "> \"" + node + "\": \"" + node2 + "\"";
+                    log.append(diff).append('\n');
+                    result = commit(diff);
+                    break;
+                case 4:
+                    diff = "* \"" + node + "\": \"" + node2 + "\"";
+                    log.append(diff).append('\n');
+                    result = commit(diff);
+                    break;
+                default:
                     fail();
+                    result = false;
+                }
+                if (result) {
+                    maskOk |= 1 << op;
+                } else {
+                    maskFail |= 1 << op;
                 }
                 get(node);
+                get(node2);
+            }
+            if (Integer.bitCount(maskOk) != opCount) {
+                fail("Not all operations were at least once successful: " + Integer.toBinaryString(maskOk));
+            }
+            if (Integer.bitCount(maskFail) != opCount) {
+                fail("Not all operations failed at least once: " + Integer.toBinaryString(maskFail));
             }
         } catch (AssertionError e) {
             throw new Exception("log: " + log, e);
@@ -113,7 +140,7 @@ public class RandomizedTest {
         return w.toString();
     }
 
-    private void commit(String diff) {
+    private boolean commit(String diff) {
         boolean ok = false;
         try {
             mkGold.commit("/", diff, null, null);
@@ -129,6 +156,7 @@ public class RandomizedTest {
         if (ok) {
             mk.commit("/", diff, null, null);
         }
+        return ok;
     }
     
     private static MongoMK createMK() {