jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1294623 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/model/MutableCommit.java main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
Date Tue, 28 Feb 2012 12:31:58 GMT
Author: dpfister
Date: Tue Feb 28 12:31:58 2012
New Revision: 1294623

URL: http://svn.apache.org/viewvc?rev=1294623&view=rev
Log:
Introduce unused revisions clean-up (WIP)
- complete copy test

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java?rev=1294623&r1=1294622&r2=1294623&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
Tue Feb 28 12:31:58 2012
@@ -24,6 +24,18 @@ public class MutableCommit extends Abstr
     public MutableCommit() {
     }
 
+    /**
+     * Copy constructor.
+     * 
+     * @param other other commit
+     */
+    public MutableCommit(Commit other) {
+        setParentId(other.getParentId());
+        setRootNodeId(other.getRootNodeId());
+        setCommitTS(other.getCommitTS());
+        setMsg(other.getMsg());
+    }
+
     public void setParentId(String parentId) {
         this.parentId = parentId;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java?rev=1294623&r1=1294622&r2=1294623&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
Tue Feb 28 12:31:58 2012
@@ -27,8 +27,8 @@ import org.apache.jackrabbit.mk.model.St
  * Defines the methods exposed by a persistence manager, that stores head
  * revision id, nodes, child node entries and blobs.
  * 
- * TODO: convert model type (e.g. Commit) arguments into byte arrays or similar
- *       primitive types (such as in #readNodeBinding).
+ * TODO: instead of deserializing objects on their own, return Binding
+ *       instances, such as in #readNodeBinding.
  */
 public interface PersistenceManager {
 

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java?rev=1294623&r1=1294622&r2=1294623&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
Tue Feb 28 12:31:58 2012
@@ -18,22 +18,31 @@ package org.apache.jackrabbit.mk.store;
 
 import java.io.File;
 import java.util.Iterator;
-import java.util.Map;
 
 import org.apache.jackrabbit.mk.MicroKernelImpl;
 import org.apache.jackrabbit.mk.Repository;
 import org.apache.jackrabbit.mk.fs.FileUtils;
+import org.apache.jackrabbit.mk.json.fast.Jsop;
+import org.apache.jackrabbit.mk.json.fast.JsopArray;
 import org.apache.jackrabbit.mk.model.ChildNode;
+import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.MutableCommit;
+import org.apache.jackrabbit.mk.model.MutableNode;
 import org.apache.jackrabbit.mk.model.Node;
-import org.apache.jackrabbit.mk.model.StoredCommit;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
  * Use-case: start off a new revision store that contains just the head revision
- * and its nodes. 
+ * and its nodes.
+ * 
+ * TODO: when copying a head revision, including commit and nodes, to a new
+ *       store, the revision id will be different, which might be confusing
+ *       for an MK client. Cause for this is the digest computation of all
+ *       fields in a commit object, including the parent commit, which is 
+ *       obviously different.
  */
 public class CopyHeadRevisionTest {
 
@@ -57,29 +66,64 @@ public class CopyHeadRevisionTest {
         mkFrom.commit("/",  "+\"b\" : {}", mkFrom.getHeadRevision(), null);
         mkFrom.commit("/b", "+\"e\" : {}", mkFrom.getHeadRevision(), null);
 
-        StoredCommit commitFrom = rsFrom.getHeadCommit();
-        
         DefaultRevisionStore rsTo = new DefaultRevisionStore(); 
         rsTo.initialize(new File("target/mk2"));
 
-        MutableCommit commitTo = new MutableCommit();
-        commitTo.setCommitTS(commitFrom.getCommitTS());
-        commitTo.setMsg(commitFrom.getMsg());
-        commitTo.setParentId(commitTo.getParentId());
-        commitTo.setRootNodeId(commitFrom.getRootNodeId());
-        rsTo.putCommit(commitTo);
+        copyHeadRevision(rsFrom, rsTo);
 
         MicroKernelImpl mkTo = new MicroKernelImpl(new Repository(rsTo));
-//        System.out.println(mkTo.getNodes("/", mkTo.getHeadRevision(), 0, 0, -1));
+
+        // TODO: assert both old and new MK have same head revision
+        // Assert.assertEquals(mkFrom.getHeadRevision(), mkTo.getHeadRevision());
+        
+        // Assert both old and new MK have same contents
+        Assert.assertEquals(
+                mkFrom.getNodes("/", mkFrom.getHeadRevision(), 2, 0, -1),
+                mkTo.getNodes("/", mkTo.getHeadRevision(), 2, 0, -1));
+
+        // Assert new MK has only 2 revisions (initial and head)
+        JsopArray revs = (JsopArray) Jsop.parse(mkTo.getRevisions(0, Integer.MAX_VALUE));
+        Assert.assertEquals(2, revs.size());
     }
     
-    private void traverse(Node node) throws Exception {
-        Map<String,String> props = node.getProperties();
+    /**
+     * Copy the head revision (commit and nodes) from a source provider to a
+     * target store.
+     * 
+     * @param from source provider
+     * @param to target store
+     * @throws Exception if an error occurs
+     */
+    private void copyHeadRevision(RevisionProvider from, RevisionStore to)
+            throws Exception {
+        
+        Commit commitFrom = from.getHeadCommit();
+        
+        Node nodeFrom = from.getNode(commitFrom.getRootNodeId());
+        copy(nodeFrom, to);
+        
+        MutableCommit commitTo = new MutableCommit(commitFrom);
+        commitTo.setParentId(to.getHeadCommitId());
+        
+        String revId = to.putCommit(commitTo);
+        to.setHeadCommitId(revId);
+    }
+    
+    /**
+     * Copy a node and all its descendants into a target store
+     * @param node source node
+     * @param store target store
+     * @throws Exception if an error occurs
+     */
+    private void copy(Node node, RevisionStore store) 
+            throws Exception {
+
+        store.putNode(new MutableNode(node, store));
+        
         Iterator<ChildNode> iter = node.getChildNodes(0, -1);
         while (iter.hasNext()) {
             ChildNode c = iter.next();
-//            System.out.println(c.getName());
-            traverse(c.getNode());
+            copy(c.getNode(), store);
         }
     }
 }



Mime
View raw message