jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1411624 - in /jackrabbit/oak/trunk: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/mk/simple/ oak-it/mk/ oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/ oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/ oak-...
Date Tue, 20 Nov 2012 11:42:43 GMT
Author: jukka
Date: Tue Nov 20 11:42:42 2012
New Revision: 1411624

URL: http://svn.apache.org/viewvc?rev=1411624&view=rev
Log:
OAK-293: MongoDB-based MicroKernel

Run the MongoMK integration tests in oak-it-mk.

Added:
    jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/BaseMongoMicroKernelFixture.java
      - copied, changed from r1411623, jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java
    jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoGridFSMicroKernelFixture.java
      - copied, changed from r1411623, jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
    jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoMicroKernelFixture.java
      - copied, changed from r1411623, jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
    jackrabbit/oak/trunk/oak-it/mk/src/test/resources/logging.properties
Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/mk/simple/SimpleKernelImplFixture.java
    jackrabbit/oak/trunk/oak-it/mk/pom.xml
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java
    jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/ClientServerFixture.java
    jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
    jackrabbit/oak/trunk/oak-it/mk/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture
    jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/mk/simple/SimpleKernelImplFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/mk/simple/SimpleKernelImplFixture.java?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/mk/simple/SimpleKernelImplFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/old/mk/simple/SimpleKernelImplFixture.java
