Author: chetanm
Date: Wed Oct 19 15:10:50 2016
New Revision: 1765641
URL: http://svn.apache.org/viewvc?rev=1765641&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Handle hierarchy conflict detection. Credits and Thanks to Vikas Saurabh for
the test scenario!
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorConflictTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.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/CommitDiff.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java?rev=1765641&r1=1765640&r2=1765641&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/CommitDiff.java
Wed Oct 19 15:10:50 2016
@@ -144,7 +144,6 @@ class CommitDiff implements NodeStateDif
}
private void setChildrenFlagOnAdd(BundlingHandler child) {
- NodeState currentNode = bundlingHandler.getNodeState();
//Add hasChildren marker for bundling case
String propName = null;
if (child.isBundledNode()){
@@ -160,9 +159,9 @@ class CommitDiff implements NodeStateDif
propName = DocumentBundlor.META_PROP_NON_BUNDLED_CHILD;
}
- //Avoid having multiple revision of same prop i.e. once
- //child related flag is set its not touched
- if (propName != null && !currentNode.hasProperty(propName)){
+ //Retouch the property if already present to enable
+ //hierarchy conflict detection
+ if (propName != null){
setProperty(createProperty(propName, Boolean.TRUE));
}
}
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorConflictTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorConflictTest.java?rev=1765641&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorConflictTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorConflictTest.java
Wed Oct 19 15:10:50 2016
@@ -0,0 +1,152 @@
+/*
+ * 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.bundlor;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+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.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.NT_FILE;
+import static org.apache.jackrabbit.JcrConstants.NT_RESOURCE;
+
+public class BundlorConflictTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Rule
+ public DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
+ private DocumentNodeStore store1;
+ private DocumentNodeStore store2;
+ private DocumentStore ds = new MemoryDocumentStore();
+
+ @Before
+ public void setUpBundlor() throws CommitFailedException {
+
+ store1 = builderProvider
+ .newBuilder()
+ .setDocumentStore(ds)
+ .memoryCacheSize(0)
+ .setClusterId(1)
+ .setAsyncDelay(0)
+ .getNodeStore();
+
+ store2 = builderProvider
+ .newBuilder()
+ .setDocumentStore(ds)
+ .memoryCacheSize(0)
+ .setClusterId(2)
+ .setAsyncDelay(0)
+ .getNodeStore();
+
+ NodeBuilder builder = store1.getRoot().builder();
+ NodeBuilder prevState = builder.child("oldState");
+
+ //Old state nt:file
+ createFile(prevState, "file");
+ //Old state app:Asset
+ createAsset(prevState, "assset");
+
+ merge(store1, builder);
+
+ NodeState registryState = BundledTypesRegistry.builder()
+ .forType("nt:file", "jcr:content")
+ .registry()
+ .forType("app:Asset")
+ .include("jcr:content")
+ .include("jcr:content/metadata")
+ .include("jcr:content/renditions")
+ .include("jcr:content/renditions/**")
+ .build();
+
+ builder = store1.getRoot().builder();
+
builder.child("jcr:system").child("documentstore").setChildNode("bundlor",
registryState);
+ merge(store1, builder);
+
+ syncStores();
+ }
+
+ @Test
+ public void simpleConflict() throws Exception {
+ NodeBuilder root = store1.getRoot().builder();
+
+ getRendBuilder(createAsset(root,
"foo")).getChildNode("rend-orig").setProperty("meta", "orig");
+ merge(store1, root);
+
+ syncStores();
+
+ NodeBuilder root1 = store1.getRoot().builder();
+ getRendBuilder(root1.getChildNode("foo")).child("rend1");//create a
new rendition
+
+ NodeBuilder root2 = store2.getRoot().builder();
+ getRendBuilder(root2.getChildNode("foo")).remove();//remove rendition
parent
+
+ merge(store1, root1);
+
+ thrown.expect(CommitFailedException.class);
+ merge(store2, root2);
+ }
+
+ private static void merge(NodeStore store,
+ NodeBuilder root)
+ throws CommitFailedException {
+ store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+ }
+
+ private NodeBuilder createFile(NodeBuilder builder, String childName) {
+ NodeBuilder file = type(builder.child(childName), NT_FILE);
+ type(file.child("jcr:content"), NT_RESOURCE);
+
+ return file;
+ }
+
+ private NodeBuilder getRendBuilder(NodeBuilder assetBuilder) {
+ return
assetBuilder.getChildNode("jcr:content").getChildNode("renditions");
+ }
+
+ private NodeBuilder createAsset(NodeBuilder builder, String childName) {
+ NodeBuilder asset = type(builder.child(childName), "app:Asset");
+ NodeBuilder assetJC = asset.child("jcr:content");
+ assetJC.child("metadata");
+ assetJC.child("renditions").child("rend-orig");
+ assetJC.child("comments");
+
+ return asset;
+ }
+
+ private NodeBuilder type(NodeBuilder builder, String typeName) {
+ builder.setProperty(JCR_PRIMARYTYPE, typeName);
+ return builder;
+ }
+
+ private void syncStores() {
+ store1.runBackgroundOperations();
+ store2.runBackgroundOperations();
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlorConflictTest.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1765641&r1=1765640&r2=1765641&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
Wed Oct 19 15:10:50 2016
@@ -289,27 +289,6 @@ public class DocumentBundlingTest {
}
@Test
- public void hasChildren_SingleVersion() throws Exception{
- createTestNode("/test/book.jpg", createChild(newNode("app:Asset"),
- "jcr:content/metadata"
- ).getNodeState());
-
- assertEquals(1,
getNodeDocument("/test/book.jpg").getValueMap(concat("jcr:content",
META_PROP_BUNDLED_CHILD)).size());
-
- NodeBuilder builder = store.getRoot().builder();
- childBuilder(builder, "/test/book.jpg/jcr:content/renditions");
- merge(builder);
-
- ds.reset();
-
- //Assert that there is only one revision for meta
:doc-has-child-bundled
- //Even on adding multiple child node there is only version kept
- assertEquals(1,
getNodeDocument("/test/book.jpg").getValueMap(concat("jcr:content",
META_PROP_BUNDLED_CHILD)).size());
- assertEquals(2,
Iterables.size(getLatestNode("test/book.jpg/jcr:content").getChildNodeNames()));
- assertEquals(0, ds.queryPaths.size());
- }
-
- @Test
public void addBundledNodePostInitialCreation() throws Exception{
NodeBuilder builder = store.getRoot().builder();
NodeBuilder appNB = newNode("app:Asset");