jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1125452 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/store/ test/java/org/ test/java/org/apache/ test/java/org/apache/jackrabbit/ test/java/org/apache/jackrabbit/mk/
Date Fri, 20 May 2011 16:32:01 GMT
Author: stefan
Date: Fri May 20 16:32:01 2011
New Revision: 1125452

URL: http://svn.apache.org/viewvc?rev=1125452&view=rev
Log:
MicroKernel prototype (WIP)

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.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=1125452&r1=1125451&r2=1125452&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 May 20 16:32:01 2011
@@ -86,7 +86,7 @@ public class MicroKernelImpl implements 
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
-
+        maxEntries = maxEntries < 0 ? Integer.MAX_VALUE : maxEntries;
         List<Commit> history = new ArrayList<Commit>();
         try {
             Commit commit = rep.getHeadCommit();
@@ -235,7 +235,7 @@ public class MicroKernelImpl implements 
         }
 
         try {
-            rep.getNode(path, revisionId);
+            rep.getNode(revisionId, path);
             return true;
         } catch (Exception e) {
             return false;
@@ -295,7 +295,7 @@ public class MicroKernelImpl implements 
         }
 
         try {
-            return rep.getNode(path, revisionId).getChildNodeCount();
+            return rep.getNode(revisionId, path).getChildNodeCount();
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java?rev=1125452&r1=1125451&r2=1125452&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java
Fri May 20 16:32:01 2011
@@ -95,7 +95,7 @@ public class NodeDelta implements NodeDi
 
     public List<Conflict> listConflicts(NodeDelta other) {
         // assume that both delta's were built using the *same* base node revision
-        if (!node1.getId().equals(other.node1)) {
+        if (!node1.getId().equals(other.node1.getId())) {
             throw new IllegalArgumentException("other and this NodeDelta object are expected
to share common node1 instance");
         }
 

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java?rev=1125452&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
(added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
Fri May 20 16:32:01 2011
@@ -0,0 +1,109 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+import java.util.ArrayList;
+
+public class ConcurrentWriteTest extends TestCase {
+
+    private static final int NUM_THREADS = 5;
+
+    private MicroKernel mk;
+
+    public void setUp() throws Exception {
+        mk = new MicroKernelImpl(System.getProperty("homeDir", "."));
+    }
+
+    public void tearDown() throws InterruptedException {
+        ((MicroKernelImpl) mk).dispose();
+    }
+
+    /**
+     * Runs the test.
+     */
+    public void testConcurrentWriting() throws Exception {
+
+        String head = mk.getHeadRevision();
+        if (mk.nodeExists("/test", head)) {
+            head = mk.commit("/", "-\"test\" : \"\"", head);
+        }
+        head = mk.commit("/", "+\"test\" : {\"jcr:primaryType\":\"nt:unstructured\"}", head);
+
+        String oldHead = head;
+        System.out.println("new HEAD: " + oldHead);
+
+        long t0 = System.currentTimeMillis();
+
+        TestThread[] threads = new TestThread[NUM_THREADS];
+        for (int i = 0; i < threads.length; i++) {
+            TestThread thread = new TestThread(head, "t" + i);
+            thread.start();
+            threads[i] = thread;
+        }
+
+        for (TestThread t : threads) {
+            if (t != null) {
+                t.join();
+            }
+        }
+
+        long t1 = System.currentTimeMillis();
+
+        System.out.println("duration: " + (t1 - t0) + "ms");
+
+        head = mk.getHeadRevision();
+        String json = mk.getNodes("/", Integer.MAX_VALUE, head);
+        System.out.println("new HEAD: " + head);
+        //System.out.println(json);
+        System.out.println();
+
+        String history = mk.getRevisions(t0, -1);
+        System.out.println("History:");
+        //System.out.println(history);
+        System.out.println();
+
+        String journal = mk.getJournal(oldHead, head);
+        System.out.println("Journal:");
+        System.out.println(journal);
+        System.out.println();
+
+    }
+
+    class TestThread extends Thread {
+        String revId;
+
+        TestThread(String revId, String name) {
+            super(name);
+            this.revId = revId;
+        }
+
+        public void run() {
+            StringBuilder sb = new StringBuilder();
+            sb.append("+\"");
+            sb.append(getName());
+            sb.append("\" : {\"jcr:primaryType\":\"nt:unstructured\"\n");
+            for (int i = 0; i < 1000; i++) {
+                sb.append(",\"sub" + i + "\" : {\"jcr:primaryType\":\"nt:unstructured\",
\"prop\":\"" + System.currentTimeMillis() + "\"}\n");
+            }
+            sb.append('}');
+            revId = mk.commit("/test", sb.toString(), revId);
+        }
+    }
+}



Mime
View raw message