You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by am...@apache.org on 2019/06/10 08:44:23 UTC

svn commit: r1860931 - /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/binary/fixtures/nodestore/DocumentMongoNodeStoreFixture.java

Author: amitj
Date: Mon Jun 10 08:44:23 2019
New Revision: 1860931

URL: http://svn.apache.org/viewvc?rev=1860931&view=rev
Log:
OAK-8394: Fix BinaryAccessDSGCIT failing intermittently for Mongo

Catching exception if any to ignore tests and also moved init of mongo connection factory only when datastore available.

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/binary/fixtures/nodestore/DocumentMongoNodeStoreFixture.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/binary/fixtures/nodestore/DocumentMongoNodeStoreFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/binary/fixtures/nodestore/DocumentMongoNodeStoreFixture.java?rev=1860931&r1=1860930&r2=1860931&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/binary/fixtures/nodestore/DocumentMongoNodeStoreFixture.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/binary/fixtures/nodestore/DocumentMongoNodeStoreFixture.java Mon Jun 10 08:44:23 2019
@@ -64,20 +64,33 @@ public class DocumentMongoNodeStoreFixtu
     private final Table<NodeStore, String, Object> components = HashBasedTable.create();
     private MongoConnection connection;
     private final Clock clock;
-    public final MongoConnectionFactory connFactory = new MongoConnectionFactory();
+    public MongoConnectionFactory connFactory;
     private String db;
     public DocumentMongoNodeStoreFixture(@Nullable DataStoreFixture dataStoreFixture) {
         this.dataStoreFixture = dataStoreFixture;
         this.clock = new Clock.Virtual();
     }
 
+    /**
+     * Mandatory to be called to initialize the connectionFactory.
+     * Lazy initializes it to limit docker container init only if relevant datastores available.
+     *
+     * @return
+     */
     @Override
     public boolean isAvailable() {
         db = UUID.randomUUID().toString();
-        this.connection = connFactory.getConnection(db);
 
         // if a DataStore is configured, it must be available for our NodeStore to be available
-        return (dataStoreFixture == null || dataStoreFixture.isAvailable()) && (connection != null);
+        if ((dataStoreFixture == null || dataStoreFixture.isAvailable())) {
+            try {
+                this.connFactory = new MongoConnectionFactory();
+                this.connection = connFactory.getConnection(db);
+
+                return (connection != null);
+            } catch (Exception e) {}
+        }
+        return false;
     }
 
     @Override
@@ -126,7 +139,7 @@ public class DocumentMongoNodeStoreFixtu
     @Override
     public void dispose(NodeStore nodeStore) {
         try {
-            if (nodeStore instanceof DocumentNodeStore) {
+            if (nodeStore != null && nodeStore instanceof DocumentNodeStore) {
                 ((DocumentNodeStore)nodeStore).dispose();
             }
 
@@ -138,7 +151,9 @@ public class DocumentMongoNodeStoreFixtu
                 FileUtils.deleteQuietly(dataStoreFolder);
             }
             MongoUtils.dropDatabase(db);
-            connection.close();
+            if (connection != null) {
+                connection.close();
+            }
         } finally {
             components.row(nodeStore).clear();
         }