jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1443551 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilderTest.java
Date Thu, 07 Feb 2013 15:21:15 GMT
Author: mduerig
Date: Thu Feb  7 15:21:15 2013
New Revision: 1443551

URL: http://svn.apache.org/viewvc?rev=1443551&view=rev
Log:
OAK-614: AssertionError in MemoryNodeBuilder

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.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/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=1443551&r1=1443550&r2=1443551&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
Thu Feb  7 15:21:15 2013
@@ -188,20 +188,19 @@ public class MemoryNodeBuilder implement
     }
 
     /**
-     * Determine whether this child has been removed.
+     * Determine whether this child exists.
      * Assumes {@code read()}, {@code write()} needs not be called.
-     * @return  {@code true} iff this child has been removed
+     * @return  {@code true} iff this child exists
      */
-    private boolean removed() {
-        return !isRoot() && parent.writeState != null &&
-                parent.hasBaseState(name) && !parent.writeState.hasChildNode(name);
+    private boolean exists() {
+        return isRoot() || parent.writeState == null || parent.writeState.hasChildNode(name);
     }
 
     @Nonnull
     private NodeState read() {
         if (revision != root.revision) {
             assert(!isRoot()); // root never gets here since revision == root.revision
-            checkState(!removed(), "This node has already been removed");
+            checkState(exists(), "This node has already been removed");
             parent.read();
 
             // The builder could have been reset, need to re-get base state
@@ -231,7 +230,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 || !removed());
+            checkState(skipRemovedCheck || exists());
             parent.write(newRevision, skipRemovedCheck);
         }
 
@@ -243,7 +242,7 @@ public class MemoryNodeBuilder implement
 
             writeState = parent.getWriteState(name);
             if (writeState == null) {
-                if (removed()) {
+                if (!exists()) {
                     writeState = new MutableNodeState(null);
                 }
                 else {
@@ -385,7 +384,7 @@ public class MemoryNodeBuilder implement
         MutableNodeState childState = getWriteState(name);
         if (childState == null) {
             writeState.nodes.remove(name);
-            childState = createChildBuilder(name).write();
+            childState = createChildBuilder(name).write(root.revision + 1, true);
         }
         childState.reset(state);
 

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=1443551&r1=1443550&r2=1443551&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
Thu Feb  7 15:21:15 2013
@@ -103,36 +103,44 @@ public class MemoryNodeBuilderTest {
 
     @Test
     public void testReadOnRemoveNode() {
-        NodeBuilder root = new MemoryNodeBuilder(BASE);
-        NodeBuilder child = root.child("x");
+        String[] names = {"x", "new"};
 
-        root.removeNode("x");
-        try {
-            child.getChildNodeCount();
-            fail();
-        } catch (IllegalStateException e) {
-            // expected
-        }
+        for (String name : names) {
+            NodeBuilder root = new MemoryNodeBuilder(BASE);
+            NodeBuilder child = root.child(name);
+
+            root.removeNode(name);
+            try {
+                child.getChildNodeCount();
+                fail();
+            } catch (IllegalStateException e) {
+                // expected
+            }
 
-        root.child("x");
-        assertEquals(0, child.getChildNodeCount()); // reconnect!
+            root.child(name);
+            assertEquals(0, child.getChildNodeCount()); // reconnect!
+        }
     }
 
     @Test
     public void testWriteOnRemoveNode() {
-        NodeBuilder root = new MemoryNodeBuilder(BASE);
-        NodeBuilder child = root.child("x");
+        String[] names = {"x", "new"};
 
-        root.removeNode("x");
-        try {
-            child.setProperty("q", "w");
-            fail();
-        } catch (IllegalStateException e) {
-            // expected
-        }
+        for (String name : names) {
+            NodeBuilder root = new MemoryNodeBuilder(BASE);
+            NodeBuilder child = root.child(name);
+
+            root.removeNode(name);
+            try {
+                child.setProperty("q", "w");
+                fail();
+            } catch (IllegalStateException e) {
+                // expected
+            }
 
-        root.child("x");
-        assertEquals(0, child.getChildNodeCount()); // reconnect!
+            root.child(name);
+            assertEquals(0, child.getChildNodeCount()); // reconnect!
+        }
     }
 
     @Test



Mime
View raw message