Tue Nov 20 11:42:42 2012
@@ -23,6 +23,11 @@ import org.apache.jackrabbit.oak.plugins
 public class SimpleKernelImplFixture implements MicroKernelFixture {
 
     @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
     public void setUpCluster(MicroKernel[] cluster) {
         MicroKernel mk =
                 new SimpleKernelImpl("mem:SimpleKernelImplFixture");

Modified: jackrabbit/oak/trunk/oak-it/mk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/pom.xml?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-it/mk/pom.xml Tue Nov 20 11:42:42 2012
@@ -44,6 +44,18 @@
         </plugin>
       </plugins>
     </pluginManagement>
+    <plugins>
+      <plugin>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <configuration>
+          <systemPropertyVariables>
+            <java.util.logging.config.file>
+              src/test/resources/logging.properties
+            </java.util.logging.config.file>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
   </build>
 
   <dependencies>
@@ -65,6 +77,13 @@
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>oak-mk-remote</artifactId>
       <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>oak-mongomk</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>com.googlecode.json-simple</groupId>
@@ -78,6 +97,12 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+        <groupId>org.slf4j</groupId>
+        <artifactId>jul-to-slf4j</artifactId>
+        <version>1.6.4</version>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
       <version>${guava.version}</version>

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
Tue Nov 20 11:42:42 2012
@@ -57,9 +57,10 @@ public abstract class AbstractMicroKerne
         Class<MicroKernelFixture> iface = MicroKernelFixture.class;
         ServiceLoader<MicroKernelFixture> loader =
                 ServiceLoader.load(iface, iface.getClassLoader());
-        
         for (MicroKernelFixture fixture : loader) {
-            fixtures.add(new Object[] { fixture });
+            if (fixture.isAvailable()) {
+                fixtures.add(new Object[] { fixture });
+            }
         }
 
         return fixtures;
@@ -108,7 +109,7 @@ public abstract class AbstractMicroKerne
      * this test case.
      */
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
         fixture.setUpCluster(mks);
         mk = mks[0];
         addInitialTestContent();

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java
Tue Nov 20 11:42:42 2012
@@ -25,6 +25,15 @@ import org.apache.jackrabbit.mk.api.Micr
 public interface MicroKernelFixture {
 
     /**
+     * Checks whether this fixture is currently available. For example
+     * a database-based fixture would only be available when the underlying
+     * database service is running.
+     *
+     * @return <code>true</code> iff the fixture is available
+     */
+    boolean isAvailable();
+
+    /**
      * Creates a new {@link MicroKernel} cluster with as many nodes as the
      * given array has elements. References to the cluster nodes are stored
      * in the given array. The initial state of the cluster consists of just
@@ -36,8 +45,9 @@ public interface MicroKernelFixture {
      *
      * @param cluster array to which references to all nodes of the
      *                created cluster should be stored
+     * @throws Exception if the cluster could not be set up
      */
-    void setUpCluster(MicroKernel[] cluster);
+    void setUpCluster(MicroKernel[] cluster) throws Exception;
 
     /**
      * Ensures that all content changes seen by one of the given cluster

Copied: jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/BaseMongoMicroKernelFixture.java
(from r1411623, jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/BaseMongoMicroKernelFixture.java?p2=jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/BaseMongoMicroKernelFixture.java&p1=jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java&r1=1411623&r2=1411624&rev=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/BaseMongoMicroKernelFixture.java
Tue Nov 20 11:42:42 2012
@@ -14,10 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.test.it;
-
-import java.io.InputStream;
-import java.util.Properties;
+package org.apache.jackrabbit.mk.test;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.blobs.BlobStore;
@@ -26,46 +23,54 @@ import org.apache.jackrabbit.mongomk.imp
 import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
 import org.apache.jackrabbit.mongomk.impl.blob.MongoBlobStore;
-import org.junit.Assert;
 
+import com.mongodb.BasicDBObject;
 import com.mongodb.DB;
 
 public abstract class BaseMongoMicroKernelFixture implements MicroKernelFixture {
 
-    protected static MongoConnection mongoConnection;
+    protected static final String HOST =
+            System.getProperty("mongo.host", "127.0.0.1");
 
-    private static MongoConnection createMongoConnection() {
-        try {
-            InputStream is = BaseMongoMicroKernelFixture.class.getResourceAsStream("/config.cfg");
-            Properties properties = new Properties();
-            properties.load(is);
-
-            String host = properties.getProperty("mongo.host");
-            int port = Integer.parseInt(properties.getProperty("mongo.port"));
-            String database = properties.getProperty("mongo.db");
+    protected static final int PORT =
+            Integer.getInteger("mongo.port", 27017);
 
-            return new MongoConnection(host, port, database);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+    protected static final String DB =
+            System.getProperty("mongo.db", "mk-tf");
+
+    private static MongoConnection mongoConnection = null;
+
+    public static MongoConnection getMongoConnection() throws Exception {
+        if (mongoConnection == null) {
+            mongoConnection = new MongoConnection(HOST, PORT, DB);
         }
+        return mongoConnection;
     }
 
     @Override
-    public void setUpCluster(MicroKernel[] cluster) {
+    public boolean isAvailable() {
         try {
-            mongoConnection = createMongoConnection();
-            DB db = mongoConnection.getDB();
-            dropCollections(db);
-
-            MongoNodeStore nodeStore = new MongoNodeStore(db);
-            BlobStore blobStore = getBlobStore(db);
-            MicroKernel mk = new MongoMicroKernel(mongoConnection, nodeStore, blobStore);
-
-            for (int i = 0; i < cluster.length; i++) {
-                cluster[i] = mk;
-            }
+            MongoConnection connection =
+                    BaseMongoMicroKernelFixture.getMongoConnection();
+            connection.getDB().command(new BasicDBObject("ping", 1));
+            return true;
         } catch (Exception e) {
-            Assert.fail(e.getMessage());
+            return false;
+        }
+    }
+
+    @Override
+    public void setUpCluster(MicroKernel[] cluster) throws Exception {
+        MongoConnection connection = getMongoConnection();
+        DB db = connection.getDB();
+        dropCollections(db);
+
+        MongoNodeStore nodeStore = new MongoNodeStore(db);
+        BlobStore blobStore = getBlobStore(db);
+        MicroKernel mk = new MongoMicroKernel(connection, nodeStore, blobStore);
+
+        for (int i = 0; i < cluster.length; i++) {
+            cluster[i] = mk;
         }
     }
 
@@ -76,7 +81,7 @@ public abstract class BaseMongoMicroKern
     @Override
     public void tearDownCluster(MicroKernel[] cluster) {
         try {
-            DB db = mongoConnection.getDB();
+            DB db = getMongoConnection().getDB();
             dropCollections(db);
         } catch (Exception e) {
             e.printStackTrace();

Modified: jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/ClientServerFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/ClientServerFixture.java?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/ClientServerFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/ClientServerFixture.java
Tue Nov 20 11:42:42 2012
@@ -31,6 +31,11 @@ public class ClientServerFixture impleme
     private Server server;
 
     @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
     public void setUpCluster(MicroKernel[] cluster) {
         mk = new MicroKernelImpl();
         server = new Server(mk);

Modified: jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
Tue Nov 20 11:42:42 2012
@@ -22,6 +22,11 @@ import org.apache.jackrabbit.mk.core.Mic
 public class MicroKernelImplFixture implements MicroKernelFixture {
 
     @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
     public void setUpCluster(MicroKernel[] cluster) {
         MicroKernel mk = new MicroKernelImpl();
         for (int i = 0; i < cluster.length; i++) {

Copied: jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoGridFSMicroKernelFixture.java
(from r1411623, jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoGridFSMicroKernelFixture.java?p2=jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoGridFSMicroKernelFixture.java&p1=jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java&r1=1411623&r2=1411624&rev=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoGridFSMicroKernelFixture.java
Tue Nov 20 11:42:42 2012
@@ -16,28 +16,15 @@
  */
 package org.apache.jackrabbit.mk.test;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mongomk.impl.blob.MongoGridFSBlobStore;
 
-public class MicroKernelImplFixture implements MicroKernelFixture {
+import com.mongodb.DB;
 
-    @Override
-    public void setUpCluster(MicroKernel[] cluster) {
-        MicroKernel mk = new MicroKernelImpl();
-        for (int i = 0; i < cluster.length; i++) {
-            cluster[i] = mk;
-        }
-    }
-
-    @Override
-    public void syncMicroKernelCluster(MicroKernel... nodes) {
-    }
+public class MongoGridFSMicroKernelFixture extends BaseMongoMicroKernelFixture {
 
     @Override
-    public void tearDownCluster(MicroKernel[] cluster) {
-        for (int i = 0; i < cluster.length; i++) {
-            ((MicroKernelImpl) cluster[i]).dispose();
-        }
+    protected BlobStore getBlobStore(DB db) {
+        return new MongoGridFSBlobStore(db);
     }
-
 }

Copied: jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoMicroKernelFixture.java
(from r1411623, jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoMicroKernelFixture.java?p2=jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoMicroKernelFixture.java&p1=jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java&r1=1411623&r2=1411624&rev=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MicroKernelImplFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoMicroKernelFixture.java
Tue Nov 20 11:42:42 2012
@@ -16,28 +16,15 @@
  */
 package org.apache.jackrabbit.mk.test;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mongomk.impl.blob.MongoBlobStore;
 
-public class MicroKernelImplFixture implements MicroKernelFixture {
+import com.mongodb.DB;
 
-    @Override
-    public void setUpCluster(MicroKernel[] cluster) {
-        MicroKernel mk = new MicroKernelImpl();
-        for (int i = 0; i < cluster.length; i++) {
-            cluster[i] = mk;
-        }
-    }
-
-    @Override
-    public void syncMicroKernelCluster(MicroKernel... nodes) {
-    }
+public class MongoMicroKernelFixture extends BaseMongoMicroKernelFixture {
 
     @Override
-    public void tearDownCluster(MicroKernel[] cluster) {
-        for (int i = 0; i < cluster.length; i++) {
-            ((MicroKernelImpl) cluster[i]).dispose();
-        }
+    protected BlobStore getBlobStore(DB db) {
+        return new MongoBlobStore(db);
     }
-
-}
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-it/mk/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/test/resources/META-INF/services/org.apache.jackrabbit.mk.test.MicroKernelFixture
Tue Nov 20 11:42:42 2012
@@ -15,3 +15,5 @@
 
 org.apache.jackrabbit.mk.test.MicroKernelImplFixture
 org.apache.jackrabbit.mk.test.ClientServerFixture
+org.apache.jackrabbit.mk.test.MongoMicroKernelFixture
+org.apache.jackrabbit.mk.test.MongoGridFSMicroKernelFixture

Added: jackrabbit/oak/trunk/oak-it/mk/src/test/resources/logging.properties
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/resources/logging.properties?rev=1411624&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/test/resources/logging.properties (added)
+++ jackrabbit/oak/trunk/oak-it/mk/src/test/resources/logging.properties Tue Nov 20 11:42:42
2012
@@ -0,0 +1,16 @@
+# 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.
+
+handlers = org.slf4j.bridge.SLF4JBridgeHandler

Modified: jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java?rev=1411624&r1=1411623&r2=1411624&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk-test/src/test/java/org/apache/jackrabbit/mongomk/test/it/BaseMongoMicroKernelFixture.java
Tue Nov 20 11:42:42 2012
@@ -16,9 +16,6 @@
  */
 package org.apache.jackrabbit.mongomk.test.it;
 
-import java.io.InputStream;
-import java.util.Properties;
-
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.blobs.BlobStore;
 import org.apache.jackrabbit.mk.test.MicroKernelFixture;
@@ -26,46 +23,54 @@ import org.apache.jackrabbit.mongomk.imp
 import org.apache.jackrabbit.mongomk.impl.MongoMicroKernel;
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
 import org.apache.jackrabbit.mongomk.impl.blob.MongoBlobStore;
-import org.junit.Assert;
 
+import com.mongodb.BasicDBObject;
 import com.mongodb.DB;
 
 public abstract class BaseMongoMicroKernelFixture implements MicroKernelFixture {
 
-    protected static MongoConnection mongoConnection;
+    protected static final String HOST =
+            System.getProperty("mongo.host", "127.0.0.1");
 
-    private static MongoConnection createMongoConnection() {
-        try {
-            InputStream is = BaseMongoMicroKernelFixture.class.getResourceAsStream("/config.cfg");
-            Properties properties = new Properties();
-            properties.load(is);
-
-            String host = properties.getProperty("mongo.host");
-            int port = Integer.parseInt(properties.getProperty("mongo.port"));
-            String database = properties.getProperty("mongo.db");
+    protected static final int PORT =
+            Integer.getInteger("mongo.port", 27017);
 
-            return new MongoConnection(host, port, database);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+    protected static final String DB =
+            System.getProperty("mongo.db", "mk-tf");
+
+    private static MongoConnection mongoConnection = null;
+
+    public static MongoConnection getMongoConnection() throws Exception {
+        if (mongoConnection == null) {
+            mongoConnection = new MongoConnection(HOST, PORT, DB);
         }
+        return mongoConnection;
     }
 
     @Override
-    public void setUpCluster(MicroKernel[] cluster) {
+    public boolean isAvailable() {
         try {
-            mongoConnection = createMongoConnection();
-            DB db = mongoConnection.getDB();
-            dropCollections(db);
-
-            MongoNodeStore nodeStore = new MongoNodeStore(db);
-            BlobStore blobStore = getBlobStore(db);
-            MicroKernel mk = new MongoMicroKernel(mongoConnection, nodeStore, blobStore);
-
-            for (int i = 0; i < cluster.length; i++) {
-                cluster[i] = mk;
-            }
+            MongoConnection connection =
+                    BaseMongoMicroKernelFixture.getMongoConnection();
+            connection.getDB().command(new BasicDBObject("ping", 1));
+            return true;
         } catch (Exception e) {
-            Assert.fail(e.getMessage());
+            return false;
+        }
+    }
+
+    @Override
+    public void setUpCluster(MicroKernel[] cluster) throws Exception {
+        MongoConnection connection = getMongoConnection();
+        DB db = connection.getDB();
+        dropCollections(db);
+
+        MongoNodeStore nodeStore = new MongoNodeStore(db);
+        BlobStore blobStore = getBlobStore(db);
+        MicroKernel mk = new MongoMicroKernel(connection, nodeStore, blobStore);
+
+        for (int i = 0; i < cluster.length; i++) {
+            cluster[i] = mk;
         }
     }
 
@@ -76,7 +81,7 @@ public abstract class BaseMongoMicroKern
     @Override
     public void tearDownCluster(MicroKernel[] cluster) {
         try {
-            DB db = mongoConnection.getDB();
+            DB db = getMongoConnection().getDB();
             dropCollections(db);
         } catch (Exception e) {
             e.printStackTrace();



Mime
View raw message