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 st...@apache.org on 2016/02/11 12:14:01 UTC

svn commit: r1729806 - /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java

Author: stefanegli
Date: Thu Feb 11 11:14:00 2016
New Revision: 1729806

URL: http://svn.apache.org/viewvc?rev=1729806&view=rev
Log:
OAK-3986 : switching to mongo, with specific cache sizes configured so that it doesnt go OOM, and enabling the test again

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java?rev=1729806&r1=1729805&r2=1729806&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/NonLocalObservationIT.java Thu Feb 11 11:14:00 2016
@@ -19,7 +19,9 @@ package org.apache.jackrabbit.oak.jcr.cl
 import static org.junit.Assert.assertTrue;
 
 import java.util.Date;
+import java.util.HashSet;
 import java.util.Random;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.jcr.Node;
@@ -31,51 +33,92 @@ import javax.jcr.observation.EventListen
 import javax.jcr.observation.ObservationManager;
 
 import org.apache.jackrabbit.api.observation.JackrabbitEvent;
+import org.apache.jackrabbit.oak.fixture.DocumentMongoFixture;
 import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
-import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.junit.AssumptionViolatedException;
 import org.junit.Test;
-import org.junit.Ignore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mongodb.DB;
 
 /**
  * Test for external events from another cluster node.
  */
 public class NonLocalObservationIT extends AbstractClusterTest {
 
+    private static final Logger log = LoggerFactory.getLogger(NonLocalObservationIT.class);
+
     AtomicReference<Exception> exception = new AtomicReference<Exception>();
 
     @Override
     protected NodeStoreFixture getFixture() {
-        return new NodeStoreFixture() {
-
-            private DocumentStore documentStore;
-
-            private DocumentStore getDocumentStore() {
-                if (documentStore == null) {
-                    documentStore = new MemoryDocumentStore();
+        /**
+         * Fixes the cluster use case plus allowing to control the cache sizes.
+         * In theory other users of DocumentMongoFixture might have similar 
+         * test cases - but keeping it simple for now - thus going via subclass.
+         */
+        return new DocumentMongoFixture() {
+            
+            private String clusterSuffix = System.currentTimeMillis() + "-NonLocalObservationIT";
+
+            private DB db;
+            
+            /** keep a reference to the node stores so that the db only gets closed after the last nodeStore was closed */
+            private Set<NodeStore> nodeStores = new HashSet<NodeStore>();
+
+            /**
+             * This is not implemented in the super class at all.
+             * <ul>
+             *  <li>use a specific suffix to make sure we have our own, new db and clean it up after the test</li>
+             *  <li>properly drop that db created above in dispose</li>
+             *  <li>use only 32MB (vs default of 256MB) memory to ensure we're not going OOM just because of this (which happens with the default)</li>
+             *  <li>disable the persistent cache for the same reason</li>
+             * </ul>
+             */
+            @Override
+            public NodeStore createNodeStore(int clusterNodeId) {
+                try {
+                    DocumentMK.Builder builder = new DocumentMK.Builder();
+                    builder.memoryCacheSize(32*1024*1024); // keep this one low to avoid OOME
+                    builder.setPersistentCache(null);      // turn this one off to avoid OOME
+                    final String suffix = clusterSuffix;
+                    db = getDb(suffix); // db will be overwritten - but that's fine
+                    builder.setMongoDB(db);
+                    DocumentNodeStore ns = builder.getNodeStore();
+                    nodeStores.add(ns);
+                    return ns;
+                } catch (Exception e) {
+                    throw new AssumptionViolatedException("Mongo instance is not available", e);
                 }
-                return documentStore;
             }
-
+            
             @Override
-            public String toString() {
-                return "TestNodeStoreFixture";
+            public void dispose(NodeStore nodeStore) {
+                super.dispose(nodeStore);
+                nodeStores.remove(nodeStore);
+                if (db != null && nodeStores.size() == 0) {
+                    try {
+                        db.dropDatabase();
+                        db.getMongo().close();
+                        db = null;
+                    } catch (Exception e) {
+                        log.error("dispose: Can't close Mongo", e);
+                    }
+                }
             }
-
+            
             @Override
-            public NodeStore createNodeStore() {
-                return new DocumentMK.Builder().setDocumentStore(getDocumentStore()).getNodeStore();
+            public String toString() {
+                return "NonLocalObservationIT's DocumentMongoFixture flavour";
             }
 
-            @Override
-            public NodeStore createNodeStore(int clusterNodeId) {
-                return new DocumentMK.Builder().setDocumentStore(getDocumentStore()).setClusterId(clusterNodeId).getNodeStore();
-            }
         };
     }
-
+    
     private void addEventHandler(Session s, final String expectedNodeSuffix) throws Exception {
         ObservationManager o = s.getWorkspace().getObservationManager();
         o.addEventListener(new EventListener() {
@@ -107,7 +150,6 @@ public class NonLocalObservationIT exten
     }
 
     @Test
-    @Ignore("OAK-3986 - disabling for now as in-memory fixture causes OOME in this or following tests")
     public void randomized() throws Exception {
         System.out.println(new Date() + ": initialization");
         if (s1 == null) {