jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1585304 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
Date Sun, 06 Apr 2014 13:42:51 GMT
Author: mduerig
Date: Sun Apr  6 13:42:51 2014
New Revision: 1585304

URL: http://svn.apache.org/r1585304
Log:
OAK-1681: Clarify contract of NodeBuilder.isReplaced()
Added test cases for isReplace and corrected implementation in MemoryNodeBuilder

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java?rev=1585304&r1=1585303&r2=1585304&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
Sun Apr  6 13:42:51 2014
@@ -63,6 +63,12 @@ class MutableNodeState extends AbstractN
      */
     private final Map<String, MutableNodeState> nodes = newHashMap();
 
+    /**
+     * Flag to indicate that this child has been replace in its parent.
+     * @see org.apache.jackrabbit.oak.spi.state.NodeBuilder#isReplaced()
+     */
+    private boolean replaced;
+
     MutableNodeState(@Nonnull NodeState base) {
         checkNotNull(base);
         this.base = ModifiedNodeState.unwrap(base, properties, nodes);
@@ -103,8 +109,12 @@ class MutableNodeState extends AbstractN
         if (child == null) {
             checkValidName(name);
             child = new MutableNodeState(state);
+            if (base.hasChildNode(name)) {
+                child.replaced = true;
+            }
             nodes.put(name, child);
         } else {
+            child.replaced = true;
             child.reset(state);
         }
         return child;
@@ -149,7 +159,7 @@ class MutableNodeState extends AbstractN
     }
 
     boolean isReplaced(NodeState before) {
-        return base != before;
+        return replaced;
     }
 
     boolean isReplaced(NodeState before, String name) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java?rev=1585304&r1=1585303&r2=1585304&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
Sun Apr  6 13:42:51 2014
@@ -16,31 +16,39 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+
+import java.util.Collection;
+
 import javax.annotation.Nonnull;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
-
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
-
+@RunWith(Parameterized.class)
 public class MemoryNodeBuilderTest {
 
-    private NodeState base;
+    private final NodeState base;
+
+    public MemoryNodeBuilderTest(NodeState base) {
+        this.base = base;
+    }
 
-    @Before
-    public void setUp() {
+    @Parameterized.Parameters
+    public static Collection<Object[]> fixtures() {
         NodeBuilder builder = EMPTY_NODE.builder();
         builder.setProperty("a", 1L);
         builder.setProperty("b", 2L);
@@ -48,7 +56,11 @@ public class MemoryNodeBuilderTest {
         builder.child("x").child("q");
         builder.child("y");
         builder.child("z");
-        base = builder.getNodeState();
+        NodeState base = builder.getNodeState();
+        return ImmutableList.of(
+            new Object[] { base },
+            new Object[] { ModifiedNodeState.squeeze(base) }
+        );
     }
 
     @Test
@@ -202,6 +214,41 @@ public class MemoryNodeBuilderTest {
     }
 
     @Test
+    public void testReplacedStatus() {
+        NodeBuilder root = base.builder();
+        NodeBuilder x = root.getChildNode("x");
+        x.setChildNode("new");
+        assertFalse(x.isReplaced());
+    }
+
+    @Test
+    public void testReplacedStatus2() {
+        NodeBuilder x = base.builder().getChildNode("x");
+        NodeBuilder q = x.getChildNode("q");
+        q.remove();
+        assertFalse(q.isReplaced());
+        x.setChildNode("q").setProperty("a", "b");
+        assertTrue(q.isReplaced());
+    }
+
+    @Test
+    public void testReplacedStatus3() {
+        NodeBuilder x = base.builder().getChildNode("x");
+        NodeBuilder q = x.getChildNode("q");
+        assertFalse(q.isReplaced());
+        x.setChildNode("q").setProperty("a", "b");
+        assertTrue(q.isReplaced());
+    }
+
+    @Test
+    public void removeParent() {
+        NodeBuilder x = base.builder().getChildNode("x");
+        NodeBuilder y = x.setChildNode("y");
+        x.remove();
+        assertFalse(x.exists());
+    }
+
+    @Test
     public void testRemovedStatus() {
         NodeBuilder root = base.builder();
         NodeBuilder x = root.child("x");



Mime
View raw message