Author: mreutegg
Date: Tue Mar  6 15:17:08 2018
New Revision: 1825993

URL: http://svn.apache.org/viewvc?rev=1825993&view=rev
Log:
OAK-7309: MongoDocumentStoreMetricsTest fails sporadically

Merged revision 1825992 from trunk

Modified:
    jackrabbit/oak/branches/1.8/   (props changed)
    
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java

Propchange: jackrabbit/oak/branches/1.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar  6 15:17:08 2018
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821665,1821668,1821681,1822121,1822201,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1824962,1825362,1825381,1825442,1825448,1825466,1825470,1825475,1825523,1825525,1825619-1825621,1825651
+/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821130,1821140-1821141,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821665,1821668,1821681,1822121,1822201,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1824962,1825362,1825381,1825442,1825448,1825466,1825470,1825475,1825523,1825525,1825619-1825621,1825651,1825992
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java?rev=1825993&r1=1825992&r2=1825993&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
 Tue Mar  6 15:17:08 2018
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
 import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
 import org.apache.jackrabbit.oak.stats.StatisticsProvider;
 import org.junit.After;
@@ -34,6 +35,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.stats.StatsOptions.METRICS_ONLY;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeNotNull;
 
 public class MongoDocumentStoreMetricsTest extends AbstractMongoConnectionTest 
{
 
@@ -48,24 +50,30 @@ public class MongoDocumentStoreMetricsTe
     }
 
     @Test
-    public void updateCounters() throws Exception {
+    public void updateCounters() {
+        MongoConnection connection = connectionFactory.getConnection();
+        assumeNotNull(connection);
         MongoDocumentStore store = new MongoDocumentStore(
-                mongoConnection.getDB(), newMongoDocumentNodeStoreBuilder());
-        MongoDocumentStoreMetrics metrics = new 
MongoDocumentStoreMetrics(store, statsProvider);
-        metrics.run();
-        // document for root node
-        assertEquals(1, getCount("MongoDB.nodes.count"));
-        // one cluster node
-        assertEquals(1, getCount("MongoDB.clusterNodes.count"));
-
-        List<UpdateOp> updates = new ArrayList<>();
-        for (int i = 0; i < 10; i++) {
-            updates.add(new UpdateOp("id-" + i, true));
+                connection.getDB(), newMongoDocumentNodeStoreBuilder());
+        try {
+            MongoDocumentStoreMetrics metrics = new 
MongoDocumentStoreMetrics(store, statsProvider);
+            metrics.run();
+            // document for root node
+            assertEquals(1, getCount("MongoDB.nodes.count"));
+            // one cluster node
+            assertEquals(1, getCount("MongoDB.clusterNodes.count"));
+
+            List<UpdateOp> updates = new ArrayList<>();
+            for (int i = 0; i < 10; i++) {
+                updates.add(new UpdateOp("id-" + i, true));
+            }
+            assertTrue(store.create(Collection.NODES, updates));
+
+            metrics.run();
+            assertEquals(11, getCount("MongoDB.nodes.count"));
+        } finally {
+            store.dispose();
         }
-        assertTrue(store.create(Collection.NODES, updates));
-
-        metrics.run();
-        assertEquals(11, getCount("MongoDB.nodes.count"));
     }
 
     private long getCount(String name) {


Reply via email to