jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r791253 - in /jackrabbit/trunk: jackrabbit-core/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/ ...
Date Sun, 05 Jul 2009 14:22:01 GMT
Author: mreutegg
Date: Sun Jul  5 14:22:01 2009
New Revision: 791253

URL: http://svn.apache.org/viewvc?rev=791253&view=rev
Log:
JCR-2188: Parallelize tests

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/resources/repositoryHelperPool.properties  
(with props)
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/ConcurrentTestSuite.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/pom.xml
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TreeComparator.java

Modified: jackrabbit/trunk/jackrabbit-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/pom.xml?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-core/pom.xml Sun Jul  5 14:22:01 2009
@@ -49,6 +49,9 @@
                 <copy todir="${project.build.directory}/repository">
                   <fileset dir="${basedir}/src/test/repository"/>
                 </copy>
+                <copy todir="${project.build.directory}/repository-2">
+                  <fileset dir="${basedir}/src/test/repository"/>
+                </copy>
               </tasks>
             </configuration>
             <goals>

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?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- 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
Sun Jul  5 14:22:01 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core;
 
+import org.apache.jackrabbit.test.ConcurrentTestSuite;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -30,7 +32,7 @@
      *         package, except the multi-threading related ones.
      */
     public static Test suite() {
-        TestSuite suite = new TestSuite("Core tests");
+        TestSuite suite = new ConcurrentTestSuite("Core tests");
 
         suite.addTestSuite(CachingHierarchyManagerTest.class);
         suite.addTestSuite(ShareableNodeTest.class);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
Sun Jul  5 14:22:01 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.data;
 
+import org.apache.jackrabbit.test.ConcurrentTestSuite;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -31,7 +33,7 @@
      * @return a test suite that executes all tests inside this package
      */
     public static Test suite() {
-        TestSuite suite = new TestSuite("Data tests");
+        TestSuite suite = new ConcurrentTestSuite("Data tests");
         suite.addTestSuite(LazyFileInputStreamTest.class);
         suite.addTestSuite(OpenFilesTest.class);
         suite.addTestSuite(DataStoreTest.class);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java
Sun Jul  5 14:22:01 2009
@@ -23,12 +23,23 @@
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.core.query.lucene.SlowQueryHandler;
 
 /**
  * <code>WorkspaceInitTest</code>...
  */
 public class WorkspaceInitTest extends AbstractJCRTest {
 
+    protected void setUp() throws Exception {
+        super.setUp();
+        SlowQueryHandler.setInitializationDelay(10 * 1000);
+    }
+
+    protected void tearDown() throws Exception {
+        SlowQueryHandler.setInitializationDelay(0);
+        super.tearDown();
+    }
+
     public void testIdleTime() throws Exception {
         // simply access the workspace, which will cause
         // initialization of SlowQueryHandler.

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
Sun Jul  5 14:22:01 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.query;
 
 import org.apache.jackrabbit.core.query.lucene.hits.ArrayHitsTest;
+import org.apache.jackrabbit.test.ConcurrentTestSuite;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -35,7 +36,7 @@
      *         package.
      */
     public static Test suite() {
-        TestSuite suite = new TestSuite("Search tests");
+        TestSuite suite = new ConcurrentTestSuite("Search tests");
 
         suite.addTestSuite(SimpleQueryTest.class);
         suite.addTestSuite(FulltextQueryTest.class);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java
Sun Jul  5 14:22:01 2009
@@ -27,11 +27,13 @@
  */
 public class SlowQueryHandler extends SearchIndex {
 
+    private static long INITIALIZATION_DELAY = 0;
+
     protected void doInit() throws IOException {
         // sleep for 10 seconds then try to read from the item state manager
         // the repository.xml is configured with a 5 second maxIdleTime
         try {
-            Thread.sleep(10 * 1000);
+            Thread.sleep(INITIALIZATION_DELAY);
         } catch (InterruptedException e) {
             // ignore
         }
@@ -39,4 +41,8 @@
         getContext().getItemStateManager().hasItemState(id);
         super.doInit();
     }
+
+    public static void setInitializationDelay(long delay) {
+        INITIALIZATION_DELAY = delay;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java
Sun Jul  5 14:22:01 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import org.apache.jackrabbit.test.ConcurrentTestSuite;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -33,7 +34,7 @@
      *         package.
      */
     public static Test suite() {
-        TestSuite suite = new TestSuite("Search tests");
+        TestSuite suite = new ConcurrentTestSuite("Search tests");
 
         suite.addTestSuite(IndexingQueueTest.class);
         suite.addTestSuite(DecimalConvertTest.class);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/TestAll.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/TestAll.java
Sun Jul  5 14:22:01 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.security.authorization.acl;
 
+import org.apache.jackrabbit.test.ConcurrentTestSuite;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -33,7 +35,7 @@
      *         package.
      */
     public static Test suite() {
-        TestSuite suite = new TestSuite("security.authorization.acl tests");
+        TestSuite suite = new ConcurrentTestSuite("security.authorization.acl tests");
 
         suite.addTestSuite(ACLTemplateTest.class);
         suite.addTestSuite(EntryTest.class);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
Sun Jul  5 14:22:01 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.security.user;
 
+import org.apache.jackrabbit.test.ConcurrentTestSuite;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -28,7 +30,7 @@
      * @return a <code>Test</code> suite that executes all test in this package.
      */
     public static Test suite() {
-        TestSuite suite = new TestSuite("core.security.user tests");
+        TestSuite suite = new ConcurrentTestSuite("core.security.user tests");
 
         suite.addTestSuite(UserManagerImplTest.class);
         suite.addTestSuite(AuthorizableImplTest.class);

Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/repositoryHelperPool.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/repositoryHelperPool.properties?rev=791253&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/repositoryHelperPool.properties (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/repositoryHelperPool.properties Sun
Jul  5 14:22:01 2009
@@ -0,0 +1,20 @@
+#  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.
+
+# first helper uses default values
+helper.0.=
+
+# second helper overwrites repository home
+helper.1.org.apache.jackrabbit.repository.home=target/repository-2

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/resources/repositoryHelperPool.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Sun Jul  5 14:22:01 2009
@@ -49,9 +49,9 @@
 public abstract class AbstractJCRTest extends JUnitTest {
 
     /**
-     * Helper object to access repository transparently
+     * Pool of helper objects to access repository transparently
      */
-    private static RepositoryHelper helper = new RepositoryHelper();
+    private static final RepositoryHelperPool HELPER_POOL = new RepositoryHelperPoolImpl();
 
     /**
      * Namespace URI for jcr prefix.
@@ -74,6 +74,11 @@
     public static final String NS_SV_URI = "http://www.jcp.org/jcr/sv/1.0";
 
     /**
+     * The repository helper for this test.
+     */
+    private RepositoryHelper helper;
+
+    /**
      * JCR Name jcr:primaryType using the namespace resolver of the current session.
      */
     protected String jcrPrimaryType;
@@ -439,7 +444,17 @@
      * @param testResult the test result.
      */
     public void run(TestResult testResult) {
-        super.run(new JCRTestResult(testResult, log));
+        try {
+            helper = HELPER_POOL.borrowHelper();
+            try {
+                super.run(new JCRTestResult(testResult, log));
+            } finally {
+                HELPER_POOL.returnHelper(helper);
+                helper = null;
+            }
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/ConcurrentTestSuite.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/ConcurrentTestSuite.java?rev=791253&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/ConcurrentTestSuite.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/ConcurrentTestSuite.java
Sun Jul  5 14:22:01 2009
@@ -0,0 +1,92 @@
+/*
+ * 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.test;
+
+import junit.framework.TestSuite;
+import junit.framework.TestResult;
+import junit.framework.Test;
+import EDU.oswego.cs.dl.util.concurrent.Executor;
+import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
+
+/**
+ * <code>ConcurrentTestSuite</code> implements a test suite that runs tests
+ * with a given concurrency level using multiple threads.
+ */
+public class ConcurrentTestSuite extends TestSuite {
+
+    private final Executor executor;
+
+    private volatile int finishedTestCount;
+
+    public ConcurrentTestSuite(String name) {
+        this(name, Runtime.getRuntime().availableProcessors() * 2);
+    }
+
+    public ConcurrentTestSuite() {
+        this(null);
+    }
+
+    public ConcurrentTestSuite(int numThreads) {
+        this(null, numThreads);
+    }
+
+    public ConcurrentTestSuite(String name, int numThreads) {
+        super(name);
+        executor = new PooledExecutor(numThreads) {
+            {
+                waitWhenBlocked();
+            }
+        };
+    }
+
+    public void run(TestResult result) {
+        finishedTestCount = 0;
+        super.run(result);
+        waitUntilFinished();
+    }
+
+    public void runTest(final Test test, final TestResult result) {
+        try {
+            executor.execute(new Runnable() {
+                public void run() {
+                    try {
+                        ConcurrentTestSuite.super.runTest(test, result);
+                    } finally {
+                        runFinished();
+                    }
+                }
+            });
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e); 
+        }
+    }
+
+    private synchronized void waitUntilFinished() {
+        while (finishedTestCount < testCount()) {
+            try {
+                wait();
+            } catch (InterruptedException e) {
+                return; // ignore
+            }
+        }
+    }
+
+    private synchronized void runFinished() {
+        finishedTestCount++;
+        notifyAll();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/ConcurrentTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java
Sun Jul  5 14:22:01 2009
@@ -16,12 +16,10 @@
  */
 package org.apache.jackrabbit.test;
 
-import junit.framework.TestSuite;
-
 /**
  * Test suite that includes all the JCR API tests
  */
-public class JCRTestSuite extends TestSuite {
+public class JCRTestSuite extends ConcurrentTestSuite {
 
     public JCRTestSuite() {
         super("JCR API tests");

Added: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java?rev=791253&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
Sun Jul  5 14:22:01 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.test;
+
+/**
+ * <code>RepositoryHelperPool</code> defines a pool of repository helper instances.
+ */
+public interface RepositoryHelperPool {
+
+    /**
+     * Borrows a repository helper instance.
+     *
+     * @return a repository helper.
+     * @throws InterruptedException if this thread is interrupted while waiting
+     *                              for a repository helper.
+     */
+    public RepositoryHelper borrowHelper() throws InterruptedException;
+
+    /**
+     * Returns the given repository helper to the pool.
+     *
+     * @param helper the repository helper to return.
+     */
+    public void returnHelper(RepositoryHelper helper);
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java?rev=791253&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
Sun Jul  5 14:22:01 2009
@@ -0,0 +1,91 @@
+/*
+ * 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.test;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * <code>RepositoryHelperPoolImpl</code> implements a pool of repository helper
+ * instances.
+ */
+public class RepositoryHelperPoolImpl implements RepositoryHelperPool {
+
+    private static final String PROP_FILE = "repositoryHelperPool.properties";
+
+    private List helpers = new LinkedList();
+
+    public RepositoryHelperPoolImpl() {
+        InputStream in = RepositoryHelperPoolImpl.class.getClassLoader().getResourceAsStream(PROP_FILE);
+        if (in != null) {
+            try {
+                Properties props = new Properties();
+                props.load(in);
+                for (int i = 0;; i++) {
+                    String prefix = "helper." + i + ".";
+                    Map helperProp = new HashMap();
+                    for (Iterator it = props.entrySet().iterator(); it.hasNext(); ) {
+                        Map.Entry entry = (Map.Entry) it.next();
+                        String key = (String) entry.getKey();
+                        if (key.startsWith(prefix)) {
+                            helperProp.put(key.substring(prefix.length()), entry.getValue());
+                        }
+                    }
+                    if (helperProp.isEmpty()) {
+                        break;
+                    }
+                    addHelper(new RepositoryHelper(helperProp));
+                }
+            } catch (IOException e) {
+                // ignore and use default
+            } finally {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+        }
+        if (helpers.isEmpty()) {
+            // use single default repo helper
+            addHelper(new RepositoryHelper());
+        }
+    }
+
+    public synchronized void addHelper(RepositoryHelper helper) {
+        helpers.add(helper);
+    }
+
+    public synchronized RepositoryHelper borrowHelper()
+            throws InterruptedException {
+        while (helpers.isEmpty()) {
+            wait();
+        }
+        return (RepositoryHelper) helpers.remove(0);
+    }
+
+    public synchronized void returnHelper(RepositoryHelper helper) {
+        helpers.add(helper);
+        notifyAll();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryHelperPoolImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java
Sun Jul  5 14:22:01 2009
@@ -17,8 +17,12 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.RepositoryStub;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.Session;
 
 /**
  * Encapsulates the various properties that are needed for a serialization test
@@ -32,6 +36,13 @@
     public String sourceFolderName;
     public String targetFolderName;
     public String rootNodeName;
+    public String nodeName1;
+    public String nodeName2;
+    public String nodeName3;
+    public String testNodeType;
+    public String propertyName1;
+    public String jcrPrimaryType;
+    public String mixReferenceable;
 
     public String propertyValueMayChange;
     public String propertySkipped;
@@ -58,7 +69,8 @@
     public String referenceTestProperty;
     public String multiValueTestProperty;
 
-    public SerializationContext(AbstractJCRTest test) throws RepositoryException {
+    public SerializationContext(AbstractJCRTest test, Session session)
+            throws RepositoryException {
         // creates a serialization context based on a test class
         baseTest = test;
 
@@ -67,6 +79,13 @@
         sourceFolderName = get("sourceFolderName");
         targetFolderName = get("targetFolderName");
         rootNodeName = get("rootNodeName");
+        nodeName1 = get(RepositoryStub.PROP_NODE_NAME1);
+        nodeName2 = get(RepositoryStub.PROP_NODE_NAME2);
+        nodeName3 = get(RepositoryStub.PROP_NODE_NAME3);
+        testNodeType = get(RepositoryStub.PROP_NODETYPE);
+        propertyName1 = get(RepositoryStub.PROP_PROP_NAME1);
+        jcrPrimaryType = session.getNamespacePrefix(AbstractJCRTest.NS_JCR_URI) + ":primaryType";
+        mixReferenceable = session.getNamespacePrefix(AbstractJCRTest.NS_MIX_URI) + ":referenceable";
 
         propertyValueMayChange = " " + get("propertyValueMayChange") + " ";
         propertySkipped = " " + get("propertySkipped") + " ";
@@ -101,4 +120,28 @@
         return value;
     }
 
+    public void log(String message) {
+        baseTest.log.println(message);
+    }
+
+    /**
+     * Ensures that the given <code>node</code> is of the given mixin type.
+     *
+     * @param node  a node.
+     * @param mixin the name of a mixin type.
+     * @throws NotExecutableException if the node is not of type mixin and the
+     *                                mixin cannot be added.
+     * @throws RepositoryException    if an error occurs.
+     */
+    protected void ensureMixinType(Node node, String mixin)
+            throws NotExecutableException, RepositoryException {
+        if (!node.isNodeType(mixin)) {
+            if (node.canAddMixin(mixin)) {
+                node.addMixin(mixin);
+            } else {
+                throw new NotExecutableException(node.getPath() +
+                        " does not support adding " + mixin);
+            }
+        }
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
Sun Jul  5 14:22:01 2009
@@ -81,7 +81,7 @@
             file = File.createTempFile("serializationTest", ".xml");
             log.print("Tempfile: " + file.getAbsolutePath());
 
-            SerializationContext sc = new SerializationContext(this);
+            SerializationContext sc = new SerializationContext(this, session);
             treeComparator = new TreeComparator(sc, session);
             treeComparator.createComplexTree(treeComparator.WORKSPACE);
         }
@@ -103,9 +103,6 @@
             session.logout();
             session = null;
         }
-        if (treeComparator != null) {
-            treeComparator.tearDown();
-        }
         workspace = null;
         super.tearDown();
     }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TreeComparator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TreeComparator.java?rev=791253&r1=791252&r2=791253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TreeComparator.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TreeComparator.java
Sun Jul  5 14:22:01 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.test.api;
 
-import org.apache.jackrabbit.test.AbstractJCRTest;
-
 import javax.jcr.Session;
 import javax.jcr.Workspace;
 import javax.jcr.Item;
@@ -35,6 +33,8 @@
 import java.util.Calendar;
 import java.io.ByteArrayInputStream;
 
+import junit.framework.Assert;
+
 /**
  * <code>TreeComparator</code> compares two trees. This allows re-use for
  * different tests, and it allows to test a function on any tree, not just a
@@ -43,7 +43,8 @@
  * TreeComparator also creates an example tree that contains as many features as
  * possible.
  */
-class TreeComparator extends AbstractJCRTest {
+class TreeComparator extends Assert {
+
     public SerializationContext sc;
 
     public final boolean WORKSPACE = true;
@@ -64,18 +65,11 @@
 
     public TreeComparator(SerializationContext sc, Session s) throws Exception {
         this.sc = sc;
-        setUp();
         session = s;
         workspace = session.getWorkspace();
         init();
     }
 
-    public void tearDown() throws Exception {
-        session = null;
-        workspace = null;
-        super.tearDown();
-    }
-
     public void setSession(Session session) {
         this.session = session;
     }
@@ -132,13 +126,13 @@
         try {
             Node src = (Node) session.getItem(sourceFolder);
             Node root = src.addNode(sc.rootNodeName);
-            root.addNode(nodeName1);
-            root.addNode(nodeName2, testNodeType);
+            root.addNode(sc.nodeName1);
+            root.addNode(sc.nodeName2, sc.testNodeType);
             byte[] byteArray = {(byte) 0, (byte) 255, (byte) 167, (byte) 100, (byte) 21,
(byte) 6, (byte) 19, (byte) 71, (byte) 221};
-            root.setProperty(propertyName1, new ByteArrayInputStream(byteArray));
-            root.setProperty(nodeName3, "hello");
+            root.setProperty(sc.propertyName1, new ByteArrayInputStream(byteArray));
+            root.setProperty(sc.nodeName3, "hello");
         } catch (Exception e) {
-            log.println("Error while creating example tree: " + e.getMessage());
+            sc.log("Error while creating example tree: " + e.getMessage());
         }
         if (save) {
             try {
@@ -181,7 +175,7 @@
             rootNode.addNode(sc.orderChildrenTestNode);
             rootNode.addNode(sc.namespaceTestNode);
         } catch (RepositoryException e) {
-            log.println("Error while creating example tree: " + e.getMessage());
+            sc.log("Error while creating example tree: " + e.getMessage());
         }
 
         // Add nodes with mixin types
@@ -205,14 +199,14 @@
                 // try saving, because some exceptions are trown only at save time
                 session.save();
             } catch (RepositoryException e) {
-                log.println("Cannot create node with mixin node type: " + e);
+                sc.log("Cannot create node with mixin node type: " + e);
                 // if saving failed for a node, then remove it again (or else the next save
will fail on it)
                 try {
                     if (n != null) {
                         n.remove();
                     }
                 } catch (RepositoryException e1) {
-                    log.println("Could not remove node: " + e);
+                    sc.log("Could not remove node: " + e);
                 }
             }
         }
@@ -235,12 +229,12 @@
             // Boolean
             pt.setProperty(sc.booleanTestProperty, true);
             // Name
-            pt.setProperty(sc.nameTestProperty, superuser.getValueFactory().createValue(jcrPrimaryType,
PropertyType.NAME));
+            pt.setProperty(sc.nameTestProperty, session.getValueFactory().createValue(sc.jcrPrimaryType,
PropertyType.NAME));
             // Path
-            pt.setProperty(sc.pathTestProperty, superuser.getValueFactory().createValue("paths/dont/have/to/point/anywhere",
PropertyType.PATH));
+            pt.setProperty(sc.pathTestProperty, session.getValueFactory().createValue("paths/dont/have/to/point/anywhere",
PropertyType.PATH));
             // Reference: Note that I only check if the node exists. We do not specify what
happens with
             // the UUID during serialization.
-            ensureMixinType(referenceable, mixReferenceable);
+            sc.ensureMixinType(referenceable, sc.mixReferenceable);
             // some implementations may require a save after addMixin()
             session.save();
 
@@ -259,7 +253,7 @@
             mvp.setProperty(sc.multiValueTestProperty, s);
             session.save();
         } catch (RepositoryException e) {
-            log.println("Could not create multi-value property: " + e);
+            sc.log("Could not create multi-value property: " + e);
         }
 
         // Save to the workspace. Note that export is from session anyway.
@@ -372,7 +366,7 @@
      */
     public void compareNodes(Node a, Node b) {
         try {
-            log.println("Comparing " + a.getPath() + " to " + b.getPath());
+            sc.log("Comparing " + a.getPath() + " to " + b.getPath());
         } catch (RepositoryException e) {
             fail("Nodes not available: " + e.getMessage());
         }
@@ -380,8 +374,8 @@
         // check primary node type
         String primaryTypeA = null, primaryTypeB = null;
         try {
-            primaryTypeA = a.getProperty(jcrPrimaryType).getName();
-            primaryTypeB = b.getProperty(jcrPrimaryType).getName();
+            primaryTypeA = a.getProperty(sc.jcrPrimaryType).getName();
+            primaryTypeB = b.getProperty(sc.jcrPrimaryType).getName();
         } catch (RepositoryException e) {
             fail("Primary node type not available: " + e);
         }
@@ -563,7 +557,7 @@
             n = (Node) session.getItem(sc.testroot);
             showTree(n, 0);
         } catch (RepositoryException e) {
-            log.println("Cannot display tree diagnostics: " + e);
+            sc.log("Cannot display tree diagnostics: " + e);
         }
     }
 
@@ -571,17 +565,19 @@
      * Recursive display of source and target tree
      */
     public void showTree(Node n, int level) throws RepositoryException {
+        StringBuffer sb = new StringBuffer();
         for (int t = 0; t < level; t++) {
-            log.print("-");
+            sb.append("-");
         }
-        log.print(n.getName() + " ");
-        log.print(n.getPrimaryNodeType().getName() + " [ ");
+        sb.append(n.getName() + " ");
+        sb.append(n.getPrimaryNodeType().getName() + " [ ");
         PropertyIterator pi = n.getProperties();
         while (pi.hasNext()) {
             Property p = (Property) pi.next();
-            log.print(p.getName() + " ");
+            sb.append(p.getName() + " ");
         }
-        log.println("]");
+        sb.append("]");
+        sc.log(sb.toString());
 
         NodeIterator ni = n.getNodes();
         while (ni.hasNext()) {



Mime
View raw message