jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1397047 - in /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak: AbstractOakTest.java RootTest.java TreeTest.java
Date Thu, 11 Oct 2012 13:40:41 GMT
Author: mreutegg
Date: Thu Oct 11 13:40:41 2012
New Revision: 1397047

URL: http://svn.apache.org/viewvc?rev=1397047&view=rev
Log:
OAK-169: Support orderable nodes
- more tests (currently fail and are ignored)

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/RootTest.java  
(with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TreeTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java?rev=1397047&r1=1397046&r2=1397047&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractOakTest.java
Thu Oct 11 13:40:41 2012
@@ -28,12 +28,17 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
 import org.apache.jackrabbit.oak.spi.lifecycle.CompositeMicroKernelTracker;
 import org.apache.jackrabbit.oak.spi.lifecycle.MicroKernelTracker;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.junit.Before;
 
+import com.google.common.collect.Lists;
+
+import static org.junit.Assert.assertEquals;
+
 /**
  * AbstractOakTest is the base class for oak test execution.
  */
@@ -77,4 +82,12 @@ public abstract class AbstractOakTest {
         return new CompositeMicroKernelTracker(hooks);
     }
 
+    protected void checkSequence(Iterable<Tree> trees, String... names) {
+        List<String> expected = Lists.newArrayList(names);
+        List<String> actual = Lists.newArrayList();
+        for (Tree t : trees) {
+            actual.add(t.getName());
+        }
+        assertEquals(expected.toString(), actual.toString());
+    }
 }
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/RootTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/RootTest.java?rev=1397047&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/RootTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/RootTest.java Thu
Oct 11 13:40:41 2012
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.commit.ConflictValidator;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Contains tests related to {@link Root}
+ */
+public class RootTest extends AbstractOakTest {
+
+    @Override
+    protected ContentRepository createRepository() {
+        return new Oak().with(new OpenSecurityProvider()).with(
+                new ConflictValidator()).createContentRepository();
+    }
+
+    @Test
+    @Ignore("OAK-169")
+    public void copyOrderableNodes() throws Exception {
+        ContentSession s = createAdminSession();
+        try {
+            Root r = s.getLatestRoot();
+            Tree t = r.getTree("/");
+            Tree c = t.addChild("c");
+            c.addChild("node1").orderBefore(null);
+            c.addChild("node2");
+            t.addChild("node3");
+            r.commit();
+
+            r.copy("/node3", "/c/node3");
+            c = r.getTree("/").getChild("c");
+            checkSequence(c.getChildren(), "node1", "node2", "node3");
+
+        } finally {
+            s.close();
+        }
+    }
+
+    @Test
+    @Ignore("OAK-169")
+    public void moveOrderableNodes() throws Exception {
+        ContentSession s = createAdminSession();
+        try {
+            Root r = s.getLatestRoot();
+            Tree t = r.getTree("/");
+            Tree c = t.addChild("c");
+            c.addChild("node1").orderBefore(null);
+            c.addChild("node2");
+            t.addChild("node3");
+            r.commit();
+
+            r.move("/node3", "/c/node3");
+            c = r.getTree("/").getChild("c");
+            checkSequence(c.getChildren(), "node1", "node2", "node3");
+
+        } finally {
+            s.close();
+        }
+    }
+}

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

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

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TreeTest.java?rev=1397047&r1=1397046&r2=1397047&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TreeTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TreeTest.java Thu
Oct 11 13:40:41 2012
@@ -18,17 +18,20 @@
  */
 package org.apache.jackrabbit.oak;
 
-import java.util.Iterator;
+import java.util.Set;
 
+import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.commit.ConflictValidator;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.junit.Test;
 
