jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1153124 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
Date Tue, 02 Aug 2011 13:45:45 GMT
Author: thomasm
Date: Tue Aug  2 13:45:44 2011
New Revision: 1153124

URL: http://svn.apache.org/viewvc?rev=1153124&view=rev
Log:
Verify the journal for move operations.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1153124&r1=1153123&r2=1153124&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Tue Aug  2 13:45:44 2011
@@ -116,6 +116,7 @@ public class MemoryKernelImpl implements
                 path = t.readString();
                 w.append("- ").key(PathUtils.concat(rootPath, path));
                 headRoot = headRoot.cloneAndRemoveChildNode(PathUtils.concat(fromRoot, path),
headRevId);
+                w.append("\n");
                 break;
             case '^':
                 path = t.readString();
@@ -143,6 +144,7 @@ public class MemoryKernelImpl implements
                 path = t.readString();
                 String from = PathUtils.concat(fromRoot, path);
                 String name = PathUtils.getName(from);
+                w.append("> ").key(PathUtils.concat(rootPath, from));
                 t.read(':');
                 String position, target;
                 boolean rename;
@@ -153,11 +155,24 @@ public class MemoryKernelImpl implements
                     t.read(':');
                     target = t.readString();
                     t.read('}');
+                    w.object().key(position);
+                    if (PathUtils.isAbsolute(target)) {
+                        w.value(target);
+                    } else {
+                        w.value(PathUtils.concat(rootPath, target));
+                    }
+                    w.endObject();
                 } else {
                     rename = true;
                     position = null;
                     target = t.readString();
+                    if (PathUtils.isAbsolute(target)) {
+                        w.value(target);
+                    } else {
+                        w.value(PathUtils.concat(rootPath, target));
+                    }
                 }
