jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1525142 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/user/ test/java/org/apache/jackrabbit/oak/kernel/
Date Fri, 20 Sep 2013 20:47:29 GMT
Author: jukka
Date: Fri Sep 20 20:47:29 2013
New Revision: 1525142

URL: http://svn.apache.org/r1525142
Log:
OAK-659: Move purge logic for transient changes below the NodeBuilder interface

Use builders instead of branches

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreCacheTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java?rev=1525142&r1=1525141&r2=1525142&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
Fri Sep 20 20:47:29 2013
@@ -89,15 +89,7 @@ class UserInitializer implements Workspa
     public void initialize(NodeBuilder builder, String workspaceName,
                                 QueryIndexProvider indexProvider,
                                 CommitHook commitHook) {
-        MemoryNodeStore store = new MemoryNodeStore();
-        NodeStoreBranch branch = store.branch();
-        branch.setRoot(builder.getNodeState());
-        try {
-            branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
-        } catch (CommitFailedException e) {
-            throw new RuntimeException(e);
-        }
-
+        MemoryNodeStore store = new MemoryNodeStore(builder.getNodeState());
         Root root = new SystemRoot(store, commitHook, workspaceName, securityProvider, indexProvider);
 
         UserConfiguration userConfiguration = securityProvider.getConfiguration(UserConfiguration.class);
@@ -133,8 +125,6 @@ class UserInitializer implements Workspa
             if (root.hasPendingChanges()) {
                 root.commit();
             }
-
-            builder.reset(store.getRoot());
         } catch (RepositoryException e) {
             log.error(errorMsg, e);
             throw new RuntimeException(e);
@@ -142,5 +132,8 @@ class UserInitializer implements Workspa
             log.error(errorMsg, e);
             throw new RuntimeException(e);
         }
+
+        builder.reset(store.getRoot());
     }
+
 }

