jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1538614 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/kernel/ main/java/org/apache/jackrabbit/oak/plugins/segment/ test/java/org/apache/jackrabbit/oak/ test/java/org/apache/jackrabbit/oak/kernel/
Date Mon, 04 Nov 2013 14:12:47 GMT
Author: mduerig
Date: Mon Nov  4 14:12:46 2013
New Revision: 1538614

URL: http://svn.apache.org/r1538614
Log:
OAK-1131  Provide a way to inject Observer instances into NodeStore implementations
Pass observer to KernelNodeStore and SegmentNodeStore as constructor argument

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1538614&r1=1538613&r2=1538614&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Mon Nov  4 14:12:46 2013
@@ -34,7 +34,6 @@ import com.google.common.cache.LoadingCa
 import com.google.common.cache.Weigher;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
-
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -56,8 +55,7 @@ import org.apache.jackrabbit.oak.spi.sta
  * {@code NodeStore} implementations against {@link MicroKernel}.
  */
 public class KernelNodeStore implements NodeStore, Observable {
-
-    private static final long DEFAULT_CACHE_SIZE = 16 * 1024 * 1024;
+    public static final long DEFAULT_CACHE_SIZE = 16 * 1024 * 1024;
 
     /**
      * The {@link MicroKernel} instance used to store the content tree.
@@ -68,7 +66,7 @@ public class KernelNodeStore implements 
      * Change observer.
      */
     @Nonnull
-    private volatile Observer observer = EmptyObserver.INSTANCE;
+    private final Observer observer;
 
     private final LoadingCache<String, KernelNodeState> cache;
 
@@ -86,8 +84,9 @@ public class KernelNodeStore implements 
      */
     private KernelNodeState root;
 
-    public KernelNodeStore(final MicroKernel kernel, long cacheSize) {
+    public KernelNodeStore(final MicroKernel kernel, long cacheSize, Observer observer) {
         this.kernel = checkNotNull(kernel);
+        this.observer = observer;
 
         Weigher<String, KernelNodeState> weigher = new Weigher<String, KernelNodeState>()
{
             @Override
@@ -130,12 +129,12 @@ public class KernelNodeStore implements 
         changeDispatcher = new ChangeDispatcher(this);
     }
 
-    public KernelNodeStore(MicroKernel kernel) {
-        this(kernel, DEFAULT_CACHE_SIZE);
+    public KernelNodeStore(MicroKernel kernel, long cacheSize) {
+        this(kernel, cacheSize, EmptyObserver.INSTANCE);
     }
 
-    public void setObserver(@Nonnull Observer observer) {
-        this.observer = checkNotNull(observer);
+    public KernelNodeStore(MicroKernel kernel) {
+        this(kernel, DEFAULT_CACHE_SIZE, EmptyObserver.INSTANCE);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1538614&r1=1538613&r2=1538614&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
Mon Nov  4 14:12:46 2013
@@ -58,19 +58,27 @@ public class SegmentNodeStore implements
 
     private long maximumBackoff = MILLISECONDS.convert(10, SECONDS);
 
-    public SegmentNodeStore(SegmentStore store, String journal) {
+    public SegmentNodeStore(SegmentStore store, String journal, Observer observer) {
         this.store = store;
         this.journal = store.getJournal(journal);
-        this.observer = EmptyObserver.INSTANCE;
+        this.observer = observer;
         this.head = new SegmentNodeState(
                 store.getWriter().getDummySegment(), this.journal.getHead());
         this.changeDispatcher = new ChangeDispatcher(this);
     }
 
+    public SegmentNodeStore(SegmentStore store, String journal) {
+        this(store, journal, EmptyObserver.INSTANCE);
+    }
+
     public SegmentNodeStore(SegmentStore store) {
         this(store, "root");
     }
 
+    public SegmentNodeStore(SegmentStore store, Observer observer) {
+        this(store, "root", observer);
+    }
+
     void setMaximumBackoff(long max) {
         this.maximumBackoff = max;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java?rev=1538614&r1=1538613&r2=1538614&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
Mon Nov  4 14:12:46 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.jackrabbit.oak;
 
+import static org.apache.jackrabbit.oak.kernel.KernelNodeStore.DEFAULT_CACHE_SIZE;
+
 import java.io.Closeable;
 import java.io.IOException;
 
@@ -27,6 +29,8 @@ import org.apache.jackrabbit.oak.kernel.
 import org.apache.jackrabbit.oak.plugins.mongomk.MongoNodeStore;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
 import org.apache.jackrabbit.oak.plugins.segment.memory.MemoryStore;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
 /**
@@ -35,6 +39,8 @@ import org.apache.jackrabbit.oak.spi.sta
 public abstract class NodeStoreFixture {
 
     public static final NodeStoreFixture SEGMENT_MK = new NodeStoreFixture() {
+        private final ResettableObserver observer = new ResettableObserver();
+
         @Override
         public String toString() {
             return "SegmentMK Fixture";
@@ -42,15 +48,22 @@ public abstract class NodeStoreFixture {
 
         @Override
         public NodeStore createNodeStore() {
-            return new SegmentNodeStore(new MemoryStore());
+            return new SegmentNodeStore(new MemoryStore(), observer);
         }
 
         @Override
         public void dispose(NodeStore nodeStore) {
         }
+
+        @Override
+        public void setObserver(Observer observer) {
+            this.observer.setObserver(observer);
+        }
     };
 
     public static final NodeStoreFixture MONGO_MK = new NodeStoreFixture() {
+        private final ResettableObserver observer = new ResettableObserver();
+
         @Override
         public String toString() {
             return "MongoMK Fixture";
@@ -58,7 +71,7 @@ public abstract class NodeStoreFixture {
 
         @Override
         public NodeStore createNodeStore() {
-            return new CloseableNodeStore(new MongoMK.Builder().open());
+            return new CloseableNodeStore(new MongoMK.Builder().open(), observer);
         }
 
         @Override
@@ -71,9 +84,16 @@ public abstract class NodeStoreFixture {
                 }
             }
         }
+
+        @Override
+        public void setObserver(Observer observer) {
+            this.observer.setObserver(observer);
+        }
     };
 
     public static final NodeStoreFixture MONGO_NS = new NodeStoreFixture() {
+        private final ResettableObserver observer = new ResettableObserver();
+
         @Override
         public String toString() {
             return "MongoNS Fixture";
@@ -90,9 +110,16 @@ public abstract class NodeStoreFixture {
                 ((MongoNodeStore) nodeStore).dispose();
             }
         }
+
+        @Override
+        public void setObserver(Observer observer) {
+            this.observer.setObserver(observer);
+        }
     };
 
     public static final NodeStoreFixture MK_IMPL = new NodeStoreFixture() {
+        private final ResettableObserver observer = new ResettableObserver();
+
         @Override
         public String toString() {
             return "MKImpl Fixture";
@@ -100,25 +127,32 @@ public abstract class NodeStoreFixture {
 
         @Override
         public NodeStore createNodeStore() {
-            return new KernelNodeStore(new MicroKernelImpl());
+            return new KernelNodeStore(new MicroKernelImpl(), DEFAULT_CACHE_SIZE, observer);
         }
 
         @Override
         public void dispose(NodeStore nodeStore) {
         }
+
+        @Override
+        public void setObserver(Observer observer) {
+            this.observer.setObserver(observer);
+        }
     };
 
     public abstract NodeStore createNodeStore();
 
     public abstract void dispose(NodeStore nodeStore);
 
+    public abstract void setObserver(Observer observer);
+
     private static class CloseableNodeStore
             extends KernelNodeStore implements Closeable {
 
         private final MongoMK kernel;
 
-        public CloseableNodeStore(MongoMK kernel) {
-            super(kernel);
+        public CloseableNodeStore(MongoMK kernel, Observer observer) {
+            super(kernel, DEFAULT_CACHE_SIZE, observer);
             this.kernel = kernel;
         }
 
@@ -127,4 +161,19 @@ public abstract class NodeStoreFixture {
             kernel.dispose();
         }
     }
+
+    private static class ResettableObserver implements Observer {
+        private Observer observer;
+
+        @Override
+        public void contentChanged(NodeState before, NodeState after) {
+            if (observer != null) {
+                observer.contentChanged(before, after);
+            }
+        }
+
+        public void setObserver(Observer observer) {
+            this.observer = observer;
+        }
+    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java?rev=1538614&r1=1538613&r2=1538614&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
Mon Nov  4 14:12:46 2013
@@ -43,7 +43,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.junit.After;
-import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -138,14 +137,17 @@ public class NodeStoreTest {
 
     @Test
     public void afterCommitHook() throws CommitFailedException {
-        // this test only works with a KernelNodeStore
-        assumeTrue(store instanceof KernelNodeStore);
+        // FIXME OAK-1131
+        assumeTrue(fixture != NodeStoreFixture.MONGO_NS);
+
         final NodeState[] states = new NodeState[2]; // { before, after }
-        ((KernelNodeStore) store).setObserver(new Observer() {
+        fixture.setObserver(new Observer() {
             @Override
             public void contentChanged(NodeState before, NodeState after) {
-                states[0] = before;
-                states[1] = after;
+                if (!before.equals(after)) {
+                    states[0] = before;
+                    states[1] = after;
+                }
             }
         });
 
@@ -368,7 +370,7 @@ public class NodeStoreTest {
 
     @Test
     public void moveToDescendant() throws CommitFailedException {
-        Assume.assumeTrue(fixture != NodeStoreFixture.SEGMENT_MK);  // FIXME OAK-1114
+        assumeTrue(fixture != NodeStoreFixture.SEGMENT_MK);  // FIXME OAK-1114
         NodeBuilder test = store.getRoot().builder().getChildNode("test");
         NodeBuilder x = test.getChildNode("x");
         assertFalse(x.moveTo(x, "xx"));



Mime
View raw message