Author: reschke
Date: Fri Mar 21 14:37:37 2014
New Revision: 1579947

URL: http://svn.apache.org/r1579947
Log:
OAK-1590 - DocumentStore-specific test framework (WIP)

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java?rev=1579947&r1=1579946&r2=1579947&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
 Fri Mar 21 14:37:37 2014
@@ -19,49 +19,32 @@ package org.apache.jackrabbit.oak.plugin
 import java.util.ArrayList;
 import java.util.Collection;
 
-import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.mongodb.DB;
 
 @RunWith(Parameterized.class)
 public abstract class AbstractDocumentStoreTest {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(AbstractDocumentStoreTest.class);
-
+    protected String dsname;
     protected DocumentStore ds;
 
-    public AbstractDocumentStoreTest(DocumentStore ds) {
-        this.ds = ds;
+    public AbstractDocumentStoreTest(DocumentStoreFixture dsf) {
+        this.ds = dsf.getDocumentStore();
+        this.dsname = dsf.getName();
     }
 
     @Parameterized.Parameters
     public static Collection<Object[]> fixtures() {
         Collection<Object[]> result = new ArrayList<Object[]>();
-        result.add(new Object[] { new MemoryDocumentStore() });
-        result.add(new Object[] { new RDBDocumentStore(new 
DocumentMK.Builder()) });
-        DocumentStore md = getMongoDS();
-        if (md != null) {
-            result.add(new Object[] { md });
-        }
-        return result;
-    }
+        DocumentStoreFixture candidates[] = new DocumentStoreFixture[] { 
DocumentStoreFixture.MEMORY, DocumentStoreFixture.MONGO,
+                DocumentStoreFixture.RDB_H2, DocumentStoreFixture.RDB_PG};
 
-    private static DocumentStore getMongoDS() {
-        String instance = "mongodb://localhost:27017/oak";
-        try {
-            MongoConnection connection = new MongoConnection(instance);
-            DB mongoDB = connection.getDB();
-            return new MongoDocumentStore(mongoDB, new DocumentMK.Builder());
-        } catch (Exception e) {
-            LOG.info("Mongo instance not available at " + instance + ", 
skipping tests...");
-            return null;
+        for (DocumentStoreFixture dsf : candidates) {
+            if (dsf.isAvailable()) {
+                result.add(new Object[] { dsf });
+            }
         }
+
+        return result;
     }
 }

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1579947&r1=1579946&r2=1579947&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
 Fri Mar 21 14:37:37 2014
@@ -36,8 +36,8 @@ public class BasicDocumentStoreTest exte
 
     private Set<String> removeMe = new HashSet<String>();
 
-    public BasicDocumentStoreTest(DocumentStore ds) {
-        super(ds);
+    public BasicDocumentStoreTest(DocumentStoreFixture dsf) {
+        super(dsf);
     }
 
     @After
@@ -93,7 +93,7 @@ public class BasicDocumentStoreTest exte
             }
         }
 
-        LOG.info("max id for " + super.ds.getClass() + " was " + test);
+        LOG.info("max id length for " + super.dsname + " was " + test);
     }
 
     private static String generateId(int length) {

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java?rev=1579947&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
 Fri Mar 21 14:37:37 2014
@@ -0,0 +1,140 @@
+/*
+ * 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.oak.plugins.document;
+
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mongodb.DB;
+
+public abstract class DocumentStoreFixture {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(DocumentStoreFixture.class);
+
+    public static final DocumentStoreFixture MEMORY = new MemoryFixture();
+    public static final DocumentStoreFixture RDB_H2 = new RDBH2Fixture();
+    public static final DocumentStoreFixture RDB_PG = new 
RDBFixture("RDB-Postgres", "jdbc:postgresql:oak", "postgres", "geheim");
+    public static final DocumentStoreFixture MONGO = new 
MongoFixture("mongodb://localhost:27017/oak");
+
+    public abstract String getName();
+
+    public abstract DocumentStore getDocumentStore();
+
+    public boolean isAvailable() {
+        return true;
+    }
+
+    private static class MemoryFixture extends DocumentStoreFixture {
+
+        DocumentStore ds = new MemoryDocumentStore();
+
+        @Override
+        public String getName() {
+            return "Memory";
+        }
+
+        @Override
+        public DocumentStore getDocumentStore() {
+            return ds;
+        }
+    }
+
+    private static class RDBH2Fixture extends DocumentStoreFixture {
+
+        DocumentStore ds = new RDBDocumentStore(new DocumentMK.Builder());
+
+        @Override
+        public String getName() {
+            return "RDB-on-HS-in-memory";
+        }
+
+        @Override
+        public DocumentStore getDocumentStore() {
+            return ds;
+        }
+    }
+
+    private static class RDBFixture extends DocumentStoreFixture {
+
+        DocumentStore ds;
+        String name;
+
+        public RDBFixture(String name, String url, String username, String 
passwd) {
+            this.name = name;
+            try {
+                DataSource datas = RDBDataSourceFactory.forJdbcUrl(url, 
username, passwd);
+                this.ds = new RDBDocumentStore(datas, new 
DocumentMK.Builder());
+            } catch (SQLException ex) {
+                LOG.info("Postgres instance not available at " + url + ", 
skipping tests...");
+            }
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public DocumentStore getDocumentStore() {
+            return ds;
+        }
+
+        @Override
+        public boolean isAvailable() {
+            return this.ds != null;
+        }
+    }
+
+    private static class MongoFixture extends DocumentStoreFixture {
+
+        DocumentStore ds;
+
+        public MongoFixture(String db) {
+            try {
+                MongoConnection connection = new MongoConnection(db);
+                DB mongoDB = connection.getDB();
+                this.ds = new MongoDocumentStore(mongoDB, new 
DocumentMK.Builder());
+            } catch (Exception e) {
+                LOG.info("Mongo instance not available at " + db + ", skipping 
tests...");
+            }
+        }
+
+        @Override
+        public String getName() {
+            return "MongoDB";
+        }
+
+        @Override
+        public DocumentStore getDocumentStore() {
+            return ds;
+        }
+
+        @Override
+        public boolean isAvailable() {
+            return this.ds != null;
+        }
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to