jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1423930 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
Date Wed, 19 Dec 2012 16:38:57 GMT
Author: mduerig
Date: Wed Dec 19 16:38:57 2012
New Revision: 1423930

URL: http://svn.apache.org/viewvc?rev=1423930&view=rev
Log:
OAK-531: NodeBuilder deleted child nodes can come back

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1423930&r1=1423929&r2=1423930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Wed Dec 19 16:38:57 2012
@@ -187,22 +187,11 @@ public class MemoryNodeBuilder implement
         }
     }
 
-    /**
-     * Determine whether the named child has been removed. This is the
-     * case when the write state has a corresponding {@code null} entry.
-     * Assumes {@code read()}, {@code write()} needs not be called.
-     * @param name  name of the child
-     * @return  {@code true} iff a child with the given name has been removed
-     */
-    private boolean removed(String name) {
-        return writeState != null && writeState.isRemoved(name);
-    }
-
     @Nonnull
     private NodeState read() {
         if (revision != root.revision) {
             assert(!isRoot()); // root never gets here since revision == root.revision
-            checkState(!parent.removed(name), "This node has already been removed");
+            checkState(!isRemoved(), "This node has already been removed");
             parent.read();
 
             // The builder could have been reset, need to re-get base state
@@ -232,7 +221,7 @@ public class MemoryNodeBuilder implement
     private MutableNodeState write(long newRevision, boolean skipRemovedCheck) {
         // make sure that all revision numbers up to the root gets updated
         if (!isRoot()) {
-            checkState(skipRemovedCheck || !parent.removed(name));
+            checkState(skipRemovedCheck || !isRemoved());
             parent.write(newRevision, skipRemovedCheck);
         }
 
@@ -244,7 +233,7 @@ public class MemoryNodeBuilder implement
 
             writeState = parent.getWriteState(name);
             if (writeState == null) {
-                if (parent.removed(name)) {
+                if (isRemoved()) {
                     writeState = new MutableNodeState(null);
                 }
                 else {

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java?rev=1423930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
Wed Dec 19 16:38:57 2012
@@ -0,0 +1,80 @@
+/*
+ * 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.kernel;
+
+import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+public class KernelNodeBuilderTest {
+
+    @Test
+    public void deletesKernelNodeStore() throws CommitFailedException {
+        NodeStore store = new KernelNodeStore(new MicroKernelImpl());
+        init(store);
+        run(store);
+    }
+
+    @Test
+    public void deletesMemoryNodeStore() throws CommitFailedException {
+        NodeStore store = new MemoryNodeStore();
+        init(store);
+        run(store);
+    }
+
+    private static void init(NodeStore store) throws CommitFailedException {
+        NodeStoreBranch branch = store.branch();
+        NodeBuilder builder = branch.getRoot().builder();
+        builder.child("x").child("y").child("z");
+        branch.setRoot(builder.getNodeState());
+        branch.merge();
+    }
+
+    private static void run(NodeStore store) throws CommitFailedException {
+        NodeStoreBranch branch = store.branch();
+        NodeBuilder builder = branch.getRoot().builder();
+
+        assertTrue("child node x should be present", builder.hasChildNode("x"));
+        assertTrue("child node x/y should be present", builder.child("x")
+                .hasChildNode("y"));
+        assertTrue("child node x/y/z should be present", builder.child("x")
+                .child("y").hasChildNode("z"));
+
+        builder.removeNode("x");
+        assertFalse("child node x not should be present",
+                builder.hasChildNode("x"));
+        assertFalse("child node x/y not should be present", builder.child("x")
+                .hasChildNode("y"));
+
+        // See OAK-531
+        assertFalse("child node x/y/z not should not be present", builder
+                .child("x").child("y").hasChildNode("z"));
+
+        branch.merge();
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message