+import com.google.common.collect.Sets;
+
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 
 /**
  * Contains tests related to {@link Tree}
@@ -37,7 +40,8 @@ public class TreeTest extends AbstractOa
 
     @Override
     protected ContentRepository createRepository() {
-        return createEmptyRepository();
+        return new Oak().with(new OpenSecurityProvider()).with(
+                new ConflictValidator()).createContentRepository();
     }
     @Test
     public void orderBefore() throws Exception {
@@ -52,23 +56,23 @@ public class TreeTest extends AbstractOa
             t = r.getTree("/");
             t.getChild("node1").orderBefore("node2");
             t.getChild("node3").orderBefore(null);
-            checkSequence(t.getChildren().iterator(), "node1", "node2", "node3");
+            checkSequence(t.getChildren(), "node1", "node2", "node3");
             r.commit();
             // check again after commit
             t = r.getTree("/");
-            checkSequence(t.getChildren().iterator(), "node1", "node2", "node3");
+            checkSequence(t.getChildren(), "node1", "node2", "node3");
 
             t.getChild("node3").orderBefore("node2");
-            checkSequence(t.getChildren().iterator(), "node1", "node3", "node2");
+            checkSequence(t.getChildren(), "node1", "node3", "node2");
             r.commit();
             t = r.getTree("/");
-            checkSequence(t.getChildren().iterator(), "node1", "node3", "node2");
+            checkSequence(t.getChildren(), "node1", "node3", "node2");
 
             t.getChild("node1").orderBefore(null);
-            checkSequence(t.getChildren().iterator(), "node3", "node2", "node1");
+            checkSequence(t.getChildren(), "node3", "node2", "node1");
             r.commit();
             t = r.getTree("/");
-            checkSequence(t.getChildren().iterator(), "node3", "node2", "node1");
+            checkSequence(t.getChildren(), "node3", "node2", "node1");
 
             // TODO :childOrder property invisible?
             //assertEquals("must not have any properties", 0, t.getPropertyCount());
@@ -77,11 +81,82 @@ public class TreeTest extends AbstractOa
         }
     }
 
-    private void checkSequence(Iterator<Tree> trees, String... names) {
-        for (String name : names) {
-            assertTrue(trees.hasNext());
-            assertEquals("wrong sequence", name, trees.next().getName());
+    @Test
+    public void concurrentAddChildOrderable() throws Exception {
+        ContentSession s1 = createAdminSession();
+        try {
+            Root r1 = s1.getLatestRoot();
+            Tree t1 = r1.getTree("/");
+            t1.addChild("node1").orderBefore(null);
+            t1.addChild("node2");
+            t1.addChild("node3");
+            r1.commit();
+            ContentSession s2 = createAdminSession();
+            try {
+                Root r2 = s2.getLatestRoot();
+                Tree t2 = r2.getTree("/");
+
+                t1 = r1.getTree("/");
+                // node4 from s1
+                t1.addChild("node4");
+                r1.commit();
+
+                // node5 from s2
+                t2.addChild("node5");
+                try {
+                    r2.commit();
+                    // commit must fail
+                } catch (CommitFailedException e) {
+                }
+
+                r1 = s1.getLatestRoot();
+                t1 = r1.getTree("/");
+                checkSequence(t1.getChildren(), "node1", "node2", "node3", "node4");
+            } finally {
+                s2.close();
+            }
+        } finally {
+            s1.close();
+        }
+
+    }
+
+    @Test
+    public void concurrentAddChild() throws Exception {
+        ContentSession s1 = createAdminSession();
+        try {
+            Root r1 = s1.getLatestRoot();
+            Tree t1 = r1.getTree("/");
+            t1.addChild("node1");
+            t1.addChild("node2");
+            t1.addChild("node3");
+            r1.commit();
+            ContentSession s2 = createAdminSession();
+            try {
+                Root r2 = s2.getLatestRoot();
+                Tree t2 = r2.getTree("/");
+
+                t1 = r1.getTree("/");
+                // node4 from s1
+                t1.addChild("node4");
+                r1.commit();
+
+                // node5 from s2
+                t2.addChild("node5");
+                r2.commit();
+
+                r1 = s1.getLatestRoot();
+                t1 = r1.getTree("/");
+                Set<String> names = Sets.newHashSet();
+                for (Tree t : t1.getChildren()) {
+                    names.add(t.getName());
+                }
+                assertEquals(Sets.newHashSet("node1", "node2", "node3", "node4", "node5"),
names);
+            } finally {
+                s2.close();
+            }
+        } finally {
+            s1.close();
         }
-        assertFalse("no more nodes expected", trees.hasNext());
     }
 }



Mime
View raw message