Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ConcurrentAddRemove2IT.java =================================================================== --- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ConcurrentAddRemove2IT.java (revision 0) +++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ConcurrentAddRemove2IT.java (working copy) @@ -0,0 +1,111 @@ +/* + * 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.jcr; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * ConcurrentAddRemove2IT... + */ +public class ConcurrentAddRemove2IT extends AbstractRepositoryTest { + + private static final int NUM_WORKERS = 2; + + private static final long RUN_TIME = TimeUnit.SECONDS.toMillis(100); + + public ConcurrentAddRemove2IT(NodeStoreFixture fixture) { + super(fixture); + } + + @Test + public void concurrentIndexUpdate() throws Exception { + List exceptions = Collections.synchronizedList(new ArrayList()); + // prepare parent structure + Node test = getAdminSession().getRootNode().addNode("test", "oak:Unstructured"); + for (int i = 0; i < 5; i++) { + test = test.addNode("level-" + i); + } + getAdminSession().save(); + List worker = new ArrayList(); + for (int i = 0; i < NUM_WORKERS; i++) { + worker.add(new Thread(new Worker( + createAdminSession(), test.getPath(), "child-" + i, exceptions))); + } + for (Thread t : worker) { + t.start(); + } + for (Thread t : worker) { + t.join(); + } + for (Exception e : exceptions) { + e.printStackTrace(); + fail(e.toString()); + } + } + + private static final class Worker implements Runnable { + + private final Session s; + private final String path; + private final String name; + private final List exceptions; + + Worker(Session s, String path, String name, List exceptions) { + this.s = s; + this.path = path; + this.name = name; + this.exceptions = exceptions; + } + + @Override + public void run() { + try { + long end = System.currentTimeMillis() + RUN_TIME; + while (end > System.currentTimeMillis()/* && exceptions.isEmpty()*/) { + s.refresh(false); + Node n = s.getNode(path); + if (n.hasNode(name)) { + n.getNode(name).remove(); + } else { + n.addNode(name, "nt:unstructured"); + } + try { + s.save(); + } catch (RepositoryException e) { + System.out.println(Thread.currentThread().getName() + ": " + e.getCause().getCause().toString()); + exceptions.add(e); + } + } + } catch (RepositoryException e) { + exceptions.add(e); + } finally { + s.logout(); + } + } + } +} Property changes on: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ConcurrentAddRemove2IT.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java =================================================================== --- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java (revision 1687113) +++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java (working copy) @@ -166,7 +166,7 @@ } public DocumentFixture(String uri) { - this(uri, true, null); + this(uri, false, null); } public DocumentFixture() { Index: oak-jcr/src/test/resources/logback-test.xml =================================================================== --- oak-jcr/src/test/resources/logback-test.xml (revision 1687113) +++ oak-jcr/src/test/resources/logback-test.xml (working copy) @@ -33,6 +33,7 @@ +