+                w.append("\n");
                 boolean before = false;
                 if ("last".equals(position)) {
                     target = PathUtils.concat(target, name);

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java?rev=1153124&r1=1153123&r2=1153124&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
Tue Aug  2 13:45:44 2011
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.mk;
 
 import junit.framework.TestCase;
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.json.JsopTokenizer;
 
 /**
  * Test moving nodes.
@@ -30,15 +31,14 @@ public class MoveNodeTest extends TestCa
     private MicroKernel mk;
 
     private String head;
+    private String journalRevision;
 
     public void setUp() throws Exception {
         mk = MicroKernelFactory.getInstance(URL);
         head = mk.getHeadRevision();
         commit("/", "+ \"test\": {\"a\":{}, \"b\":{}, \"c\":{}}");
         commit("/", "+ \"test2\": {}");
-
-        int todoTestJournal;
-
+        getJournal();
     }
 
     public void tearDown() throws InterruptedException {
@@ -53,30 +53,40 @@ public class MoveNodeTest extends TestCa
         // rename /test/b
         commit("/", "> \"test/b\": \"test/b1\"");
         assertEquals("{a,b1,c}", getNode("/test"));
+        assertJournal("> \"/test/b\":\"/test/b1\"");
         // and back
         commit("/", "> \"test/b1\": \"test/b\"");
         assertEquals("{a,b,c}", getNode("/test"));
+        assertJournal("> \"/test/b1\":\"/test/b\"");
     }
 
     public void testReorderBefore() {
         // order c before b
         commit("/", "> \"test/c\": {\"before\": \"test/b\"}");
         assertEquals("{a,c,b}", getNode("/test"));
+        assertJournal("> \"/test/c\":{\"before\":\"/test/b\"}");
+
         // and now b before a
         commit("/", "> \"test/b\": {\"before\": \"test/a\"}");
         assertEquals("{b,a,c}", getNode("/test"));
+        assertJournal("> \"/test/b\":{\"before\":\"/test/a\"}");
     }
 
     public void testReorderAfter() {
         // order a after b
         commit("/", "> \"test/a\": {\"after\": \"test/b\"}");
         assertEquals("{b,a,c}", getNode("/test"));
+        assertJournal("> \"/test/a\":{\"after\":\"/test/b\"}");
+
         // and now a after c
         commit("/", "> \"test/a\": {\"after\": \"test/c\"}");
         assertEquals("{b,c,a}", getNode("/test"));
+        assertJournal("> \"/test/a\":{\"after\":\"/test/c\"}");
+
         // and now a after a (a no-op)
         commit("/", "> \"test/a\": {\"after\": \"test/a\"}");
         assertEquals("{b,c,a}", getNode("/test"));
+        assertJournal("> \"/test/a\":{\"after\":\"/test/a\"}");
     }
 
     public void testMoveFirst() {
@@ -84,10 +94,13 @@ public class MoveNodeTest extends TestCa
         commit("/", "> \"test/a\": {\"first\": \"test2\"}");
         assertEquals("{b,c}", getNode("/test"));
         assertEquals("{a}", getNode("/test2"));
+        assertJournal("> \"/test/a\":{\"first\":\"/test2\"}");
+
         // move /test/c to /test2
         commit("/", "> \"test/c\": {\"first\": \"test2\"}");
         assertEquals("{b}", getNode("/test"));
         assertEquals("{c,a}", getNode("/test2"));
+        assertJournal("> \"/test/c\":{\"first\":\"/test2\"}");
     }
 
     public void testMoveBefore() {
@@ -95,10 +108,13 @@ public class MoveNodeTest extends TestCa
         commit("/", "> \"test/b\": {\"first\": \"test2\"}");
         assertEquals("{a,c}", getNode("/test"));
         assertEquals("{b}", getNode("/test2"));
+        assertJournal("> \"/test/b\":{\"first\":\"/test2\"}");
+
         // move /test/c to /test2, before b
         commit("/", "> \"test/c\": {\"before\": \"test2/b\"}");
         assertEquals("{a}", getNode("/test"));
         assertEquals("{c,b}", getNode("/test2"));
+        assertJournal("> \"/test/c\":{\"before\":\"/test2/b\"}");
     }
 
     public void testMoveAfter() {
@@ -106,14 +122,19 @@ public class MoveNodeTest extends TestCa
         commit("/", "> \"test/c\": \"test2/c\"");
         assertEquals("{a,b}", getNode("/test"));
         assertEquals("{c}", getNode("/test2"));
+        assertJournal("> \"/test/c\":\"/test2/c\"");
+
         // move /test/a to /test2, after c
         commit("/", "> \"test/a\": {\"after\": \"test2/c\"}");
         assertEquals("{b}", getNode("/test"));
         assertEquals("{c,a}", getNode("/test2"));
+        assertJournal("> \"/test/a\":{\"after\":\"/test2/c\"}");
+
         // move /test/b to /test2, after c
         commit("/", "> \"test/b\": {\"after\": \"test2/c\"}");
         assertEquals("{}", getNode("/test"));
         assertEquals("{c,b,a}", getNode("/test2"));
+        assertJournal("> \"/test/b\":{\"after\":\"/test2/c\"}");
     }
 
     public void testMoveLast() {
@@ -121,10 +142,13 @@ public class MoveNodeTest extends TestCa
         commit("/", "> \"test/b\": {\"last\": \"test2\"}");
         assertEquals("{a,c}", getNode("/test"));
         assertEquals("{b}", getNode("/test2"));
+        assertJournal("> \"/test/b\":{\"last\":\"/test2\"}");
+
         // move /test/c to /test2, as last
         commit("/", "> \"test/c\": {\"last\": \"test2\"}");
         assertEquals("{a}", getNode("/test"));
         assertEquals("{b,c}", getNode("/test2"));
+        assertJournal("> \"/test/c\":{\"last\":\"/test2\"}");
     }
 
     public void testMove() {
@@ -132,14 +156,19 @@ public class MoveNodeTest extends TestCa
         commit("/", "> \"test/b\": \"/test2/b\"");
         assertEquals("{a,c}", getNode("/test"));
         assertEquals("{b}", getNode("/test2"));
+        assertJournal("> \"/test/b\":\"/test2/b\"");
+
         // move /test/a to /test2
         commit("/", "> \"test/a\": \"test2/a1\"");
         assertEquals("{c}", getNode("/test"));
         assertEquals("{b,a1}", getNode("/test2"));
+        assertJournal("> \"/test/a\":\"/test2/a1\"");
+
         // move /test/c to /test2
         commit("/", "> \"test/c\": \"test2/c\"");
         assertEquals("{}", getNode("/test"));
         assertEquals("{b,a1,c}", getNode("/test2"));
+        assertJournal("> \"/test/c\":\"/test2/c\"");
     }
 
     private void commit(String root, String diff) {
@@ -154,4 +183,63 @@ public class MoveNodeTest extends TestCa
         return s;
     }
 
+    private void assertJournal(String expectedJournal) {
+        assertEquals(expectedJournal, getJournal());
+    }
+
+    private String getJournal() {
+        if (journalRevision == null) {
+            String revs = mk.getRevisions(0, 1);
+            JsopTokenizer t = new JsopTokenizer(revs);
+            t.read('[');
+            do {
+                t.read('{');
+                assertEquals("id", t.readString());
+                t.read(':');
+                journalRevision = t.readString();
+                t.read(',');
+                assertEquals("ts", t.readString());
+                t.read(':');
+                t.read(JsopTokenizer.NUMBER);
+                t.read('}');
+            } while (t.matches(','));
+        }
+        String head = mk.getHeadRevision();
+        String journal = mk.getJournal(journalRevision, head);
+        JsopTokenizer t = new JsopTokenizer(journal);
+        StringBuilder buff = new StringBuilder();
+        t.read('[');
+        boolean isNew = false;
+        do {
+            t.read('{');
+            assertEquals("id", t.readString());
+            t.read(':');
+            t.readString();
+            t.read(',');
+            assertEquals("ts", t.readString());
+            t.read(':');
+            t.read(JsopTokenizer.NUMBER);
+            t.read(',');
+            assertEquals("msg", t.readString());
+            t.read(':');
+            t.read();
+            t.read(',');
+            assertEquals("changes", t.readString());
+            t.read(':');
+            String changes = t.readString().trim();
+            if (isNew) {
+                if (buff.length() > 0) {
+                    buff.append('\n');
+                }
+                buff.append(changes);
+            }
+            // the first revision isn't new, all others are
+            isNew = true;
+            t.read('}');
+        } while (t.matches(','));
+        System.out.println();
+        journalRevision = head;
+        return buff.toString();
+    }
+
 }
\ No newline at end of file



Mime
View raw message