jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r550733 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core: ConcurrentCheckinMixedTransactionTest.java ConcurrentVersioningWithTransactionsTest.java MultiThreadingTests.java TestAll.java
Date Tue, 26 Jun 2007 08:18:23 GMT
Author: mreutegg
Date: Tue Jun 26 01:18:22 2007
New Revision: 550733

URL: http://svn.apache.org/viewvc?view=rev&rev=550733
Log:
JCR-962: Deadlocks in ConcurrentVersioningWithTransactionsTest
- bertrands test case from JCR-962 issue
- created new test suite MultiThreadingTests, which contains all long running test cases related
to multi-threading.

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentCheckinMixedTransactionTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningWithTransactionsTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiThreadingTests.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentCheckinMixedTransactionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentCheckinMixedTransactionTest.java?view=auto&rev=550733
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentCheckinMixedTransactionTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentCheckinMixedTransactionTest.java
Tue Jun 26 01:18:22 2007
@@ -0,0 +1,95 @@
+/*
+ * 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.core;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+
+/**
+ * <code>ConcurrentCheckinMixedTransactionTest</code> performs concurrent
+ * version operations with only some threads using XATransactions.
+ */
+public class ConcurrentCheckinMixedTransactionTest
+        extends AbstractConcurrencyTest {
+
+    private static final int NUM_THREADS = 10;
+
+    private static final int RUN_NUM_SECONDS = 20;
+
+    public void testCheckInOut() throws RepositoryException {
+        final long end = System.currentTimeMillis() + RUN_NUM_SECONDS * 1000;
+        // tasks with even ids run within transactions
+        final int[] taskId = new int[1];
+        Thread t = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    runTask(new Task() {
+                        public void execute(Session session, Node test)
+                                throws RepositoryException {
+                            int id;
+                            synchronized (ConcurrentCheckinMixedTransactionTest.this) {
+                                id = taskId[0]++;
+                            }
+                            int i = 0;
+                            while (end > System.currentTimeMillis()) {
+                                UserTransactionImpl uTx = null;
+                                try {
+                                    if (id % 2 == 0) {
+                                        uTx = new UserTransactionImpl(session);
+                                        uTx.begin();
+                                    }
+                                    Node n = test.addNode("node" + i++);
+                                    n.addMixin(mixVersionable);
+                                    session.save();
+                                    n.checkout();
+                                    n.checkin();
+                                    if (uTx != null) {
+                                        uTx.commit();
+                                    }
+                                } catch (NotSupportedException e) {
+                                    throw new RepositoryException(e);
+                                } catch (SystemException e) {
+                                    throw new RepositoryException(e);
+                                } catch (HeuristicMixedException e) {
+                                    throw new RepositoryException(e);
+                                } catch (HeuristicRollbackException e) {
+                                    throw new RepositoryException(e);
+                                } catch (RollbackException e) {
+                                    throw new RepositoryException(e);
+                                }
+                            }
+                        }
+                    }, NUM_THREADS);
+                } catch (RepositoryException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+        t.start();
+        try {
+            t.join();
+        } catch (InterruptedException e) {
+            // ignore
+        }
+    }
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningWithTransactionsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningWithTransactionsTest.java?view=auto&rev=550733
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningWithTransactionsTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ConcurrentVersioningWithTransactionsTest.java
Tue Jun 26 01:18:22 2007
@@ -0,0 +1,190 @@
+/*
+ * 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.core;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.version.Version;
+import javax.transaction.UserTransaction;
+
+import org.apache.jackrabbit.core.state.StaleItemStateException;
+
+/**
+ * <code>ConcurrentVersioningTest</code> contains test cases that run version
+ * operations with concurrent threads.
+ */
+public class ConcurrentVersioningWithTransactionsTest extends AbstractConcurrencyTest {
+
+    /**
+     * The number of threads.
+     */
+    private static final int CONCURRENCY = 100;
+
+    /**
+     * The total number of operations to execute. E.g. number of checkins
+     * performed by the threads.
+     */
+    private static final int NUM_OPERATIONS = 100;
+
+    public void testConcurrentAddVersionableInTransaction()
+            throws RepositoryException {
+        runTask(new Task() {
+            public void execute(Session session, Node test)
+                    throws RepositoryException {
+                // add versionable nodes
+                final String threadName = Thread.currentThread().getName();
+                Node parent;
+                synchronized (ConcurrentVersioningWithTransactionsTest.class) {
+                    parent = test.addNode(threadName);
+                    test.save();
+                }
+                for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
+                    try {
+                        final UserTransaction utx = new UserTransactionImpl(test.getSession());
+                        utx.begin();
+                        final String nodeName = "test" + i;
+                        Node n = parent.addNode(nodeName);
+                        n.addMixin(mixVersionable);
+                        session.save();
+                        utx.commit();
+                    } catch (Exception e) {
+                        final Throwable deepCause = getLevel2Cause(e);
+                        if (deepCause != null && deepCause instanceof StaleItemStateException)
{
+                            // ignore
+                        } else {
+                            throw new RepositoryException(threadName + ", i=" + i + ":" +
e.getClass().getName(), e);
+                        }
+                    }
+                }
+            }
+        }, CONCURRENCY);
+    }
+
+    public void testConcurrentCheckinInTransaction()
+            throws RepositoryException {
+        runTask(new Task() {
+            public void execute(Session session, Node test)
+                    throws RepositoryException {
+                int i = 0;
+                try {
+                    Node n = test.addNode("test");
+                    n.addMixin(mixVersionable);
+                    session.save();
+                    for (i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
+                        final UserTransaction utx = new UserTransactionImpl(test.getSession());
+                        utx.begin();
+                        n.checkout();
+                        n.checkin();
+                        utx.commit();
+                    }
+                    n.checkout();
+                } catch (Exception e) {
+                    final String threadName = Thread.currentThread().getName();
+                    final Throwable deepCause = getLevel2Cause(e);
+                    if (deepCause != null && deepCause instanceof StaleItemStateException)
{
+                        // ignore
+                    } else {
+                        throw new RepositoryException(threadName + ", i=" + i + ":" + e.getClass().getName(),
e);
+                    }
+                }
+            }
+        }, CONCURRENCY);
+    }
+
+    public void testConcurrentCreateAndCheckinCheckoutInTransaction()
+            throws RepositoryException {
+        runTask(new Task() {
+            public void execute(Session session, Node test)
+                    throws RepositoryException {
+                // add versionable nodes
+                for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
+                    try {
+                        final UserTransaction utx = new UserTransactionImpl(test.getSession());
+                        utx.begin();
+                        Node n = test.addNode("test" + i);
+                        n.addMixin(mixVersionable);
+                        session.save();
+                        n.checkout();
+                        n.checkin();
+                        n.checkout();
+                        utx.commit();
+                    } catch (Exception e) {
+                        final String threadName = Thread.currentThread().getName();
+                        final Throwable deepCause = getLevel2Cause(e);
+                        if (deepCause != null && deepCause instanceof StaleItemStateException)
{
+                            // ignore
+                        } else {
+                            throw new RepositoryException(threadName + ", i=" + i + ":" +
e.getClass().getName(), e);
+                        }
+                    }
+                }
+            }
+        }, CONCURRENCY);
+    }
+
+    public void testConcurrentRestoreInTransaction()
+            throws RepositoryException {
+        runTask(new Task() {
+            public void execute(Session session, Node test)
+                    throws RepositoryException {
+                int i = 0;
+                try {
+                    Node n = test.addNode("test");
+                    n.addMixin(mixVersionable);
+                    session.save();
+                    // create 3 version
+                    List versions = new ArrayList();
+                    for (i = 0; i < 3; i++) {
+                        n.checkout();
+                        versions.add(n.checkin());
+                    }
+                    // do random restores
+                    Random rand = new Random();
+                    for (i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
+                        Version v = (Version) versions.get(rand.nextInt(versions.size()));
+                        n.restore(v, true);
+                    }
+                    n.checkout();
+                } catch (Exception e) {
+                    final String threadName = Thread.currentThread().getName();
+                    final Throwable deepCause = getLevel2Cause(e);
+                    if (deepCause != null && deepCause instanceof StaleItemStateException)
{
+                        // ignore
+                    } else {
+                        throw new RepositoryException(threadName + ", i=" + i + ":" + e.getClass().getName(),
e);
+                    }
+                }
+            }
+        }, CONCURRENCY);
+    }
+
+    private static Throwable getLevel2Cause(Throwable t) {
+        Throwable result = null;
+        try {
+            result = t.getCause().getCause();
+        } catch (NullPointerException npe) {
+            // ignore, we have no deep cause
+        }
+        return result;
+
+    }
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiThreadingTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiThreadingTests.java?view=auto&rev=550733
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiThreadingTests.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiThreadingTests.java
Tue Jun 26 01:18:22 2007
@@ -0,0 +1,45 @@
+/*
+ * 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.core;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.framework.Test;
+
+/**
+ * <code>MultiThreadingTests</code> is a test suite that includes all
+ * multi-threading related tests.
+ */
+public class MultiThreadingTests extends TestCase {
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Multi-threading tests");
+
+        suite.addTestSuite(ConcurrencyTest.class);
+        suite.addTestSuite(ConcurrentLoginTest.class);
+        suite.addTestSuite(ConcurrentNodeModificationTest.class);
+        suite.addTestSuite(ConcurrentReadWriteTest.class);
+        suite.addTestSuite(ConcurrentSaveTest.class);
+        suite.addTestSuite(ConcurrentVersioningTest.class);
+        suite.addTestSuite(ConcurrentVersioningWithTransactionsTest.class);
+        suite.addTestSuite(ConcurrentCheckinMixedTransactionTest.class);
+        suite.addTestSuite(LockTest.class);
+        suite.addTestSuite(ReadVersionsWhileModified.class);
+
+        return suite;
+    }
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java?view=diff&rev=550733&r1=550732&r2=550733
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
Tue Jun 26 01:18:22 2007
@@ -26,23 +26,15 @@
 public class TestAll extends TestCase {
 
     /**
-     * Returns a <code>Test</code> suite that executes all tests inside this
-     * package.
-     *
      * @return a <code>Test</code> suite that executes all tests inside this
-     *         package.
+     *         package, except the multi-threading related ones.
      */
     public static Test suite() {
         TestSuite suite = new TestSuite("Core tests");
 
-        //suite.addTestSuite(ConcurrencyTest.class);
-        //suite.addTestSuite(ConcurrentSaveTest.class);
-        //suite.addTestSuite(ConcurrentNodeModificationTest.class);
-        //suite.addTestSuite(LockTest.class);
         suite.addTestSuite(NamespaceRegistryImplTest.class);
         suite.addTestSuite(TransientRepositoryTest.class);
         suite.addTestSuite(XATest.class);
-        suite.addTestSuite(ConcurrentLoginTest.class);
 
         return suite;
     }



Mime
View raw message