Author: chetanm
Date: Fri Nov 11 12:13:40 2016
New Revision: 1769279

URL: http://svn.apache.org/viewvc?rev=1769279&view=rev
Log:
OAK-5079 - Diff would not work for bundled nodes when done without journal 
support

Handled the case where secondary nodestore is in use

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDiffer.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDifferTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1769279&r1=1769278&r2=1769279&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
 Fri Nov 11 12:13:40 2016
@@ -146,7 +146,10 @@ public final class DocumentNodeStore
      * in DocumentBundlor as those are only required by DocumentNodeState
      */
     public static final List<String> META_PROP_NAMES = ImmutableList.of(
-            DocumentBundlor.META_PROP_PATTERN
+            DocumentBundlor.META_PROP_PATTERN,
+            DocumentBundlor.META_PROP_BUNDLING_PATH,
+            DocumentBundlor.META_PROP_NON_BUNDLED_CHILD,
+            DocumentBundlor.META_PROP_BUNDLED_CHILD
     );
 
     /**

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDiffer.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDiffer.java?rev=1769279&r1=1769278&r2=1769279&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDiffer.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDiffer.java
 Fri Nov 11 12:13:40 2016
@@ -105,7 +105,7 @@ public class BundledDocumentDiffer {
             String bundlingPath = 
state.getString(DocumentBundlor.META_PROP_BUNDLING_PATH);
             String bundlingRootPath = 
PathUtils.getAncestorPath(state.getPath(), PathUtils.getDepth(bundlingPath));
             DocumentNodeState bundlingRoot = 
nodeStore.getNode(bundlingRootPath, state.getLastRevision());
-            result = (DocumentNodeState) NodeStateUtils.getNode(bundlingRoot, 
bundlingRootPath);
+            result = (DocumentNodeState) NodeStateUtils.getNode(bundlingRoot, 
bundlingPath);
         } else {
             result = nodeStore.getNode(state.getPath(), 
state.getLastRevision());
         }

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java?rev=1769279&r1=1769278&r2=1769279&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java
 Fri Nov 11 12:13:40 2016
@@ -46,7 +46,7 @@ import static org.apache.jackrabbit.oak.
  * so as to expose it as an {@link AbstractDocumentNodeState} by extracting
  * the meta properties which are stored as hidden properties
  */
