Author: reschke
Date: Tue May 26 14:39:57 2015
New Revision: 1681767

URL: http://svn.apache.org/r1681767
Log:
OAK-2901 - Allow RDBBlobStoreTest to run against multiple DB types

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreFixture.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreFixture.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreFixture.java?rev=1681767&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreFixture.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreFixture.java
 Tue May 26 14:39:57 2015
@@ -0,0 +1,99 @@
+/*
+ * 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.blob;
+
+import javax.sql.DataSource;
+
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class RDBBlobStoreFixture {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(RDBBlobStoreFixture.class);
+    public static final String TABLEPREFIX = "bstest_";
+
+    public abstract RDBBlobStore createRDBBlobStore();
+
+    public abstract String getName();
+
+    public abstract void dispose();
+
+    public abstract boolean isAvailable();
+
+    public static final RDBBlobStoreFixture RDB_DB2 = new MyFixture("RDB-DB2", 
System.getProperty("rdb-db2-jdbc-url",
+            "jdbc:db2://localhost:50000/OAK"), 
System.getProperty("rdb-db2-jdbc-user", "oak"), System.getProperty(
+            "rdb-db2-jdbc-passwd", "geheim"));
+    public static final RDBBlobStoreFixture RDB_MYSQL = new 
MyFixture("RDB-MySQL", System.getProperty("rdb-mysql-jdbc-url",
+            "jdbc:mysql://localhost:3306/oak"), 
System.getProperty("rdb-mysql-jdbc-user", "root"), System.getProperty(
+            "rdb-mysql-jdbc-passwd", "geheim"));
+    public static final RDBBlobStoreFixture RDB_ORACLE = new 
MyFixture("RDB-Oracle", System.getProperty("rdb-oracle-jdbc-url",
+            "jdbc:oracle:thin:@localhost:1521:orcl"), 
System.getProperty("rdb-oracle-jdbc-user", "system"), System.getProperty(
+            "rdb-oracle-jdbc-passwd", "geheim"));
+    public static final RDBBlobStoreFixture RDB_MSSQL = new 
MyFixture("RDB-MSSql", System.getProperty("rdb-mssql-jdbc-url",
+            "jdbc:sqlserver://localhost:1433;databaseName=OAK"), 
System.getProperty("rdb-mssql-jdbc-user", "sa"),
+            System.getProperty("rdb-mssql-jdbc-passwd", "geheim"));
+    public static final RDBBlobStoreFixture RDB_H2 = new 
MyFixture("RDB-H2(file)", System.getProperty("rdb-h2-jdbc-url",
+            "jdbc:h2:file:./target/ds-test"), 
System.getProperty("rdb-h2-jdbc-user", "sa"), System.getProperty(
+            "rdb-postgres-jdbc-passwd", ""));
+    public static final RDBBlobStoreFixture RDB_PG = new 
MyFixture("RDB-Postgres", System.getProperty("rdb-postgres-jdbc-url",
+            "jdbc:postgresql:oak"), 
System.getProperty("rdb-postgres-jdbc-user", "postgres"), System.getProperty(
+            "rdb-postgres-jdbc-passwd", "geheim"));
+
+    private static class MyFixture extends RDBBlobStoreFixture {
+
+        private String name;
+        private DataSource dataSource;
+        private RDBBlobStore bs;
+        private RDBOptions options = new 
RDBOptions().tablePrefix(TABLEPREFIX).dropTablesOnClose(true);
+
+        public MyFixture(String name, String url, String username, String 
passwd) {
+            this.name = name;
+            try {
+                dataSource = RDBDataSourceFactory.forJdbcUrl(url, username, 
passwd);
+            } catch (Exception ex) {
+                LOG.info("Database instance not available at " + url + ", 
skipping tests...", ex);
+            }
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public RDBBlobStore createRDBBlobStore() {
+            bs = new RDBBlobStore(dataSource, options);
+            return bs;
+        }
+
+        @Override
+        public boolean isAvailable() {
+            return dataSource != null;
+        }
+
+        @Override
+        public void dispose() {
+            if (this.bs != null) {
+                this.bs.close();
+                this.bs = null;
+            }
+        }
+    }
+}

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

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java?rev=1681767&r1=1681766&r2=1681767&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/blob/RDBBlobStoreTest.java
 Tue May 26 14:39:57 2015
@@ -21,19 +21,21 @@ import static org.junit.Assert.assertTru
 import java.io.IOException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Random;
 
 import org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore;
 import org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStoreFriend;
-import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
-import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions;
 import org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,24 +44,38 @@ import com.google.common.collect.Lists;
 /**
  * Tests the RDBBlobStore implementation.
  */
+@RunWith(Parameterized.class)
 public class RDBBlobStoreTest extends AbstractBlobStoreTest {
 
-    private RDBBlobStore blobStore;
-
-    private static final String URL = System.getProperty("rdb.jdbc-url", 
-                    "jdbc:h2:file:./target/db/RDBBlobStoreTest");
+    @Parameterized.Parameters
+    public static Collection<Object[]> fixtures() {
+        Collection<Object[]> result = new ArrayList<Object[]>();
+        RDBBlobStoreFixture candidates[] = new RDBBlobStoreFixture[] { 
RDBBlobStoreFixture.RDB_DB2, RDBBlobStoreFixture.RDB_H2,
+                RDBBlobStoreFixture.RDB_MSSQL, RDBBlobStoreFixture.RDB_MYSQL, 
RDBBlobStoreFixture.RDB_ORACLE,
+                RDBBlobStoreFixture.RDB_PG };
+
+        for (RDBBlobStoreFixture bsf : candidates) {
+            if (bsf.isAvailable()) {
+                result.add(new Object[] { bsf });
+            }
+        }
 
-    private static final String USERNAME = System.getProperty("rdb.jdbc-user", 
"sa");
+        return result;
+    }
 
-    private static final String PASSWD = System.getProperty("rdb.jdbc-passwd", 
"");
+    private RDBBlobStore blobStore;
+    private String blobStoreName;
 
     private static final Logger LOG = 
LoggerFactory.getLogger(RDBBlobStoreTest.class);
 
+    public RDBBlobStoreTest(RDBBlobStoreFixture bsf) {
+        blobStore = bsf.createRDBBlobStore();
+        blobStoreName = bsf.getName();
+    }
+
     @Before
     @Override
     public void setUp() throws Exception {
-        blobStore = new RDBBlobStore(RDBDataSourceFactory.forJdbcUrl(URL, 
USERNAME, PASSWD), new RDBOptions().tablePrefix("test")
-                .dropTablesOnClose(true));
         blobStore.setBlockSize(128);
         blobStore.setBlockSizeMin(48);
         this.store = blobStore;
@@ -109,7 +125,7 @@ public class RDBBlobStoreTest extends Ab
             }
         }
 
-        LOG.info("max blob length for " + URL + " was " + test);
+        LOG.info("max blob length for " + blobStoreName + " was " + test);
 
         int expected = Math.max(blobStore.getBlockSize(), 2 * 1024 * 1024);
         assertTrue("expected supported block size is " + expected + ", but 
measured: " + test, test >= expected);


Reply via email to