Author: reschke
Date: Thu Jun 11 13:22:06 2015
New Revision: 1684886

URL: http://svn.apache.org/r1684886
Log:
OAK-2972: Simplify DocumentNodeStoreService handling of custom blob data 
sources, improve test coverage (ported to 1.2)

Modified:
    jackrabbit/oak/branches/1.2/   (props changed)
    
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
    
jackrabbit/oak/branches/1.2/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy

Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun 11 13:22:06 2015
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679958,1679961,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683278,1683323,1683687,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679958,1679961,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683278,1683323,1683687,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684868
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1684886&r1=1684885&r2=1684886&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
 (original)
+++ 
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
 Thu Jun 11 13:22:06 2015
@@ -48,7 +48,6 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Modified;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Reference;
@@ -210,17 +209,6 @@ public class DocumentNodeStoreService {
     )
     public static final String CUSTOM_BLOB_STORE = "customBlobStore";
 
-    /**
-     * Boolean value indicating a different DataSource has to be used for
-     * BlobStore
-     */
-    @Property(boolValue = false,
-            label = "Custom DataSource",
-            description = "Boolean value indicating that DataSource is 
configured " +
-                    "separately, and that it should be used"
-    )
-    public static final String CUSTOM_BLOB_DATA_SOURCE = 
"customBlobDataSource";
-
     private static final long MB = 1024 * 1024;
 
     private static enum DocumentStoreType {
@@ -311,7 +299,6 @@ public class DocumentNodeStoreService {
     private DocumentStoreType documentStoreType;
 
     private boolean customBlobStore;
-    private boolean customBlobDataSource;
 
     @Activate
     protected void activate(ComponentContext context, Map<String, ?> config) 
throws Exception {
@@ -321,7 +308,6 @@ public class DocumentNodeStoreService {
         executor.start(whiteboard);
         maxReplicationLagInSecs = toLong(config.get(PROP_REPLICATION_LAG), 
DEFAULT_MAX_REPLICATION_LAG);
         customBlobStore = toBoolean(prop(CUSTOM_BLOB_STORE), false);
-        customBlobDataSource = toBoolean(prop(CUSTOM_BLOB_DATA_SOURCE), false);
         documentStoreType = 
DocumentStoreType.fromString(PropertiesUtil.toString(config.get(PROP_DS_TYPE), 
"MONGO"));
 
         registerNodeStoreIfPossible();
@@ -331,12 +317,11 @@ public class DocumentNodeStoreService {
         if (context == null) {
             log.info("Component still not activated. Ignoring the 
initialization call");
         } else if (customBlobStore && blobStore == null) {
-            log.info("BlobStore use enabled. DocumentNodeStoreService would be 
initialized when "
+            log.info("Custom BlobStore use enabled. DocumentNodeStoreService 
would be initialized when "
                     + "BlobStore would be available");
-        } else if (documentStoreType == DocumentStoreType.RDB
-                && (dataSource == null || (customBlobDataSource && 
blobDataSource == null))) {
+        } else if (documentStoreType == DocumentStoreType.RDB && (dataSource 
== null || blobDataSource == null)) {
             log.info("DataSource use enabled. DocumentNodeStoreService would 
be initialized when "
-                    + "DataSource would be available");
+                    + "DataSource would be available (currently available: 
nodes: {}, blobs: {})", dataSource, blobDataSource);
         } else {
             registerNodeStore();
         }
@@ -369,7 +354,7 @@ public class DocumentNodeStoreService {
                 setCacheSegmentCount(cacheSegmentCount).
                 setCacheStackMoveDistance(cacheStackMoveDistance).
                 offHeapCacheSize(offHeapCache * MB);
-        
+
         if (persistentCache != null && persistentCache.length() > 0) {
             mkBuilder.setPersistentCache(persistentCache);
         }
@@ -381,14 +366,16 @@ public class DocumentNodeStoreService {
             mkBuilder.setBlobStore(blobStore);
         }
 
-        if (documentStoreType == DocumentStoreType.RDB){
+        if (documentStoreType == DocumentStoreType.RDB) {
             checkNotNull(dataSource, "DataStore type set [%s] but DataSource 
reference not initialized", PROP_DS_TYPE);
-            if(customBlobDataSource){
-                checkNotNull(blobDataSource, "DataStore type set [%s] and 
BlobStore is configured to use different " +
-                        "DataSource via [%s] but BlobDataSource reference not 
initialized", PROP_DS_TYPE, CUSTOM_BLOB_DATA_SOURCE);
+            if (!customBlobStore) {
+                checkNotNull(blobDataSource, "DataStore type set [%s] but 
BlobDataSource reference not initialized", PROP_DS_TYPE);
                 mkBuilder.setRDBConnection(dataSource, blobDataSource);
                 log.info("Connected to datasources {} {}", dataSource, 
blobDataSource);
             } else {
+                if (blobDataSource != null && blobDataSource != dataSource) {
+                    log.info("Ignoring blobDataSource {} as custom blob store 
takes precedence.", blobDataSource);
+                }
                 mkBuilder.setRDBConnection(dataSource);
                 log.info("Connected to datasource {}", dataSource);
             }
@@ -470,6 +457,7 @@ public class DocumentNodeStoreService {
 
     @SuppressWarnings("UnusedDeclaration")
     protected void bindDataSource(DataSource dataSource) throws IOException {
+        log.info("Initializing DocumentNodeStore with dataSource [{}]", 
dataSource);
         this.dataSource = dataSource;
         registerNodeStoreIfPossible();
     }
@@ -482,6 +470,7 @@ public class DocumentNodeStoreService {
 
     @SuppressWarnings("UnusedDeclaration")
     protected void bindBlobDataSource(DataSource dataSource) throws 
IOException {
+        log.info("Initializing DocumentNodeStore with blobDataSource [{}]", 
dataSource);
         this.blobDataSource = dataSource;
         registerNodeStoreIfPossible();
     }

Modified: 
jackrabbit/oak/branches/1.2/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy?rev=1684886&r1=1684885&r2=1684886&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.2/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
 (original)
+++ 
jackrabbit/oak/branches/1.2/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
 Thu Jun 11 13:22:06 2015
@@ -59,6 +59,33 @@ class DocumentNodeStoreConfigTest extend
 
         //3. Check that DS contains tables from both RDBBlobStore and 
RDBDocumentStore
         assert getExistingTables(ds).containsAll(['NODES', 'DATASTORE_META'])
+
+        //4. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds).size() == 1
+    }
+
+    @Test
+    public void testRDBDocumentStoreLateDataSource() throws Exception {
+        registry = repositoryFactory.initializeServiceRegistry(config)
+
+        //1. Create config for DocumentNodeStore with RDB enabled
+        createConfig([
+                
'org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService': [
+                        documentStoreType: 'RDB'
+                ]
+        ])
+
+        //2. Register the DataSource as a service
+        DataSource ds = createDS("jdbc:h2:mem:testRDBlateds;DB_CLOSE_DELAY=-1")
+        registry.registerService(DataSource.class.name, ds, 
['datasource.name': 'oak'] as Hashtable)
+
+        DocumentNodeStore ns = getServiceWithWait(NodeStore.class)
+
+        //3. Check that DS contains tables from both RDBBlobStore and 
RDBDocumentStore
+        assert getExistingTables(ds).containsAll(['NODES', 'DATASTORE_META'])
+
+        //4. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds).size() == 1
     }
 
     @Test
@@ -73,7 +100,6 @@ class DocumentNodeStoreConfigTest extend
         createConfig([
                 
'org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService': [
                         documentStoreType      : 'RDB',
-                        customBlobDataSource   : true,
                         'blobDataSource.target': '(datasource.name=oak-blob)',
                 ]
         ])
@@ -95,6 +121,9 @@ class DocumentNodeStoreConfigTest extend
         //DS2 should contain only RDBBlobStore tables
         assert !ds2Tables.contains('NODES')
         assert ds2Tables.contains('DATASTORE_META')
+
+        //4. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds1).size() == 1
     }
 
     @Test
@@ -102,14 +131,19 @@ class DocumentNodeStoreConfigTest extend
         registry = repositoryFactory.initializeServiceRegistry(config)
 
         //1. Register the DataSource as a service
-        DataSource ds = createDS("jdbc:h2:mem:testRDB3;DB_CLOSE_DELAY=-1")
-        registry.registerService(DataSource.class.name, ds, 
['datasource.name': 'oak'] as Hashtable)
+        DataSource ds1 = createDS("jdbc:h2:mem:testRDB3;DB_CLOSE_DELAY=-1")
+        registry.registerService(DataSource.class.name, ds1, 
['datasource.name': 'oak'] as Hashtable)
+
+        DataSource ds2 = createDS("jdbc:h2:mem:testRDB3b;DB_CLOSE_DELAY=-1")
+        registry.registerService(DataSource.class.name, ds2, 
['datasource.name': 'oak-blob'] as Hashtable)
 
         //2. Create config for DocumentNodeStore with RDB enabled
+        // (supply blobDataSource which should be ignored because customBlob 
takes precedence)
         createConfig([
                 
'org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService': [
                         documentStoreType: 'RDB',
-                        customBlobStore  : true
+                        'blobDataSource.target': '(datasource.name=oak-blob)',
+                        customBlobStore  : true,
                 ]
         ])
 
@@ -117,12 +151,20 @@ class DocumentNodeStoreConfigTest extend
 
         DocumentNodeStore ns = getServiceWithWait(NodeStore.class)
 
-        //3. Check that DS contains tables only from both RDBDocumentStore
-        List<String> dsTables = getExistingTables(ds)
+        //3. Check that DS1 contains tables only from both RDBDocumentStore
+        List<String> ds1Tables = getExistingTables(ds1)
+
+        //DS1 should contain RDBDocumentStore tables only
+        assert ds1Tables.contains('NODES')
+        assert !ds1Tables.contains('DATASTORE_META')
 
-        //DS1 should contain RDBDocumentStore tables
-        assert dsTables.contains('NODES')
-        assert !dsTables.contains('DATASTORE_META')
+        //4. Check that DS2 is empty
+        List<String> ds2Tables = getExistingTables(ds2)
+        assert !ds2Tables.contains('NODES')
+        assert !ds2Tables.contains('DATASTORE_META')
+
+        //5. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds1).size() == 1
     }
 
     @Test
@@ -204,6 +246,20 @@ class DocumentNodeStoreConfigTest extend
         return existing
     }
 
+    private List<String> getIdsOfClusterNodes(DataSource ds) {
+        Connection con = ds.connection
+        List<String> entries = []
+        try {
+            ResultSet rs = con.prepareStatement("SELECT ID FROM 
CLUSTERNODES").executeQuery()
+            while (rs.next()) {
+                entries << rs.get(1)
+            }
+        } finally {
+            con.close()
+        }
+        return entries
+    }
+    
     private DataSource createDS(String url) {
         DataSource ds = new JdbcDataSource()
         ds.url = url


Reply via email to