Author: mreutegg
Date: Tue Mar  3 09:18:34 2015
New Revision: 1663565

URL: http://svn.apache.org/r1663565
Log:
OAK-2562: DiffCache is inefficient

Added a test (currently ignored)

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java?rev=1663565&r1=1663564&r2=1663565&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java
 Tue Mar  3 09:18:34 2015
@@ -43,6 +43,7 @@ public abstract class AbstractMongoConne
     public void setUpConnection() throws Exception {
         mongoConnection = MongoUtils.getConnection();
         MongoUtils.dropCollections(mongoConnection.getDB());
+        Revision.setClock(getTestClock());
         mk = new 
DocumentMK.Builder().clock(getTestClock()).setMongoDB(mongoConnection.getDB()).open();
     }
 
@@ -58,6 +59,7 @@ public abstract class AbstractMongoConne
         mongoConnection = MongoUtils.getConnection();
         MongoUtils.dropCollections(mongoConnection.getDB());
         mongoConnection.close();
+        Revision.resetClockToDefault();
     }
 
     @Override

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java?rev=1663565&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java
 Tue Mar  3 09:18:34 2015
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
+import static org.junit.Assert.assertEquals;
+
+public class DocumentNodeStoreDiffTest extends AbstractMongoConnectionTest {
+
+    // OAK-2562
+    @Ignore
+    @Test
+    public void diff() throws Exception {
+        DocumentNodeStore store = mk.getNodeStore();
+
+        NodeBuilder builder = store.getRoot().builder();
+        builder.child("other");
+        for (int i = 0; i < 10; i++) {
+            builder.child("test").child("folder").child("node-" + i);
+        }
+        merge(store, builder);
+
+        for (int i = 0; i < 50; i++) {
+            builder = store.getRoot().builder();
+            builder.child("other").child("node-" + i);
+            merge(store, builder);
+        }
+
+        NodeState before = store.getRoot();
+
+        builder = store.getRoot().builder();
+        builder.child("test").child("folder").child("node-x").child("child");
+        NodeState after = merge(store, builder);
+
+        for (int i = 0; i < 10; i++) {
+            builder = store.getRoot().builder();
+            builder.child("test").child("folder").child("node-" + 
i).child("child");
+            merge(store, builder);
+        }
+
+        CacheStats stats = ((MemoryDiffCache) 
store.getDiffCache()).getDiffCacheStats();
+        stats.resetStats();
+
+        // must not cause cache misses
+        Diff.perform(before, after);
+        assertEquals(0, stats.getMissCount());
+    }
+
+    @Override
+    protected Clock getTestClock() throws InterruptedException {
+        return new Clock.Virtual();
+    }
+
+    private static NodeState merge(NodeStore store, NodeBuilder builder)
+            throws CommitFailedException {
+        return store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+    }
+    
+    private static class Diff extends DefaultNodeStateDiff {
+        
+        static void perform(NodeState before, NodeState after) {
+            after.compareAgainstBaseState(before, new Diff());
+        }
+
+        @Override
+        public boolean childNodeAdded(String name, NodeState after) {
+            return after.compareAgainstBaseState(EMPTY_NODE, this);
+        }
+
+        @Override
+        public boolean childNodeChanged(String name,
+                                        NodeState before,
+                                        NodeState after) {
+            return after.compareAgainstBaseState(before, this);
+        }
+
+        @Override
+        public boolean childNodeDeleted(String name, NodeState before) {
+            return MISSING_NODE.compareAgainstBaseState(before, this);
+        }
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to