jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1461044 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/ test/java/org/apache/jackrabbit/mongomk/ test/java/org/apache/jackrabbit/mongomk/prototype/
Date Tue, 26 Mar 2013 10:00:26 GMT
Author: mreutegg
Date: Tue Mar 26 10:00:26 2013
New Revision: 1461044

URL: http://svn.apache.org/r1461044
Log:
OAK-619 Lock-free MongoMK implementation
- Improve branch support
- Copied over some tests from previous MongoDB based MicroKernel implementation. Some tests
are still marked ignored.
- Fixed NPE in Commit.createOrUpdateNode() (newestRev may be null)
- Disabled document splitting until it is fully implemented -> max size set to Integer.MAX_VALUE
- Fixed path issue with JSOP move and copy operation

Added:
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/BaseMongoMKTest.java
  (with props)
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchMergeTest.java
      - copied, changed from r1461015, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchTest.java
      - copied, changed from r1461015, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKCommitMoveTest.java
      - copied, changed from r1461015, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitMoveTest.java
Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
    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/AbstractMongoConnectionTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java?rev=1461044&r1=1461043&r2=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
Tue Mar 26 10:00:26 2013
@@ -41,8 +41,10 @@ public class Commit {
      * The maximum size of a document. If it is larger, it is split.
      */
     // TODO check which value is the best one
-    private static final int MAX_DOCUMENT_SIZE = 16 * 1024;
-    
+    //private static final int MAX_DOCUMENT_SIZE = 16 * 1024;
+    // TODO disabled until document split is fully implemented
+    private static final int MAX_DOCUMENT_SIZE = Integer.MAX_VALUE;
+
     /**
      * Whether to purge old revisions if a node gets too large. If false, old
      * revisions are stored in a separate document. If true, old revisions are
@@ -115,12 +117,38 @@ public class Commit {
         }
     }
 
+    void prepare(Revision baseRevision) {
+        if (!operations.isEmpty()) {
+            applyToDocumentStore(baseRevision);
+            applyToCache();
+        }
+    }
+
     /**
      * Apply the changes to the document store (to update MongoDB).
      */
     void applyToDocumentStore() {
+        applyToDocumentStore(null);
+    }
+
+    /**
+     * Apply the changes to the document store (to update MongoDB).
+     *
+     * @param baseRevision the base revision of this commit. Currently only
+     *                     used for branch commits.
+     */
+    void applyToDocumentStore(Revision baseRevision) {
+        // the value in _revisions.<revision> property of the commit root node
+        // regular commits use "true", which makes the commit visible to
+        // other readers. branch commits use the base revision to indicate
+        // the visibility of the commit
+        String commitValue = baseRevision != null ? baseRevision.toString() : "true";
         DocumentStore store = mk.getDocumentStore();
         String commitRootPath = null;
+        if (baseRevision != null) {
+            // branch commits always use root node as commit root
+            commitRootPath = "/";
+        }
         ArrayList<UpdateOp> newNodes = new ArrayList<UpdateOp>();
         ArrayList<UpdateOp> changedNodes = new ArrayList<UpdateOp>();
         for (String p : operations.keySet()) {
@@ -160,7 +188,7 @@ public class Commit {
             // no updates and root of commit is also new. that is,
             // it is the root of a subtree added in a commit.
             // so we try to add the root like all other nodes
-            commitRoot.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), "true");
+            commitRoot.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), commitValue);
             newNodes.add(commitRoot);
         }
         try {
@@ -191,7 +219,7 @@ public class Commit {
             // first to check if there was a conflict, and only then to commit
             // the revision, with the revision property set)
             if (changedNodes.size() > 0 || !commitRoot.isNew) {
-                commitRoot.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), "true");
+                commitRoot.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), commitValue);
                 createOrUpdateNode(store, commitRoot);
                 operations.put(commitRootPath, commitRoot);
             }