Modified: 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=1525142&r1=1525141&r2=1525142&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilderTest.java
Fri Sep 20 20:47:29 2013
@@ -49,16 +49,13 @@ public class KernelNodeBuilderTest {
     }
 
     private static void init(NodeStore store) throws CommitFailedException {
-        NodeStoreBranch branch = store.branch();
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
         builder.child("x").child("y").child("z");
-        branch.setRoot(builder.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
     }
 
     private static void run(NodeStore store) throws CommitFailedException {
-        NodeStoreBranch branch = store.branch();
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
 
         assertTrue("child node x should be present", builder.hasChildNode("x"));
         assertTrue("child node x/y should be present", builder.child("x")
@@ -76,7 +73,7 @@ public class KernelNodeBuilderTest {
         assertFalse("child node x/y/z not should not be present", builder
                 .child("x").child("y").hasChildNode("z"));
 
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java?rev=1525142&r1=1525141&r2=1525142&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
Fri Sep 20 20:47:29 2013
@@ -38,7 +38,6 @@ import org.apache.jackrabbit.oak.spi.sta
 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.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -50,18 +49,16 @@ public class KernelNodeStateTest {
     @Before
     public void setUp() throws CommitFailedException {
         NodeStore store = new KernelNodeStore(new MicroKernelImpl());
-        NodeStoreBranch branch = store.branch();
 
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
         builder.setProperty("a", 1);
         builder.setProperty("b", 2);
         builder.setProperty("c", 3);
         builder.child("x");
         builder.child("y");
         builder.child("z");
-        branch.setRoot(builder.getNodeState());
 
-        state = branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        state = store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
     }
 
     @After

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreCacheTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreCacheTest.java?rev=1525142&r1=1525141&r2=1525142&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreCacheTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreCacheTest.java
Fri Sep 20 20:47:29 2013
@@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.spi.com
 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.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -55,17 +54,14 @@ public class KernelNodeStoreCacheTest {
     public void setUp() throws Exception {
         wrapper = new MicroKernelWrapper(new MicroKernelImpl());
         store = new KernelNodeStore(wrapper);
-        NodeStoreBranch branch = store.branch();
 
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
         builder.child("a");
         NodeBuilder b = builder.child("b");
         b.child("c");
         b.child("d");
         b.child("e");
-        branch.setRoot(builder.getNodeState());
-
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
     }
 
     /**
@@ -111,13 +107,13 @@ public class KernelNodeStoreCacheTest {
     public void withIdFilter() throws Exception {
         wrapper.filter = PROP_FILTER_WITH_ID;
         int uncachedReads = readTreeWithCleanedCache();
-        System.out.println("Uncached reads: " + uncachedReads);
+        // System.out.println("Uncached reads: " + uncachedReads);
 
         modifyContent();
 
         int cachedReads = readTreeWithCache();
 
-        System.out.println("Cached reads: " + cachedReads);
+        // System.out.println("Cached reads: " + cachedReads);
         assertTrue(cachedReads < uncachedReads);
     }
 
@@ -140,11 +136,9 @@ public class KernelNodeStoreCacheTest {
     }
 
     private void modifyContent() throws Exception {
-        NodeStoreBranch branch = store.branch();
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
         builder.child("a").setProperty("foo", "bar");
-        branch.setRoot(builder.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
     }
 
     private void readTree(NodeState root) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java?rev=1525142&r1=1525141&r2=1525142&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
Fri Sep 20 20:47:29 2013
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.oak.spi.sta
 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.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -44,16 +43,14 @@ public class LargeKernelNodeStateTest {
     @Before
     public void setUp() throws CommitFailedException {
         NodeStore store = new KernelNodeStore(new MicroKernelImpl());
-        NodeStoreBranch branch = store.branch();
 
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
         builder.setProperty("a", 1);
         for (int i = 0; i <= N; i++) {
             builder.child("x" + i);
         }
-        branch.setRoot(builder.getNodeState());
 
-        state = branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        state = store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
     }
 
     @After

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java?rev=1525142&r1=1525141&r2=1525142&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
Fri Sep 20 20:47:29 2013
@@ -78,8 +78,7 @@ public class NodeStoreTest {
     @Before
     public void setUp() throws Exception {
         store = fixture.createNodeStore();
-        NodeStoreBranch branch = store.branch();
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
         NodeBuilder test = builder.child("test");
         test.setProperty("a", 1);
         test.setProperty("b", 2);
@@ -87,9 +86,7 @@ public class NodeStoreTest {
         test.child("x");
         test.child("y");
         test.child("z");
-        branch.setRoot(builder.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
-        root = store.getRoot();
+        root = store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
     }
 
     @After
@@ -178,12 +175,8 @@ public class NodeStoreTest {
 
         testBuilder.getChildNode("a").remove();
 
-        NodeState newRoot = rootBuilder.getNodeState();
-
-        NodeStoreBranch branch = store.branch();
-        branch.setRoot(newRoot);
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
-        store.getRoot(); // triggers the observer
+        store.merge(rootBuilder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        NodeState newRoot = store.getRoot(); // triggers the observer
 
         NodeState before = states[0];
         NodeState after = states[1];
@@ -208,11 +201,7 @@ public class NodeStoreTest {
 
         testBuilder.getChildNode("a").remove();
 
-        NodeState newRoot = rootBuilder.getNodeState();
-
-        NodeStoreBranch branch = store.branch();
-        branch.setRoot(newRoot);
-        branch.merge(new CommitHook() {
+        store.merge(rootBuilder, new CommitHook() {
             @Override
             public NodeState processCommit(NodeState before, NodeState after) {
                 NodeBuilder rootBuilder = after.builder();
@@ -232,22 +221,18 @@ public class NodeStoreTest {
 
     @Test
     public void manyChildNodes() throws CommitFailedException {
-        NodeStoreBranch branch = store.branch();
-        NodeBuilder root = branch.getHead().builder();
+        NodeBuilder root = store.getRoot().builder();
         NodeBuilder parent = root.child("parent");
         for (int i = 0; i <= KernelNodeState.MAX_CHILD_NODE_NAMES; i++) {
             parent.child("child-" + i);
         }
-        branch.setRoot(root.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(root, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         NodeState base = store.getRoot();
-        branch = store.branch();
-        root = branch.getHead().builder();
+        root = base.builder();
         parent = root.child("parent");
         parent.child("child-new");
-        branch.setRoot(root.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(root, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         Diff diff = new Diff();
         store.getRoot().compareAgainstBaseState(base, diff);
@@ -257,9 +242,10 @@ public class NodeStoreTest {
         assertEquals("child-new", diff.added.get(0));
 
         base = store.getRoot();
-        branch = store.branch();
-        branch.move("/parent/child-new", "/parent/child-moved");
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        root = base.builder();
+        parent = root.getChildNode("parent");
+        parent.getChildNode("child-new").moveTo(parent, "child-moved");
+        store.merge(root, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         diff = new Diff();
         store.getRoot().compareAgainstBaseState(base, diff);
@@ -270,14 +256,12 @@ public class NodeStoreTest {
         assertEquals("child-moved", diff.added.get(0));
 
         base = store.getRoot();
-        branch = store.branch();
-        root = branch.getHead().builder();
+        root = base.builder();
         parent = root.child("parent");
         parent.child("child-moved").setProperty("foo", "value");
         parent.child("child-moved").setProperty(
                 new MultiStringPropertyState("bar", Arrays.asList("value")));
-        branch.setRoot(root.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(root, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         diff = new Diff();
         store.getRoot().compareAgainstBaseState(base, diff);
@@ -289,14 +273,12 @@ public class NodeStoreTest {
         assertTrue(diff.addedProperties.contains("bar"));
 
         base = store.getRoot();
-        branch = store.branch();
-        root = branch.getHead().builder();
+        root = base.builder();
         parent = root.child("parent");
         parent.setProperty("foo", "value");
         parent.setProperty(new MultiStringPropertyState(
                 "bar", Arrays.asList("value")));
-        branch.setRoot(root.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(root, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         diff = new Diff();
         store.getRoot().compareAgainstBaseState(base, diff);
@@ -308,12 +290,10 @@ public class NodeStoreTest {
         assertTrue(diff.addedProperties.contains("bar"));
 
         base = store.getRoot();
-        branch = store.branch();
-        root = branch.getHead().builder();
+        root = base.builder();
         parent = root.child("parent");
         parent.getChildNode("child-moved").remove();
-        branch.setRoot(root.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(root, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         diff = new Diff();
         store.getRoot().compareAgainstBaseState(base, diff);
@@ -325,8 +305,8 @@ public class NodeStoreTest {
 
     @Test
     public void moveToSelf() throws CommitFailedException {
-        NodeStoreBranch branch = store.branch();
-        assertTrue(branch.move("/x", "/x"));
+        NodeBuilder builder = store.getRoot().builder();
+        assertTrue(builder.getChildNode("x").moveTo(builder, "x"));
     }
 
     @Test
@@ -344,26 +324,21 @@ public class NodeStoreTest {
     }
 
     private static NodeStore init(NodeStore store) throws CommitFailedException {
-        NodeStoreBranch branch = store.branch();
-        NodeBuilder builder = branch.getHead().builder();
+        NodeBuilder builder = store.getRoot().builder();
         builder.setChildNode("root");
-        branch.setRoot(builder.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
         return store;
     }
 
     @Test
     public void merge() throws CommitFailedException {
-        NodeStoreBranch branch1 = store.branch();
-        NodeBuilder builder1 = branch1.getHead().builder();
+        NodeState base = store.getRoot();
+        NodeBuilder builder1 = base.builder();
 
-        NodeStoreBranch branch2 = store.branch();
-        NodeBuilder builder2 = branch1.getHead().builder();
+        NodeBuilder builder2 = base.builder();
 
         builder1.setChildNode("node1");
-        branch1.setRoot(builder1.getNodeState());
         builder2.setChildNode("node2");
-        branch2.setRoot(builder2.getNodeState());
 
         store.merge(builder1, EmptyHook.INSTANCE, new PostCommitHook() {
             @Override
@@ -406,17 +381,14 @@ public class NodeStoreTest {
     }
 
     private void compareAgainstBaseState(int childNodeCount) throws CommitFailedException
{
-        NodeStoreBranch branch = store.branch();
-
-        NodeState before = branch.getHead();
+        NodeState before = store.getRoot();
         NodeBuilder builder = before.builder();
         for (int k = 0; k < childNodeCount; k++) {
             builder.child("c" + k);
         }
 
         builder.child("foo").child(":bar").child("quz").setProperty("p", "v");
-        branch.setRoot(builder.getNodeState());
-        branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
+        store.merge(builder, EmptyHook.INSTANCE, PostCommitHook.EMPTY);
 
         NodeState after = store.getRoot();
         Diff diff = new Diff();



Mime
View raw message