-class DelegatingDocumentNodeState extends AbstractDocumentNodeState {
+public class DelegatingDocumentNodeState extends AbstractDocumentNodeState {
     //Hidden props holding DocumentNodeState meta properties
     static final String PROP_REVISION = ":doc-rev";
     static final String PROP_LAST_REV = ":doc-lastRev";

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java?rev=1769279&r1=1769278&r2=1769279&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
 Fri Nov 11 12:13:40 2016
@@ -39,7 +39,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-class SecondaryStoreCache implements DocumentNodeStateCache, 
SecondaryStoreRootObserver {
+public class SecondaryStoreCache implements DocumentNodeStateCache, 
SecondaryStoreRootObserver {
     private final Logger log = LoggerFactory.getLogger(getClass());
     private static final AbstractDocumentNodeState[] EMPTY = new 
AbstractDocumentNodeState[0];
     private final NodeStore store;

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java?rev=1769279&r1=1769278&r2=1769279&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
 Fri Nov 11 12:13:40 2016
@@ -43,7 +43,7 @@ import org.apache.jackrabbit.oak.stats.T
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class SecondaryStoreObserver implements Observer {
+public class SecondaryStoreObserver implements Observer {
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final NodeStore nodeStore;
     private final PathFilter pathFilter;

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDifferTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDifferTest.java?rev=1769279&r1=1769278&r2=1769279&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDifferTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundledDocumentDifferTest.java
 Fri Nov 11 12:13:40 2016
@@ -19,13 +19,26 @@
 
 package org.apache.jackrabbit.oak.plugins.document.bundlor;
 
+import java.util.Collections;
+
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
 import org.apache.jackrabbit.oak.commons.json.JsopWriter;
 import org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState;
 import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import 
org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState;
+import 
org.apache.jackrabbit.oak.plugins.document.secondary.SecondaryStoreBuilder;
+import 
org.apache.jackrabbit.oak.plugins.document.secondary.SecondaryStoreCache;
+import 
org.apache.jackrabbit.oak.plugins.document.secondary.SecondaryStoreObserver;
+import org.apache.jackrabbit.oak.plugins.index.PathFilter;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
+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.NodeStateUtils;
@@ -34,6 +47,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static com.google.inject.internal.util.$ImmutableList.of;
 import static 
org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore.SYS_PROP_DISABLE_JOURNAL;
 import static 
org.apache.jackrabbit.oak.plugins.document.TestUtils.childBuilder;
 import static org.apache.jackrabbit.oak.plugins.document.TestUtils.createChild;
@@ -42,8 +56,10 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigHandler.DOCUMENT_NODE_STORE;
 import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlingTest.asDocumentState;
 import static 
org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlingTest.newNode;
+import static org.hamcrest.CoreMatchers.hasItem;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public class BundledDocumentDifferTest {
@@ -52,6 +68,7 @@ public class BundledDocumentDifferTest {
     private DocumentNodeStore store;
     private String journalDisabledProp;
     private BundledDocumentDiffer differ;
+    private MemoryNodeStore secondary = new MemoryNodeStore();
 
 
     @Before
@@ -120,6 +137,52 @@ public class BundledDocumentDifferTest {
         assertEquals("^\"jcr:content\":{}", w.toString());
     }
 
+    @Test
+    public void diffWithSecondary() throws Exception{
+        configureSecondary();
+        NodeBuilder builder = createContentStructure();
+        NodeState r1 = merge(store, builder);
+        NodeState rs1 = DelegatingDocumentNodeState.wrap(secondary.getRoot(), 
store);
+
+        builder = store.getRoot().builder();
+        childBuilder(builder, "/test/book.jpg/jcr:content").setProperty("foo", 
"bar");
+        NodeState r2 = merge(store, builder);
+
+        JsopWriter w = new JsopBuilder();
+        String path = "/test/book.jpg";
+        assertFalse(differ.diff(adns(rs1, path), adns(r2, path), w));
+        assertEquals("^\"jcr:content\":{}", w.toString());
+    }
+
+    @Test
+    public void diffFewChildren() throws Exception{
+        NodeBuilder builder = createContentStructure();
+        NodeState r1 = merge(store, builder);
+
+        builder = store.getRoot().builder();
+        childBuilder(builder, "/test/book.jpg/jcr:content").setProperty("foo", 
"bar");
+        childBuilder(builder, 
"/test/book.jpg/jcr:content/renditions/newChild2").setProperty("foo", "bar");
+        childBuilder(builder, "/test/book.jpg/newChild1");
+        NodeState r2 = merge(store, builder);
+
+        String path = "/test/book.jpg";
+        CollectingDiff diff = new CollectingDiff();
+        adns(r2, path).compareAgainstBaseState(adns(r1, path), diff);
+
+        assertThat(diff.changes.get("added"), hasItem("newChild1"));
+        assertThat(diff.changes.get("changed"), hasItem("jcr:content"));
+
+        diff = new CollectingDiff();
+        path = "/test/book.jpg/jcr:content/renditions";
+        adns(r2, path).compareAgainstBaseState(adns(r1, path), diff);
+
+        System.out.println(diff);
+        assertThat(diff.changes.get("added"), hasItem("newChild2"));
+
+    }
+
+
+
     private NodeBuilder createContentStructure() {
         NodeBuilder builder = store.getRoot().builder();
         NodeBuilder appNB = newNode("app:Asset");
@@ -137,9 +200,52 @@ public class BundledDocumentDifferTest {
         return builder;
     }
 
-    private AbstractDocumentNodeState dns(NodeState root, String path){
+    private static class CollectingDiff extends DefaultNodeStateDiff {
+        private ListMultimap<String, String> changes = 
ArrayListMultimap.create();
+
+        @Override
+        public boolean childNodeAdded(String name, NodeState after) {
+            changes.get("added").add(name);
+            return true;
+        }
+
+        @Override
+        public boolean childNodeChanged(String name, NodeState before, 
NodeState after) {
+            changes.get("changed").add(name);
+            return super.childNodeChanged(name, before, after);
+        }
+
+        @Override
+        public boolean childNodeDeleted(String name, NodeState before) {
+            changes.get("deleted").add(name);
+            return super.childNodeDeleted(name, before);
+        }
+
+        @Override
+        public String toString() {
+            return changes.toString();
+        }
+    }
+
+    private DocumentNodeState dns(NodeState root, String path){
         return asDocumentState(NodeStateUtils.getNode(root, path));
     }
 
+    private AbstractDocumentNodeState adns(NodeState root, String path){
+        return (AbstractDocumentNodeState) NodeStateUtils.getNode(root, path);
+    }
+
+    private SecondaryStoreCache configureSecondary(){
+        SecondaryStoreBuilder builder = createBuilder(new PathFilter(of("/"), 
Collections.<String>emptyList()));
+        builder.metaPropNames(DocumentNodeStore.META_PROP_NAMES);
+        SecondaryStoreCache cache = builder.buildCache();
+        SecondaryStoreObserver observer = builder.buildObserver(cache);
+        store.addObserver(observer);
+        return cache;
+    }
+
+    private SecondaryStoreBuilder createBuilder(PathFilter pathFilter) {
+        return new SecondaryStoreBuilder(secondary).pathFilter(pathFilter);
+    }
 
 }
\ No newline at end of file

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java?rev=1769279&r1=1769278&r2=1769279&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
 Fri Nov 11 12:13:40 2016
@@ -761,7 +761,6 @@ public class DocumentBundlingTest {
         assertTrue("No change reported for /test/book.jpg/jcr:content", 
addedPropertyNames.contains("fooContent"));
     }
 
-    @Ignore("OAK-5079")
     @Test
     public void bundledNodeAndDiffFew() throws Exception{
         store.dispose();


Reply via email to