@@ -207,7 +235,7 @@ public class Commit {
         if (baseRevision != null) {
             // TODO detect conflicts here
             Revision newestRev = mk.getNewestRevision(map, revision, true);
-            if (mk.isRevisionNewer(newestRev, baseRevision)) {
+            if (newestRev != null && mk.isRevisionNewer(newestRev, baseRevision))
{
                 // TODO transaction rollback
                 throw new MicroKernelException("The node " + 
                         op.path + " was changed in revision " + 

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java?rev=1461044&r1=1461043&r2=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/DocumentStore.java
Tue Mar 26 10:00:26 2013
@@ -19,6 +19,11 @@ package org.apache.jackrabbit.mongomk.pr
 import java.util.List;
 import java.util.Map;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.mk.api.MicroKernelException;
+
 /**
  * The interface for the backend storage for documents.
  */
@@ -34,18 +39,20 @@ public interface DocumentStore {
      * can modify it without affecting the stored version).
      *
      * @param collection the collection
-     * @param path the path
+     * @param key the key
      * @return the map, or null if not found
      */
+    @CheckForNull
     Map<String, Object> find(Collection collection, String key);
 
+    @Nonnull
     List<Map<String, Object>> query(Collection collection, String fromKey, String
toKey, int limit);
     
     /**
      * Remove a document.
      *
      * @param collection the collection
-     * @param path the path
+     * @param key the key
      */
     void remove(Collection collection, String key);
 
@@ -65,8 +72,11 @@ public interface DocumentStore {
      * @param collection the collection
      * @param update the update operation
      * @return the new document
+     * @throws MicroKernelException if the operation failed.
      */    
-    Map<String, Object> createOrUpdate(Collection collection, UpdateOp update); 
+    @Nonnull
+    Map<String, Object> createOrUpdate(Collection collection, UpdateOp update)
+            throws MicroKernelException;
     
     void dispose();
 

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java?rev=1461044&r1=1461043&r2=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MemoryDocumentStore.java
Tue Mar 26 10:00:26 2013
@@ -23,6 +23,8 @@ import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentNavigableMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.mongomk.prototype.UpdateOp.Operation;
 
 /**
@@ -58,6 +60,7 @@ public class MemoryDocumentStore impleme
         return copy;
     }
     
+    @Nonnull
     public List<Map<String, Object>> query(Collection collection, String fromKey,
String toKey, int limit) {
         ConcurrentSkipListMap<String, Map<String, Object>> map = getMap(collection);
         ConcurrentNavigableMap<String, Map<String, Object>> sub = map.subMap(fromKey,
toKey);
@@ -94,6 +97,7 @@ public class MemoryDocumentStore impleme
         }
     }
 
+    @Nonnull
     public Map<String, Object> createOrUpdate(Collection collection, UpdateOp update)
{
         ConcurrentSkipListMap<String, Map<String, Object>> map = getMap(collection);
         Map<String, Object> n;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java?rev=1461044&r1=1461043&r2=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
Tue Mar 26 10:00:26 2013
@@ -25,6 +25,8 @@ import java.util.Map.Entry;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 
+import javax.annotation.Nonnull;
+
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
@@ -130,6 +132,7 @@ public class MongoDocumentStore implemen
         }
     }
     
+    @Nonnull
     @Override
     public List<Map<String, Object>> query(Collection collection,
             String fromKey, String toKey, int limit) {
@@ -172,6 +175,7 @@ public class MongoDocumentStore implemen
         }
     }
 
+    @Nonnull
     @Override
     public Map<String, Object> createOrUpdate(Collection collection, UpdateOp updateOp)
{
         log("createOrUpdate", updateOp);        

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=1461044&r1=1461043&r2=1461044&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
Tue Mar 26 10:00:26 2013
@@ -29,6 +29,7 @@ import java.util.TreeSet;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
@@ -139,8 +140,8 @@ public class MongoMK implements MicroKer
     /**
      * Maps branch commit revision to revision it is based on
      */
-    private final Map<String, String> branchCommits =
-            Collections.synchronizedMap(new HashMap<String, String>());
+    private final Map<Revision, Revision> branchCommits =
+            Collections.synchronizedMap(new HashMap<Revision, Revision>());
 
     /**
      * Create a new in-memory MongoMK used for testing.
@@ -265,6 +266,29 @@ public class MongoMK implements MicroKer
     }
     
     private boolean includeRevision(Revision x, Revision requestRevision) {
+        if (branchCommits.containsKey(x)) {
+            // only include if requested revision is also a branch revision
+            // with a history including x
+            Revision rev = requestRevision;
+            for (;;) {
+                if (rev != null) {
+                    if (rev.equals(x)) {
+                        return true;
+                    }
+                } else {
+                    // not part of branch identified by requestedRevision
+                    return false;
+                }
+                rev = branchCommits.get(rev);
+            }
+        }
+        // assert: x is not a branch commit
+        while (branchCommits.containsKey(requestRevision)) {
+            // reset requestRevision to branch base revision to make
+            // sure we don't include revisions committed after branch
+            // was created
+            requestRevision = branchCommits.get(requestRevision);
+        }
         if (x.getClusterId() == this.clusterId && 
                 requestRevision.getClusterId() == this.clusterId) {
             // both revisions were created by this cluster node: 
@@ -275,7 +299,7 @@ public class MongoMK implements MicroKer
         return requestRevision.compareRevisionTime(x) >= 0;
     }
     
-    boolean isRevisionNewer(Revision x, Revision previous) {
+    boolean isRevisionNewer(@Nonnull Revision x, @Nonnull Revision previous) {
         // TODO currently we only compare the timestamps
         return x.compareRevisionTime(previous) > 0;
     }
@@ -285,16 +309,23 @@ public class MongoMK implements MicroKer
      * considered valid if the given node map is the root of the commit, or the
      * commit root has the revision set. This method may read further nodes to
      * perform this check.
+     * This method also takes pending branches into consideration.
+     * The <code>readRevision</code> identifies the read revision used by the
+     * client, which may be a branch revision logged in {@link #branchCommits}.
+     * The revision <code>rev</code> is valid if it is part of the branch
+     * history of <code>readRevision</code>.
      *
      * @param rev     revision to check.
+     * @param readRevision the read revision of the client.
      * @param nodeMap the node to check.
      * @return <code>true</code> if the revision is valid; <code>false</code>
      *         otherwise.
      */
-    boolean isValidRevision(Revision rev, Map<String, Object> nodeMap) {
-        @SuppressWarnings("unchecked")
-        Map<String, String> revisions = (Map<String, String>) nodeMap.get(UpdateOp.REVISIONS);
-        if (revisions != null && revisions.containsKey(rev.toString())) {
+    boolean isValidRevision(@Nonnull Revision rev,
+                            @Nonnull Revision readRevision,
+                            @Nonnull Map<String, Object> nodeMap) {
+        //noinspection unchecked
+        if (isCommitted(rev, readRevision, (Map<String, String>) nodeMap.get(UpdateOp.REVISIONS)))
{
             return true;
         }
         // check commit root
@@ -325,8 +356,37 @@ public class MongoMK implements MicroKer
             return false;
         }
         //noinspection unchecked
-        revisions = (Map<String, String>) nodeMap.get(UpdateOp.REVISIONS);
-        return revisions != null && revisions.containsKey(rev.toString());
+        return isCommitted(rev, readRevision, (Map<String, String>) nodeMap.get(UpdateOp.REVISIONS));
+    }
+
+    /**
+     * Returns <code>true</code> if the given revision is set to committed in
+     * the revisions map. That is, the revision exists in the map and the string
+     * value is <code>"true"</code> or equals the <code>readRevision</code>.
+     *
+     * @param revision  the revision to check.
+     * @param readRevision the read revision.
+     * @param revisions the revisions map, or <code>null</code> if none is set.
+     * @return <code>true</code> if the revision is committed, otherwise
+     *         <code>false</code>.
+     */
+    private boolean isCommitted(@Nonnull Revision revision,
+                                @Nonnull Revision readRevision,
+                                @Nullable Map<String, String> revisions) {
+        if (revision.equals(readRevision)) {
+            return true;
+        }
+        if (revisions == null) {
+            return false;
+        }
+        String value = revisions.get(revision.toString());
+        if (value == null) {
+            return false;
+        }
+        if (!value.equals("true")) {
+            revision = Revision.fromString(value);
+        }
+        return includeRevision(revision, readRevision);
     }
 
     public Children getChildren(String path, Revision rev, int limit) {
@@ -447,12 +507,8 @@ public class MongoMK implements MicroKer
     }
 
     @Override
-    public synchronized String getHeadRevision() throws MicroKernelException {
-        String head = headRevision.toString();
-        while (branchCommits.containsKey(head)) {
-            head = branchCommits.get(head);
-        }
-        return head;
+    public String getHeadRevision() throws MicroKernelException {
+        return headRevision.toString();
     }
 
     @Override
@@ -647,10 +703,10 @@ public class MongoMK implements MicroKer
                 String sourcePath = path;
                 String targetPath = t.readString();
                 if (!PathUtils.isAbsolute(targetPath)) {
-                    targetPath = PathUtils.concat(path, targetPath);
+                    targetPath = PathUtils.concat(rootPath, targetPath);
                 }
                 commit.moveNode(sourcePath, targetPath);
-                moveNode(sourcePath, targetPath, Revision.fromString(stripBranchRevMarker(baseRevId)),
commit);
+                moveNode(sourcePath, targetPath, baseRev, commit);
                 break;
             }
             case '*': {
@@ -659,10 +715,10 @@ public class MongoMK implements MicroKer
                 String sourcePath = path;
                 String targetPath = t.readString();
                 if (!PathUtils.isAbsolute(targetPath)) {
-                    targetPath = PathUtils.concat(path, targetPath);
+                    targetPath = PathUtils.concat(rootPath, targetPath);
                 }
                 commit.copyNode(sourcePath, targetPath);
-                copyNode(sourcePath, targetPath, Revision.fromString(stripBranchRevMarker(baseRevId)),
commit);
+                copyNode(sourcePath, targetPath, baseRev, commit);
                 break;
             }
             default:
@@ -670,12 +726,11 @@ public class MongoMK implements MicroKer
             }
         }
         if (baseRevId.startsWith("b")) {
-            // just commit to head currently
-            commit.apply();
+            // prepare commit
+            commit.prepare(baseRev);
             // remember branch commit
-            branchCommits.put(rev.toString(), baseRevId.substring(1));
+            branchCommits.put(rev, baseRev);
 
-            headRevision = commit.getRevision();
             return "b" + rev.toString();
 
             // String jsonBranch = branchCommits.remove(revisionId);
@@ -777,7 +832,8 @@ public class MongoMK implements MicroKer
         String value = null;
         for (String r : valueMap.keySet()) {
             Revision propRev = Revision.fromString(r);
-            if (isRevisionNewer(propRev, maxRev)) {
+            if (isRevisionNewer(propRev, maxRev)
+                    || !isValidRevision(propRev, maxRev, nodeMap)) {
                 continue;
             }
             if (firstRev == null || isRevisionNewer(propRev, firstRev)) {
@@ -799,7 +855,7 @@ public class MongoMK implements MicroKer
      * @param onlyCommitted whether only committed changes should be considered
      * @return the revision, or null if deleted
      */
-    Revision getNewestRevision(Map<String, Object> nodeMap, Revision before, boolean
onlyCommitted) {
+    @Nullable Revision getNewestRevision(Map<String, Object> nodeMap, Revision before,
boolean onlyCommitted) {
         if (nodeMap == null) {
             return null;
         }
@@ -848,11 +904,11 @@ public class MongoMK implements MicroKer
     }
 
     @Override
-    public String branch(String trunkRevisionId) throws MicroKernelException {
-        // TODO improve implementation if needed
-        String branchId = "b" + trunkRevisionId;
-        // branchCommits.put(branchId, "");
-        return branchId;
+    public String branch(@Nullable String trunkRevisionId) throws MicroKernelException {
+        // nothing is written when the branch is created, the returned
+        // revision simply acts as a reference to the branch base revision
+        String revisionId = trunkRevisionId != null ? trunkRevisionId : headRevision.toString();
+        return "b" + revisionId;
     }
 
     @Override
@@ -865,11 +921,22 @@ public class MongoMK implements MicroKer
 
         // reading from the branch is reading from the trunk currently
         String revisionId = branchRevisionId.substring(1).replace('+', ' ').trim();
-        String baseRevId = revisionId;
+        // make branch commits visible
+        List<Revision> branchRevisions = new ArrayList<Revision>();
+        UpdateOp op = new UpdateOp("/", Utils.getIdFromPath("/"), false);
+        Revision baseRevId = Revision.fromString(revisionId);
         while (baseRevId != null) {
-            baseRevId = branchCommits.remove(baseRevId);
+            branchRevisions.add(baseRevId);
+            op.set(UpdateOp.REVISIONS + "." + baseRevId, "true");
+            baseRevId = branchCommits.get(baseRevId);
+        }
+        store.createOrUpdate(DocumentStore.Collection.NODES, op);
+        // remove from branchCommits map after successful update
+        for (Revision r : branchRevisions) {
+            branchCommits.remove(r);
         }
-        return revisionId;
+        headRevision = newRevision();
+        return headRevision.toString();
 
         // TODO improve implementation if needed
         // if (!branchRevisionId.startsWith("b")) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java?rev=1461044&r1=1461043&r2=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/AbstractMongoConnectionTest.java
Tue Mar 26 10:00:26 2013
@@ -41,18 +41,24 @@ public class AbstractMongoConnectionTest
     protected static final String DB =
             System.getProperty("mongo.db", "MongoMKDB");
 
-    protected static MongoConnection mongoConnection;
+    protected static Boolean mongoAvailable;
+
+    protected MongoConnection mongoConnection;
 
     private static Exception mongoException = null;
 
     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
-        if (mongoConnection == null) {
-            mongoConnection = new MongoConnection(HOST, PORT, DB);
+        if (mongoAvailable == null) {
+            MongoConnection mongoConnection = new MongoConnection(HOST, PORT, DB);
             try {
                 mongoConnection.getDB().command(new BasicDBObject("ping", 1));
+                mongoAvailable = Boolean.TRUE;
             } catch (Exception e) {
+                mongoAvailable = Boolean.FALSE;
                 mongoException = e;
+            } finally {
+                mongoConnection.close();
             }
         }
         Assume.assumeNoException(mongoException);
@@ -60,12 +66,14 @@ public class AbstractMongoConnectionTest
 
     @Before
     public void setUpConnection() throws Exception {
+        mongoConnection = new MongoConnection(HOST, PORT, DB);
         dropCollections(mongoConnection.getDB());
     }
 
     @After
     public void tearDownConnection() throws Exception {
         dropCollections(mongoConnection.getDB());
+        mongoConnection.close();
     }
 
     protected void dropCollections(DB db) throws Exception {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java?rev=1461044&r1=1461043&r2=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/BaseMongoMicroKernelTest.java
Tue Mar 26 10:00:26 2013
@@ -39,7 +39,7 @@ import com.mongodb.DB;
  */
 public class BaseMongoMicroKernelTest extends AbstractMongoConnectionTest {
 
-    public static MicroKernel mk;
+    public MicroKernel mk;
 
     @Before
     public void setUp() throws Exception {
@@ -95,13 +95,13 @@ public class BaseMongoMicroKernelTest ex
     }
 
     protected void assertPropExists(String rev, String path, String property) {
-        String nodes = mk.getNodes(path, rev, -1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
         assertPropertyExists(obj, property);
     }
 
     protected void assertPropNotExists(String rev, String path, String property) {
-        String nodes = mk.getNodes(path, rev, -1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         if (nodes == null) {
             return;
         }
@@ -110,7 +110,7 @@ public class BaseMongoMicroKernelTest ex
     }
 
     protected void assertPropValue(String rev, String path, String property, String value)
{
-        String nodes = mk.getNodes(path, rev, -1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes(path, rev, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
         assertPropertyValue(obj, property, value);
     }

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/BaseMongoMKTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/BaseMongoMKTest.java?rev=1461044&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/BaseMongoMKTest.java
(added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/BaseMongoMKTest.java
Tue Mar 26 10:00:26 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.mongomk.prototype;
+
+import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
+import org.apache.jackrabbit.mongomk.prototype.MongoMK;
+import org.junit.Before;
+
+import com.mongodb.DB;
+
+/**
+ * <code>BaseMongoMKTest</code>...
+ */
+public class BaseMongoMKTest extends BaseMongoMicroKernelTest {
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        DB db = mongoConnection.getDB();
+        mk = new MongoMK(db, 0);
+    }
+
+    @Override
+    public void tearDownConnection() throws Exception {
+        super.tearDownConnection();
+        ((MongoMK) mk).dispose();
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/BaseMongoMKTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/BaseMongoMKTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchMergeTest.java
(from r1461015, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchMergeTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchMergeTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java&r1=1461015&r2=1461044&rev=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchMergeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchMergeTest.java
Tue Mar 26 10:00:26 2013
@@ -14,26 +14,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl;
+package org.apache.jackrabbit.mongomk.prototype;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.junit.Ignore;
+import org.junit.Test;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
-import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
-import org.junit.Ignore;
-import org.junit.Test;
-
 /**
  * Tests for {@code MicroKernel#branch}
  */
-public class MongoMKBranchMergeTest extends BaseMongoMicroKernelTest {
+public class MongoMKBranchMergeTest extends BaseMongoMKTest {
 
     @Test
     public void oneBranchAddedChildren1() {
@@ -81,6 +80,7 @@ public class MongoMKBranchMergeTest exte
         assertNodesExist(null, "/root", "/root/child1");
 
         String branchRev = mk.branch(null);
+        System.out.println("branchRev: " + branchRev);
 
         addNodes(null, "/root/child2");
         assertNodesExist(null, "/root", "/root/child1", "/root/child2");
@@ -143,7 +143,7 @@ public class MongoMKBranchMergeTest exte
         branchRev = mk.merge(branchRev, "");
         assertPropExists(branchRev, "/", "jcr:primaryType");
 
-        String mergedNode = mk.getNodes("/", branchRev, -1, 0, -1, null);
+        String mergedNode = mk.getNodes("/", branchRev, 0, 0, -1, null);
         String expectedNode = "{\"jcr:primaryType\":\"nam:rep:root\",\":childNodeCount\":0}";
         assertEquals("Wrong property value after merge", expectedNode, mergedNode);
     }
@@ -230,6 +230,7 @@ public class MongoMKBranchMergeTest exte
     }
 
     @Test
+    @Ignore
     public void twoBranchesAddedChildren1() {
         addNodes(null, "/trunk", "/trunk/child1");
         assertNodesExist(null, "/trunk", "/trunk/child1");
@@ -261,6 +262,7 @@ public class MongoMKBranchMergeTest exte
     }
 
     @Test
+    @Ignore
     public void oneBranchAddedChildrenWithConflict() {
         addNodes(null, "/trunk", "/trunk/child1");
         assertNodesExist(null, "/trunk", "/trunk/child1");
@@ -280,6 +282,7 @@ public class MongoMKBranchMergeTest exte
     }
 
     @Test
+    @Ignore
     public void oneBranchChangedPropertiesWithConflict() {
         addNodes(null, "/trunk");
         setProp(null, "/trunk/prop1", "value1");
@@ -298,6 +301,7 @@ public class MongoMKBranchMergeTest exte
     }
 
     @Test
+    @Ignore
     public void addExistingRootInBranch() {
         addNodes(null, "/root");
         assertNodesExist(null, "/root");
@@ -310,6 +314,7 @@ public class MongoMKBranchMergeTest exte
     }
 
     @Test
+    @Ignore
     public void addExistingChildInBranch() {
         addNodes(null, "/root", "/root/child1");
         assertNodesExist(null, "/root", "/root/child1");
@@ -350,6 +355,7 @@ public class MongoMKBranchMergeTest exte
     }
 
     @Test
+    @Ignore
     public void movesInBranch() {
         String rev = mk.commit("/", "+\"a\":{\"b\":{}}", null, null);
         String branchRev = mk.branch(rev);

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchTest.java
(from r1461015, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java&r1=1461015&r2=1461044&rev=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKBranchTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKBranchTest.java
Tue Mar 26 10:00:26 2013
@@ -14,9 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl;
+package org.apache.jackrabbit.mongomk.prototype;
 
-import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 import org.junit.Test;
@@ -28,7 +27,7 @@ import static org.junit.Assert.assertTru
  * <code>MongoMKBranchTest</code> performs a test to check if commits
  * to a branch are not visible to other branches.
  */
-public class MongoMKBranchTest extends BaseMongoMicroKernelTest {
+public class MongoMKBranchTest extends BaseMongoMKTest {
 
     /**
      * Creates the following revision history:
@@ -55,7 +54,7 @@ public class MongoMKBranchTest extends B
         String rev2 = mk.commit("", "+\"/child2\":{}", null, "");
 
         String branchRev2 = mk.branch(rev2);
-        String json = mk.getNodes("/child1", branchRev2, 1000, 0, -1, null);
+        String json = mk.getNodes("/child1", branchRev2, 0, 0, -1, null);
         JSONParser parser = new JSONParser();
         JSONObject obj = (JSONObject) parser.parse(json);
         assertFalse(obj.containsKey("foo"));

Copied: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKCommitMoveTest.java
(from r1461015, jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitMoveTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKCommitMoveTest.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKCommitMoveTest.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitMoveTest.java&r1=1461015&r2=1461044&rev=1461044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/impl/MongoMKCommitMoveTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoMKCommitMoveTest.java
Tue Mar 26 10:00:26 2013
@@ -14,21 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl;
+package org.apache.jackrabbit.mongomk.prototype;
+
+import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
+import org.json.simple.JSONObject;
+import org.junit.Ignore;
+import org.junit.Test;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import org.apache.jackrabbit.mongomk.BaseMongoMicroKernelTest;
-import org.json.simple.JSONObject;
-import org.junit.Test;
-
 /**
  * Tests for {@link MongoMicroKernel#commit(String, String, String, String)}
  * with emphasis on move operations.
  */
-public class MongoMKCommitMoveTest extends BaseMongoMicroKernelTest {
+@Ignore
+public class MongoMKCommitMoveTest extends BaseMongoMKTest {
 
     @Test
     public void moveNode() throws Exception {
@@ -116,16 +118,16 @@ public class MongoMKCommitMoveTest exten
     public void moveNodeWithProperties() throws Exception {
         mk.commit("/", "+\"a\" : { \"key1\" : \"value1\" }", null, null);
         assertTrue(mk.nodeExists("/a", null));
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/a", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "a/key1", "value1");
+        assertPropertyValue(obj, "key1", "value1");
 
         mk.commit("/", ">\"a\" : \"c\"", null, null);
         assertFalse(mk.nodeExists("/a", null));
         assertTrue(mk.nodeExists("/c", null));
-        nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/, null
/*filter*/);
+        nodes = mk.getNodes("/c", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "c/key1", "value1");
+        assertPropertyValue(obj, "key1", "value1");
     }
 
     @Test
@@ -249,9 +251,9 @@ public class MongoMKCommitMoveTest exten
         assertFalse(mk.nodeExists("/a", null));
         assertTrue(mk.nodeExists("/c", null));
 
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/c", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "c/key1", "value1");
+        assertPropertyValue(obj, "key1", "value1");
     }
 
     @Test
@@ -265,9 +267,9 @@ public class MongoMKCommitMoveTest exten
         assertTrue(mk.nodeExists("/c", null));
         assertTrue(mk.nodeExists("/c/b", null));
 
-        String nodes = mk.getNodes("/", null, 2 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/c/b", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "c/b/key1", "value1");
+        assertPropertyValue(obj, "key1", "value1");
     }
 
     @Test
@@ -281,9 +283,9 @@ public class MongoMKCommitMoveTest exten
         assertTrue(mk.nodeExists("/b", null));
         assertTrue(mk.nodeExists("/c", null));
 
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/c", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyValue(obj, "c/key1", "value1");
+        assertPropertyValue(obj, "key1", "value1");
     }
 
     @Test
@@ -297,9 +299,9 @@ public class MongoMKCommitMoveTest exten
         assertTrue(mk.nodeExists("/c", null));
         assertTrue(mk.nodeExists("/c/b", null));
 
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/c/b", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyNotExists(obj, "c/b/key1");
+        assertPropertyNotExists(obj, "key1");
     }
 
     @Test
@@ -311,9 +313,9 @@ public class MongoMKCommitMoveTest exten
         assertFalse(mk.nodeExists("/a", null));
         assertTrue(mk.nodeExists("/c", null));
 
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/c", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyNotExists(obj, "c/key1");
+        assertPropertyNotExists(obj, "key1");
     }
 
     @Test
@@ -327,9 +329,9 @@ public class MongoMKCommitMoveTest exten
         assertTrue(mk.nodeExists("/b", null));
         assertTrue(mk.nodeExists("/c", null));
 
-        String nodes = mk.getNodes("/", null, 1 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
+        String nodes = mk.getNodes("/c", null, 0 /*depth*/, 0 /*offset*/, -1 /*maxChildNodes*/,
null /*filter*/);
         JSONObject obj = parseJSONObject(nodes);
-        assertPropertyNotExists(obj, "c/key1");
+        assertPropertyNotExists(obj, "key1");
     }
 
     @Test



Mime
View raw message