You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2016/01/12 16:31:40 UTC

svn commit: r1724260 - /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterConflictTest.java

Author: mreutegg
Date: Tue Jan 12 15:31:40 2016
New Revision: 1724260

URL: http://svn.apache.org/viewvc?rev=1724260&view=rev
Log:
OAK-3859: Suspended commit depends on non-conflicting change

Add (ignored) test

Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterConflictTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterConflictTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterConflictTest.java?rev=1724260&r1=1724259&r2=1724260&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterConflictTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ClusterConflictTest.java Tue Jan 12 15:31:40 2016
@@ -16,7 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.document;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.annotation.CheckForNull;
 
@@ -35,6 +38,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -139,6 +143,74 @@ public class ClusterConflictTest {
         }
     }
 
+    // OAK-3859
+    @Ignore("OAK-3859")
+    @Test
+    public void mixedConflictAndCollision() throws Exception {
+        NodeBuilder b1 = ns1.getRoot().builder();
+        b1.child("test");
+        merge(ns1, b1);
+
+        ns1.runBackgroundOperations();
+        ns2.runBackgroundOperations();
+
+        AtomicLong counter = new AtomicLong();
+        final List<Exception> exceptions = Collections.synchronizedList(
+                new ArrayList<Exception>());
+        // the writers perform conflicting changes
+        List<Thread> writers = Lists.newArrayList();
+        writers.add(new Thread(new Writer(exceptions, ns1, counter)));
+        writers.add(new Thread(new Writer(exceptions, ns1, counter)));
+        for (Thread t : writers) {
+            t.start();
+        }
+
+        for (int i = 0; i < 10; i++) {
+            NodeBuilder b21 = ns2.getRoot().builder();
+            // this change does not conflict with changes on ns1 but
+            // will be considered a collision
+            b21.child("test").setProperty("q", 1);
+            merge(ns2, b21);
+        }
+
+        for (Thread t : writers) {
+            t.join(10000);
+        }
+
+        for (Exception e : exceptions) {
+            throw e;
+        }
+    }
+
+    private static class Writer implements Runnable {
+
+        private final List<Exception> exceptions;
+        private final NodeStore ns;
+        private final AtomicLong counter;
+
+        public Writer(List<Exception> exceptions,
+                      NodeStore ns,
+                      AtomicLong counter) {
+            this.exceptions = exceptions;
+            this.ns = ns;
+            this.counter = counter;
+        }
+
+        @Override
+        public void run() {
+            try {
+                for (int i = 0; i < 200; i++) {
+                    NodeBuilder b = ns.getRoot().builder();
+                    b.child("test").setProperty("p", counter.incrementAndGet());
+                    merge(ns, b);
+                }
+            } catch (CommitFailedException e) {
+                e.printStackTrace();
+                exceptions.add(e);
+            }
+        }
+    }
+
     private static class TestHook extends EditorHook {
 
         TestHook() {