jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1293323 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/model/ test/java/org/apache/jackrabbit/mk/store/
Date Fri, 24 Feb 2012 16:25:27 GMT
Author: dpfister
Date: Fri Feb 24 16:25:26 2012
New Revision: 1293323

URL: http://svn.apache.org/viewvc?rev=1293323&view=rev
Log:
Introduce unused revisions clean-up (WIP)
- add new constructors for test-setup
- remove provider in arguments (already available as instance variable)
- add first test

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
  (with props)
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1293323&r1=1293322&r2=1293323&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Fri Feb 24 16:25:26 2012
@@ -53,6 +53,15 @@ public class MicroKernelImpl implements 
     public MicroKernelImpl(String homeDir) throws MicroKernelException {
         init(homeDir);
     }
+    
+    /**
+     * Alternate constructor, used for testing.
+     * 
+     * @param rep repository, already initialized
+     */
+    public MicroKernelImpl(Repository rep) {
+        this.rep = rep;
+    }
 
     protected void init(String homeDir) throws MicroKernelException {
         try {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1293323&r1=1293322&r2=1293323&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
Fri Feb 24 16:25:26 2012
@@ -34,9 +34,8 @@ import org.apache.jackrabbit.mk.util.Pat
  */
 public class Repository {
 
-    final String homeDir;
-    boolean initialized;
-
+    private final String homeDir;
+    private boolean initialized;
     private final DefaultRevisionStore rs;
 
     public Repository(String homeDir) throws Exception {
@@ -47,17 +46,25 @@ public class Repository {
         this.homeDir = home.getCanonicalPath();
 
         rs = new DefaultRevisionStore();
-
-        initialized = false;
     }
-
+    
+    /**
+     * Alternate constructor, used for testing.
+     * 
+     * @param rs revision store, already initialized
+     */
+    public Repository(DefaultRevisionStore rs) {
+        this.homeDir = null;
+        this.rs = rs;
+        
+        initialized = true;
+    }
+    
     public void init() throws Exception {
         if (initialized) {
             return;
         }
-
-        File home = new File(homeDir);
-        rs.initialize(home);
+        rs.initialize(new File(homeDir));
 
         initialized = true;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java?rev=1293323&r1=1293322&r2=1293323&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
Fri Feb 24 16:25:26 2012
@@ -88,7 +88,7 @@ public abstract class AbstractNode imple
         return childEntries.getEntries(offset, count);
     }
 
-    public Iterator<ChildNode> getChildNodes(int offset, int count, final RevisionProvider
provider)
+    public Iterator<ChildNode> getChildNodes(int offset, int count)
             throws Exception {
         if (offset < 0 || count < -1) {
             throw new IllegalArgumentException();
@@ -117,7 +117,7 @@ public abstract class AbstractNode imple
         };
     }
 
-    public Node getNode(String relPath, RevisionProvider provider)
+    public Node getNode(String relPath)
             throws NotFoundException, Exception {
         String[] names = PathUtils.split(relPath);
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java?rev=1293323&r1=1293322&r2=1293323&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
Fri Feb 24 16:25:26 2012
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.mk.model;
 
 import org.apache.jackrabbit.mk.store.Binding;
-import org.apache.jackrabbit.mk.store.RevisionProvider;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 
 import java.util.Iterator;
@@ -40,8 +39,8 @@ public interface Node {
      */
     Iterator<ChildNodeEntry> getChildNodeEntries(int offset, int count);
 
-    Iterator<ChildNode> getChildNodes(int offset, int count, RevisionProvider provider)
throws Exception;
-    Node getNode(String relPath, RevisionProvider provider) throws NotFoundException, Exception;
+    Iterator<ChildNode> getChildNodes(int offset, int count) throws Exception;
+    Node getNode(String relPath) throws NotFoundException, Exception;
 
     void diff(Node other, NodeDiffHandler handler);
     

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java?rev=1293323&r1=1293322&r2=1293323&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
Fri Feb 24 16:25:26 2012
@@ -83,13 +83,13 @@ public class StoredNode extends Abstract
         return new UnmodifiableIterator<String>(super.getChildNodeNames(offset, count));
     }
 
-    public Iterator<ChildNode> getChildNodes(int offset, int count, RevisionProvider
provider)
+    public Iterator<ChildNode> getChildNodes(int offset, int count)
             throws Exception {
-        return new UnmodifiableIterator<ChildNode>(super.getChildNodes(offset, count,
provider));
+        return new UnmodifiableIterator<ChildNode>(super.getChildNodes(offset, count));
     }
 
-    public Node getNode(String relPath, RevisionProvider provider) throws NotFoundException,
Exception {
-        Node result = super.getNode(relPath, provider);
+    public Node getNode(String relPath) throws NotFoundException, Exception {
+        Node result = super.getNode(relPath);
         if (!(result instanceof StoredNode)) {
             // todo return a StoredNode instance instead?
         }

Added: 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=1293323&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
(added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
Fri Feb 24 16:25:26 2012
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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.model.ChildNode;
+import org.apache.jackrabbit.mk.model.MutableCommit;
+import org.apache.jackrabbit.mk.model.Node;
+import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.junit.After;
+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. 
+ */
+public class CopyHeadRevisionTest {
+
+    @Before
+    public void setup() throws Exception {
+        FileUtils.deleteRecursive("target/mk1", false);
+        FileUtils.deleteRecursive("target/mk2", false);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+    }
+    
+    @Test
+    public void testCopyHeadRevisionToNewStore() throws Exception {
+        DefaultRevisionStore rsFrom = new DefaultRevisionStore();
+        rsFrom.initialize(new File("target/mk1"));
+                
+        MicroKernelImpl mkFrom = new MicroKernelImpl(new Repository(rsFrom));
+        mkFrom.commit("/",  "+\"a\" : { \"c\":{}, \"d\":{} }", mkFrom.getHeadRevision(),
null);
+        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);
+
+        MicroKernelImpl mkTo = new MicroKernelImpl(new Repository(rsTo));
+//        System.out.println(mkTo.getNodes("/", mkTo.getHeadRevision(), 0, 0, -1));
+    }
+    
+    private void traverse(Node node) throws Exception {
+        Map<String,String> props = node.getProperties();
+        Iterator<ChildNode> iter = node.getChildNodes(0, -1);
+        while (iter.hasNext()) {
+            ChildNode c = iter.next();
+//            System.out.println(c.getName());
+            traverse(c.getNode());
+        }
+    }
+}

Propchange: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/store/CopyHeadRevisionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url



Mime
View raw message