jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1445703 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/ test/java/org/apache/jackrabbit/mongomk/prototype/
Date Wed, 13 Feb 2013 16:10:42 GMT
Author: thomasm
Date: Wed Feb 13 16:10:41 2013
New Revision: 1445703

URL: http://svn.apache.org/r1445703
Log:
OAK-619 Lock-free MongoMK implementation

Added:
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java
Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java

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=1445703&r1=1445702&r2=1445703&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
Wed Feb 13 16:10:41 2013
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.mongomk.pr
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.apache.jackrabbit.mongomk.impl.model.MongoNode;
 import org.apache.jackrabbit.mongomk.prototype.UpdateOp.Operation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -78,7 +77,7 @@ public class MongoDocumentStore implemen
                     break;
                 }
                 case INCREMENT: {
-                    incUpdates.append(k, (Long)op.value);
+                    incUpdates.append(k, op.value);
                     break;
                 }
                 case ADD_MAP_ENTRY: {
@@ -121,14 +120,16 @@ public class MongoDocumentStore implemen
         nodesCollection.ensureIndex(index, options);
     }
 
-    private Map<String, Object> convertFromDBObject(DBObject n) {
+    private static Map<String, Object> convertFromDBObject(DBObject n) {
         Map<String, Object> copy = Utils.newMap();
-        synchronized (n) {
-            for (String key : n.keySet()) {
-                copy.put(key, n.get(key));
+        if (n != null) {
+            synchronized (n) {
+                for (String key : n.keySet()) {
+                    copy.put(key, n.get(key));
+                }
             }
-            return copy;
         }
+        return copy;
     }
 
     private DBCollection getDBCollection(Collection collection) {

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java?rev=1445703&r1=1445702&r2=1445703&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDocumentStoreTest.java
Wed Feb 13 16:10:41 2013
@@ -24,17 +24,33 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.jackrabbit.mongomk.AbstractMongoConnectionTest;
 import org.apache.jackrabbit.mongomk.prototype.DocumentStore.Collection;
-import org.junit.Ignore;
 import org.junit.Test;
 
-public class MongoDocumentStoreTest extends AbstractMongoConnectionTest {
-
+public class MongoDocumentStoreTest {
+    
+    private static boolean MONGO_DB = false;
+    
+    // private final static int NODE_COUNT = 2000;
+    private static int NODE_COUNT = 10;
+
+    DocumentStore openDocumentStore() {
+        if (MONGO_DB) {
+            return new MongoDocumentStore(MongoUtils.getConnection().getDB());
+        }
+        return new MemoryDocumentStore();
+    }
+    
+    void dropCollections() {
+        if (MONGO_DB) {
+            MongoUtils.dropCollections(MongoUtils.getConnection().getDB());
+        }
+    }
+    
     @Test
-    @Ignore
     public void addGetAndRemove() throws Exception {
-        DocumentStore docStore = new MongoDocumentStore(mongoConnection.getDB());
+        dropCollections();
+        DocumentStore docStore = openDocumentStore();
 
         UpdateOp updateOp = new UpdateOp("/");
         updateOp.addMapEntry("property1", "key1", "value1");
@@ -43,11 +59,11 @@ public class MongoDocumentStoreTest exte
         docStore.createOrUpdate(Collection.NODES, updateOp);
         Map<String, Object> obj = docStore.find(Collection.NODES, "/");
 
-        Map property1 = (Map)obj.get("property1");
-        String value1 = (String)property1.get("key1");
+        Map<?, ?> property1 = (Map<?, ?>) obj.get("property1");
+        String value1 = (String) property1.get("key1");
         assertEquals("value1", value1);
 
-        Long value2 = (Long)obj.get("property2");
+        Long value2 = (Long) obj.get("property2");
         assertEquals(Long.valueOf(1), value2);
 
         String value3 = (String)obj.get("property3");
@@ -56,18 +72,20 @@ public class MongoDocumentStoreTest exte
         docStore.remove(Collection.NODES, "/");
         obj = docStore.find(Collection.NODES, "/");
         assertTrue(obj == null);
+        dropCollections();
     }
 
     @Test
-    @Ignore
     public void addLotsOfNodes() throws Exception {
+
         char[] nPrefix = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
-        int nNodes = 2000;
+        int nNodes = NODE_COUNT;
 
         for (int nThreads = 1; nThreads < 32; nThreads = nThreads * 2) {
-            DocumentStore docStore = new MongoDocumentStore(mongoConnection.getDB());
+            DocumentStore docStore = openDocumentStore();
+            dropCollections();
 
-            System.out.println("Adding and updating " + nNodes + " nodes in each " + nThreads
+ " threads");
+            log("Adding and updating " + nNodes + " nodes in each " + nThreads + " threads");
             long start = System.currentTimeMillis();
 
             ExecutorService executor = Executors.newFixedThreadPool(nThreads);
@@ -78,9 +96,18 @@ public class MongoDocumentStoreTest exte
             executor.awaitTermination(1, TimeUnit.MINUTES);
 
             long end = System.currentTimeMillis();
-            System.out.println("Done: " + (end - start) + "ms");
-            dropCollections(mongoConnection.getDB());
+            log("Done: " + (end - start) + "ms");
+            
+        }
+        dropCollections();
+
+    }
+    
+    private static void log(String s) {
+        if (NODE_COUNT < 100) {
+            return;
         }
+        System.out.println(s);
     }
 
     private static class AddAndUpdateNodesTask implements Runnable {

Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java?rev=1445703&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java
(added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoUtils.java
Wed Feb 13 16:10:41 2013
@@ -0,0 +1,79 @@
+/*
+ * 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.impl.MongoConnection;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+
+/**
+ * A utility class to get a {@link MongoConnection} to a local mongo instance
+ * and clean a test database.
+ */
+public class MongoUtils {
+
+    protected static final String HOST =
+            System.getProperty("mongo.host", "127.0.0.1");
+
+    protected static final int PORT =
+            Integer.getInteger("mongo.port", 27017);
+
+    protected static final String DB =
+            System.getProperty("mongo.db", "MongoMKDB");
+
+    protected static MongoConnection mongoConnection;
+
+    protected static Exception exception;
+
+    /**
+     * Get a connection if available. If not available, null is returned. If
+     * called again, the same connection is returned, or null is returned if
+     * there was an error.
+     * 
+     * @return the connection or null
+     */
+    public static MongoConnection getConnection() {
+        if (exception != null) {
+            return null;
+        }
+        if (mongoConnection == null) {
+            try {
+                mongoConnection = new MongoConnection(HOST, PORT, DB);
+                mongoConnection.getDB().command(new BasicDBObject("ping", 1));
+                dropCollections(mongoConnection.getDB());
+            } catch (Exception e) {
+                exception = e;
+            }
+        }
+        return mongoConnection;
+    }
+    
+    /**
+     * Drop all user defined collections. System collections are not dropped.
+     * 
+     * @param db the connection
+     */
+    public static void dropCollections(DB db) {
+        for (String name : db.getCollectionNames()) {
+            if (!name.startsWith("system.")) {
+                db.getCollection(name).drop();
+            }
+        }
+    }
+
+}



Mime
View raw message