jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1173551 - in /jackrabbit/sandbox/microkernel: ./ src/test/java/org/apache/jackrabbit/mk/ src/test/java/org/apache/jackrabbit/mk/blobs/ src/test/java/org/apache/jackrabbit/mk/concurrent/ src/test/java/org/apache/jackrabbit/mk/fs/ src/test/j...
Date Wed, 21 Sep 2011 10:01:36 GMT
Author: thomasm
Date: Wed Sep 21 10:01:36 2011
New Revision: 1173551

URL: http://svn.apache.org/viewvc?rev=1173551&view=rev
Log:
Improved tests

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
Modified:
    jackrabbit/sandbox/microkernel/pom.xml
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/fs/TestFileSystem.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/LargeNodeTest.java

Modified: jackrabbit/sandbox/microkernel/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/pom.xml?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/pom.xml (original)
+++ jackrabbit/sandbox/microkernel/pom.xml Wed Sep 21 10:01:36 2011
@@ -28,6 +28,9 @@
     <version>0.1-SNAPSHOT</version>
     <name>MicroKernel</name>
     <description>Hierarchical MVCC-based persistence store</description>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
 
     <dependencies>
         <dependency>
@@ -74,17 +77,17 @@
             -->
             <plugin>
                 <groupId>org.pitest</groupId>
-                <artifactId>pitest-maven</artifactId>
-                <version>0.20</version>
-                <configuration>
-                    <inScopeClasses>
-                        <param>org.apache.jackrabbit.mk.util.Path*</param>
-                    </inScopeClasses>
-                    <targetClasses>
-                        <param>org.apache.jackrabbit.mk.util.Path*</param>
-                    </targetClasses>
-                </configuration>
-            </plugin>
+                    <artifactId>pitest-maven</artifactId>
+                    <version>0.23</version>
+                    <configuration>
+                        <inScopeClasses>
+                            <param>org.apache.jackrabbit.mk.index.*</param>
+                        </inScopeClasses>
+                        <targetClasses>
+                            <param>org.apache.jackrabbit.mk.index.*</param>
+                        </targetClasses>
+                    </configuration>
+                </plugin>
         </plugins>
     </build>
     

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java Wed Sep 21 10:01:36 2011
@@ -16,11 +16,10 @@
  */
 package org.apache.jackrabbit.mk;
 
+import java.util.Random;
 import junit.framework.TestCase;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 
-import java.util.Random;
-
 public class ConcurrentWriteTest extends TestCase {
 
     protected static final String TEST_PATH = "/" + ConcurrentWriteTest.class.getName();

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java Wed Sep 21 10:01:36 2011
@@ -16,34 +16,27 @@
  */
 package org.apache.jackrabbit.mk;
 
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test large node, property, and values (longer than 65 KB).
  */
-public class LargeObjectTest extends TestCase {
-
-    // private static final String URL = "fs:{homeDir}/target;clean";
-    // private static final String URL = "mem:";
-    private static final String URL = "mem:fs:target/temp;clean";
+@RunWith(Parameterized.class)
+public class LargeObjectTest extends MultiMkTestBase {
 
     private static final String TEST_PATH = "/" + LargeObjectTest.class.getName();
 
-    private MicroKernel mk;
-
-    public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(URL);
-        mk.commit("/", "+ \"" + TEST_PATH.substring(1) + "\": {}", mk.getHeadRevision(), null);
-    }
-
-    public void tearDown() throws InterruptedException {
-        mk.commit("/", "- \"" + TEST_PATH.substring(1) + "\"", mk.getHeadRevision(), null);
-        mk.dispose();
+    public LargeObjectTest(String url) {
+        super(url);
     }
 
+    @Test
     public void test() {
 
+        mk.commit("/", "+ \"" + TEST_PATH.substring(1) + "\": {}", mk.getHeadRevision(), null);
+
         String head = mk.getHeadRevision();
         head = mk.commit(TEST_PATH, "+ \"test\": { \"data\": \"Hello World\" }", head, null);
 
@@ -56,6 +49,8 @@ public class LargeObjectTest extends Tes
         head = mk.commit(TEST_PATH, "+ \"" + large + "\": { \"" + large + "\": \"Hello World\" }", head, null);
         head = mk.commit(TEST_PATH, "^ \"" + large + "/" + large + "\": \"" + large + "\"", head, null);
 
+        mk.commit("/", "- \"" + TEST_PATH.substring(1) + "\"", mk.getHeadRevision(), null);
+
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java Wed Sep 21 10:01:36 2011
@@ -16,159 +16,195 @@
  */
 package org.apache.jackrabbit.mk;
 
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.api.MicroKernel;
+import junit.framework.Assert;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test moving nodes.
  */
-public class MoveNodeTest extends TestCase {
-
-    // private static final String URL = "fs:{homeDir};clean";
-    // private static final String URL = "mem:;clean";
-    private static final String URL = "mem:fs:target/temp;clean";
-
-    private MicroKernel mk;
+@RunWith(Parameterized.class)
+public class MoveNodeTest extends MultiMkTestBase {
 
     private String head;
     private String journalRevision;
 
+    public MoveNodeTest(String url) {
+        super(url);
+    }
+
+    @Before
     public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(URL);
+        super.setUp();
         head = mk.getHeadRevision();
         commit("/", "+ \"test\": {\"a\":{}, \"b\":{}, \"c\":{}}");
         commit("/", "+ \"test2\": {}");
         getJournal();
     }
 
-    public void tearDown() throws InterruptedException {
-        mk.dispose();
+    @Test
+    public void order() {
+        Assert.assertEquals("{a,b,c}", getNode("/test"));
     }
 
-    public void testOrder() {
-        assertEquals("{a,b,c}", getNode("/test"));
-    }
+    @Test
+    public void rename() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
 
-    public void testRename() {
         // rename /test/b
         commit("/", "> \"test/b\": \"test/b1\"");
-        assertEquals("{a,b1,c}", getNode("/test"));
+        Assert.assertEquals("{a,b1,c}", getNode("/test"));
         assertJournal("> \"/test/b\":\"/test/b1\"");
         // and back
         commit("/", "> \"test/b1\": \"test/b\"");
-        assertEquals("{a,b,c}", getNode("/test"));
+        Assert.assertEquals("{a,b,c}", getNode("/test"));
         assertJournal("> \"/test/b1\":\"/test/b\"");
     }
 
-    public void testReorderBefore() {
+    @Test
+    public void reorderBefore() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
+
         // order c before b
         commit("/", "> \"test/c\": {\"before\": \"test/b\"}");
-        assertEquals("{a,c,b}", getNode("/test"));
+        Assert.assertEquals("{a,c,b}", getNode("/test"));
         assertJournal("> \"/test/c\":{\"before\":\"/test/b\"}");
 
         // and now b before a
         commit("/", "> \"test/b\": {\"before\": \"test/a\"}");
-        assertEquals("{b,a,c}", getNode("/test"));
+        Assert.assertEquals("{b,a,c}", getNode("/test"));
         assertJournal("> \"/test/b\":{\"before\":\"/test/a\"}");
     }
 
-    public void testReorderAfter() {
+    @Test
+    public void reorderAfter() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
+
         // order a after b
         commit("/", "> \"test/a\": {\"after\": \"test/b\"}");
-        assertEquals("{b,a,c}", getNode("/test"));
+        Assert.assertEquals("{b,a,c}", getNode("/test"));
         assertJournal("> \"/test/a\":{\"after\":\"/test/b\"}");
 
         // and now a after c
         commit("/", "> \"test/a\": {\"after\": \"test/c\"}");
-        assertEquals("{b,c,a}", getNode("/test"));
+        Assert.assertEquals("{b,c,a}", getNode("/test"));
         assertJournal("> \"/test/a\":{\"after\":\"/test/c\"}");
 
         // and now a after a (a no-op)
         commit("/", "> \"test/a\": {\"after\": \"test/a\"}");
-        assertEquals("{b,c,a}", getNode("/test"));
+        Assert.assertEquals("{b,c,a}", getNode("/test"));
         assertJournal("> \"/test/a\":{\"after\":\"/test/a\"}");
     }
 
-    public void testMoveFirst() {
+    @Test
+    public void moveFirst() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
+
         // move /test/a to /test2/a (rename is not supported in this way)
         commit("/", "> \"test/a\": {\"first\": \"test2\"}");
-        assertEquals("{b,c}", getNode("/test"));
-        assertEquals("{a}", getNode("/test2"));
+        Assert.assertEquals("{b,c}", getNode("/test"));
+        Assert.assertEquals("{a}", getNode("/test2"));
         assertJournal("> \"/test/a\":{\"first\":\"/test2\"}");
 
         // move /test/c to /test2
         commit("/", "> \"test/c\": {\"first\": \"test2\"}");
-        assertEquals("{b}", getNode("/test"));
-        assertEquals("{c,a}", getNode("/test2"));
+        Assert.assertEquals("{b}", getNode("/test"));
+        Assert.assertEquals("{c,a}", getNode("/test2"));
         assertJournal("> \"/test/c\":{\"first\":\"/test2\"}");
     }
 
-    public void testMoveBefore() {
+    @Test
+    public void moveBefore() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
+
         // move /test/b to /test2/b, before any other nodes in /test2
         commit("/", "> \"test/b\": {\"first\": \"test2\"}");
-        assertEquals("{a,c}", getNode("/test"));
-        assertEquals("{b}", getNode("/test2"));
+        Assert.assertEquals("{a,c}", getNode("/test"));
+        Assert.assertEquals("{b}", getNode("/test2"));
         assertJournal("> \"/test/b\":{\"first\":\"/test2\"}");
 
         // move /test/c to /test2, before b
         commit("/", "> \"test/c\": {\"before\": \"test2/b\"}");
-        assertEquals("{a}", getNode("/test"));
-        assertEquals("{c,b}", getNode("/test2"));
+        Assert.assertEquals("{a}", getNode("/test"));
+        Assert.assertEquals("{c,b}", getNode("/test2"));
         assertJournal("> \"/test/c\":{\"before\":\"/test2/b\"}");
     }
 
-    public void testMoveAfter() {
+    @Test
+    public void moveAfter() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
+
         // move /test/c to /test2
         commit("/", "> \"test/c\": \"test2/c\"");
-        assertEquals("{a,b}", getNode("/test"));
-        assertEquals("{c}", getNode("/test2"));
+        Assert.assertEquals("{a,b}", getNode("/test"));
+        Assert.assertEquals("{c}", getNode("/test2"));
         assertJournal("> \"/test/c\":\"/test2/c\"");
 
         // move /test/a to /test2, after c
         commit("/", "> \"test/a\": {\"after\": \"test2/c\"}");
-        assertEquals("{b}", getNode("/test"));
-        assertEquals("{c,a}", getNode("/test2"));
+        Assert.assertEquals("{b}", getNode("/test"));
+        Assert.assertEquals("{c,a}", getNode("/test2"));
         assertJournal("> \"/test/a\":{\"after\":\"/test2/c\"}");
 
         // move /test/b to /test2, after c
         commit("/", "> \"test/b\": {\"after\": \"test2/c\"}");
-        assertEquals("{}", getNode("/test"));
-        assertEquals("{c,b,a}", getNode("/test2"));
+        Assert.assertEquals("{}", getNode("/test"));
+        Assert.assertEquals("{c,b,a}", getNode("/test2"));
         assertJournal("> \"/test/b\":{\"after\":\"/test2/c\"}");
     }
 
-    public void testMoveLast() {
+    @Test
+    public void moveLast() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
+
         // move /test/a to /test2, as last
         commit("/", "> \"test/b\": {\"last\": \"test2\"}");
-        assertEquals("{a,c}", getNode("/test"));
-        assertEquals("{b}", getNode("/test2"));
+        Assert.assertEquals("{a,c}", getNode("/test"));
+        Assert.assertEquals("{b}", getNode("/test2"));
         assertJournal("> \"/test/b\":{\"last\":\"/test2\"}");
 
         // move /test/c to /test2, as last
         commit("/", "> \"test/c\": {\"last\": \"test2\"}");
-        assertEquals("{a}", getNode("/test"));
-        assertEquals("{b,c}", getNode("/test2"));
+        Assert.assertEquals("{a}", getNode("/test"));
+        Assert.assertEquals("{b,c}", getNode("/test2"));
         assertJournal("> \"/test/c\":{\"last\":\"/test2\"}");
     }
 
-    public void testMove() {
+    @Test
+    public void move() {
         // move /test/b to /test2
         commit("/", "> \"test/b\": \"/test2/b\"");
-        assertEquals("{a,c}", getNode("/test"));
-        assertEquals("{b}", getNode("/test2"));
+        Assert.assertEquals("{a,c}", getNode("/test"));
+        Assert.assertEquals("{b}", getNode("/test2"));
         assertJournal("> \"/test/b\":\"/test2/b\"");
 
         // move /test/a to /test2
         commit("/", "> \"test/a\": \"test2/a1\"");
-        assertEquals("{c}", getNode("/test"));
-        assertEquals("{b,a1}", getNode("/test2"));
+        Assert.assertEquals("{c}", getNode("/test"));
+        Assert.assertEquals("{b,a1}", getNode("/test2"));
         assertJournal("> \"/test/a\":\"/test2/a1\"");
 
         // move /test/c to /test2
         commit("/", "> \"test/c\": \"test2/c\"");
-        assertEquals("{}", getNode("/test"));
-        assertEquals("{b,a1,c}", getNode("/test2"));
+        Assert.assertEquals("{}", getNode("/test"));
+        Assert.assertEquals("{b,a1,c}", getNode("/test2"));
         assertJournal("> \"/test/c\":\"/test2/c\"");
     }
 
@@ -185,7 +221,7 @@ public class MoveNodeTest extends TestCa
     }
 
     private void assertJournal(String expectedJournal) {
-        assertEquals(expectedJournal, getJournal());
+        Assert.assertEquals(expectedJournal, getJournal());
     }
 
     private String getJournal() {
@@ -195,11 +231,11 @@ public class MoveNodeTest extends TestCa
             t.read('[');
             do {
                 t.read('{');
-                assertEquals("id", t.readString());
+                Assert.assertEquals("id", t.readString());
                 t.read(':');
                 journalRevision = t.readString();
                 t.read(',');
-                assertEquals("ts", t.readString());
+                Assert.assertEquals("ts", t.readString());
                 t.read(':');
                 t.read(JsopTokenizer.NUMBER);
                 t.read('}');
@@ -213,19 +249,19 @@ public class MoveNodeTest extends TestCa
         boolean isNew = false;
         do {
             t.read('{');
-            assertEquals("id", t.readString());
+            Assert.assertEquals("id", t.readString());
             t.read(':');
             t.readString();
             t.read(',');
-            assertEquals("ts", t.readString());
+            Assert.assertEquals("ts", t.readString());
             t.read(':');
             t.read(JsopTokenizer.NUMBER);
             t.read(',');
-            assertEquals("msg", t.readString());
+            Assert.assertEquals("msg", t.readString());
             t.read(':');
             t.read();
             t.read(',');
-            assertEquals("changes", t.readString());
+            Assert.assertEquals("changes", t.readString());
             t.read(':');
             String changes = t.readString().trim();
             if (isNew) {

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java?rev=1173551&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java (added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java Wed Sep 21 10:01:36 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.mk;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runners.Parameterized.Parameters;
+
+public class MultiMkTestBase {
+
+    public MicroKernel mk;
+    protected String url;
+
+    public MultiMkTestBase(String url) {
+        this.url = url;
+    }
+
+    @Parameters
+    public static Collection<Object[]> urls() {
+            return Arrays.asList(new Object[][]{
+                    {"fs:{homeDir}/target"},
+                    {"mem:"},
+                    {"mem:fs:target/temp"}});
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        mk = MicroKernelFactory.getInstance(url + ";clean");
+    }
+
+    @After
+    public void tearDown() throws InterruptedException {
+        mk.dispose();
+    }
+
+    protected void reconnect() {
+        if (!url.startsWith("mem:")) {
+            mk.dispose();
+            mk = MicroKernelFactory.getInstance(url);
+        }
+    }
+
+}

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java Wed Sep 21 10:01:36 2011
@@ -16,45 +16,40 @@
  */
 package org.apache.jackrabbit.mk.blobs;
 
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Random;
+import junit.framework.Assert;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test the data store using the MicroKernel API.
  */
-public class DataStoreTest extends TestCase {
-
-    // private static final String URL = "fs:{homeDir}/target;clean";
-    private static final String URL = "mem:fs:target/temp;clean";
-    // private static final String URL = "mem:";
-
-    private MicroKernel mk;
-
-    public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(URL);
-    }
+@RunWith(Parameterized.class)
+public class DataStoreTest extends MultiMkTestBase {
 
-    public void tearDown() throws InterruptedException {
-        mk.dispose();
+    public DataStoreTest(String url) {
+        super(url);
     }
 
-    public void testSmall() throws IOException {
+    @Test
+    public void small() throws IOException {
         doTest(10, 10);
     }
 
-    public void testMedium() throws IOException {
+    @Test
+    public void medium() throws IOException {
         doTest(1000, 10);
     }
 
-    public void testLarge() throws IOException {
+    @Test
+    public void large() throws IOException {
         doTest(1000000, 1);
     }
 
@@ -73,7 +68,7 @@ public class DataStoreTest extends TestC
             int len = count == 1 ? maxLength : r.nextInt(maxLength);
             byte[] expectedData = new byte[len];
             r.nextBytes(expectedData);
-            assertEquals(len, mk.getLength(s[i++]));
+            Assert.assertEquals(len, mk.getLength(s[i++]));
 
             String id = s[i++];
             doTestReadFully(expectedData, len, id);
@@ -87,10 +82,10 @@ public class DataStoreTest extends TestC
     }
 
     private void assertByteArrayEquals(byte[] expected, int expectedLen, byte[] got) {
-        assertEquals(expectedLen, got.length);
+        Assert.assertEquals(expectedLen, got.length);
         for (int j = 0; j < expectedLen; j++) {
             if (expected[j] != got[j]) {
-                assertEquals("j:" + j, expected[j], got[j]);
+                Assert.assertEquals("j:" + j, expected[j], got[j]);
             }
         }
     }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentBlobTest.java Wed Sep 21 10:01:36 2011
@@ -18,42 +18,47 @@ package org.apache.jackrabbit.mk.concurr
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+import junit.framework.Assert;
 import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
+import org.apache.jackrabbit.mk.util.Concurrent;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.IOUtilsTest;
+import org.apache.jackrabbit.mk.util.Concurrent.Task;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Test concurrent access to the blob store.
  */
-public class ConcurrentBlobTest extends ConcurrentTest {
+public class ConcurrentBlobTest {
 
-    private static final byte[] EMPTY = new byte[50];
+    static final byte[] EMPTY = new byte[50];
 
     MemoryBlobStore store = new MemoryBlobStore();
 
+    @Before
     public void setUp() throws Exception {
         store.setBlockSizeMin(50);
     }
 
-    public void tearDown() throws InterruptedException {
-        // ignore
-    }
-
-    void access() {
-        try {
-            int i = id.getAndIncrement();
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            IOUtils.writeLong(out, i);
-            out.write(EMPTY);
-            byte[] data = out.toByteArray();
-            String id = store.writeBlob(new ByteArrayInputStream(data));
-            assertEquals(58, store.getBlobLength(id));
-            byte[] test = out.toByteArray();
-            assertEquals(8, store.readBlob(id, 0, test, 0, 8));
-            IOUtilsTest.assertEquals(data, test);
-        } catch (Throwable t) {
-            lastException = new Exception(t);
-        }
+    @Test
+    public void test() throws Exception {
+        final AtomicInteger id = new AtomicInteger();
+        Concurrent.run(new Task() {
+            public void call() throws Exception {
+                int i = id.getAndIncrement();
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                IOUtils.writeLong(out, i);
+                out.write(EMPTY);
+                byte[] data = out.toByteArray();
+                String id = store.writeBlob(new ByteArrayInputStream(data));
+                Assert.assertEquals(58, store.getBlobLength(id));
+                byte[] test = out.toByteArray();
+                Assert.assertEquals(8, store.readBlob(id, 0, test, 0, 8));
+                IOUtilsTest.assertEquals(data, test);
+            }
+        });
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentCacheTest.java Wed Sep 21 10:01:36 2011
@@ -17,33 +17,30 @@
 package org.apache.jackrabbit.mk.concurrent;
 
 import java.util.concurrent.atomic.AtomicInteger;
+import junit.framework.Assert;
 import org.apache.jackrabbit.mk.util.Cache;
+import org.apache.jackrabbit.mk.util.Concurrent;
+import org.apache.jackrabbit.mk.util.Concurrent.Task;
+import org.junit.Test;
 
 /**
  * Tests the cache implementation.
  */
-public class ConcurrentCacheTest extends ConcurrentTest implements Cache.Backend<Integer, ConcurrentCacheTest.Data> {
+public class ConcurrentCacheTest implements Cache.Backend<Integer, ConcurrentCacheTest.Data> {
 
     Cache<Integer, Data> cache = Cache.newInstance(this, 5);
     AtomicInteger counter = new AtomicInteger();
     volatile int value;
 
-    public void setUp() throws Exception {
-        // nothing to do
-    }
-
-    public void tearDown() throws InterruptedException {
-        // nothing to do
-    }
-
-    void access() {
-        try {
-            int k = value++ % 10;
-            Data v = cache.get(k);
-            assertEquals(k, v.value);
-        } catch (Throwable t) {
-            lastException = new Exception(t);
-        }
+    @Test
+    public void test() throws Exception {
+        Concurrent.run(new Task() {
+            public void call() throws Exception {
+                int k = value++ % 10;
+                Data v = cache.get(k);
+                Assert.assertEquals(k, v.value);
+            }
+        });
     }
 
     public Data load(Integer key) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/concurrent/ConcurrentTest.java Wed Sep 21 10:01:36 2011
@@ -1,92 +1,59 @@
 /*
  * 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.
+ * 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.mk.concurrent;
 
 import java.util.concurrent.atomic.AtomicInteger;
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
+import junit.framework.Assert;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.apache.jackrabbit.mk.util.Concurrent;
+import org.apache.jackrabbit.mk.util.Concurrent.Task;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test concurrent access to nodes, the journal, and revision.
  */
-public class ConcurrentTest extends TestCase {
+@RunWith(Parameterized.class)
+public class ConcurrentTest extends MultiMkTestBase {
 
-    // private static final String URL = "fs:{homeDir}/target;clean";
-    private static final String URL = "mem:";
-    // private static final String URL = "mem:fs:target/temp;clean";
-
-    protected MicroKernel mk;
-    protected AtomicInteger id = new AtomicInteger();
-    protected Exception lastException;
-    boolean stop;
-
-    public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(URL);
-    }
-
-    public void tearDown() throws InterruptedException {
-        mk.dispose();
+    public ConcurrentTest(String url) {
+        super(url);
     }
 
+    @Test
     public void test() throws Exception {
-        Thread t = new Thread("Test") {
-            public void run() {
-                while (!stop) {
-                    access();
-                }
+        final AtomicInteger id = new AtomicInteger();
+        Concurrent.run(new Task() {
+            public void call() throws Exception {
+                long start = System.currentTimeMillis();
+                String rev = mk.getHeadRevision();
+                int i = id.getAndIncrement();
+                String newRev = mk.commit("/", "+\"" + i + "\":{\"x\": " + i + "}", rev, "");
+                Assert.assertTrue(!newRev.equals(rev));
+                mk.getJournal(rev, newRev);
+                mk.getRevisions(start, 100);
+                mk.getNodes("/" + i, newRev);
+                mk.getNodes("/" + i, newRev, 0, 0, 0);
+                Assert.assertFalse(mk.nodeExists("/" + i, rev));
+                Assert.assertTrue(mk.nodeExists("/" + i, newRev));
+                rev = newRev;
+                newRev = mk.commit("/", "-\"" + i + "\"", rev, "");
+                Assert.assertTrue(mk.nodeExists("/" + i, rev));
+                Assert.assertFalse(mk.nodeExists("/" + i, newRev));
             }
-        };
-        t.start();
-        long start = System.currentTimeMillis();
-        for (int i = 0; i < 100000; i++) {
-            if (i % 100 == 0 && System.currentTimeMillis() - start > 1000) {
-                break;
-            }
-            access();
-        }
-        stop = true;
-        t.join();
-        if (lastException != null) {
-            throw lastException;
-        }
-
-    }
-
-    void access() {
-        try {
-            long start = System.currentTimeMillis();
-            String rev = mk.getHeadRevision();
-            int i = id.getAndIncrement();
-            String newRev = mk.commit("/", "+\"" + i + "\":{\"x\": " + i + "}", rev, "");
-            assertTrue(!newRev.equals(rev));
-            mk.getJournal(rev, newRev);
-            mk.getRevisions(start, 100);
-            mk.getNodes("/" + i, newRev);
-            mk.getNodes("/" + i, newRev, 0, 0, 0);
-            assertFalse(mk.nodeExists("/" + i, rev));
-            assertTrue(mk.nodeExists("/" + i, newRev));
-            rev = newRev;
-            newRev = mk.commit("/", "-\"" + i + "\"", rev, "");
-            assertTrue(mk.nodeExists("/" + i, rev));
-            assertFalse(mk.nodeExists("/" + i, newRev));
-        } catch (Throwable t) {
-            lastException = new Exception(t);
-        }
+        });
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/fs/TestFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/fs/TestFileSystem.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/fs/TestFileSystem.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/fs/TestFileSystem.java Wed Sep 21 10:01:36 2011
@@ -169,13 +169,11 @@ public class TestFileSystem extends Test
 
         assertTrue(FileUtils.tryDelete(fsBase + "/test2"));
         FileUtils.delete(fsBase + "/test");
-        if (fsBase.indexOf("memFS:") < 0 && fsBase.indexOf("memLZF:") < 0) {
-            FileUtils.createDirectories(fsBase + "/testDir");
-            assertTrue(FileUtils.isDirectory(fsBase + "/testDir"));
-            if (!fsBase.startsWith("jdbc:")) {
-                FileUtils.deleteRecursive(fsBase + "/testDir", false);
-                assertTrue(!FileUtils.exists(fsBase + "/testDir"));
-            }
+        FileUtils.createDirectories(fsBase + "/testDir");
+        assertTrue(FileUtils.isDirectory(fsBase + "/testDir"));
+        if (!fsBase.startsWith("jdbc:")) {
+            FileUtils.deleteRecursive(fsBase + "/testDir", false);
+            assertTrue(!FileUtils.exists(fsBase + "/testDir"));
         }
     }
 

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java Wed Sep 21 10:01:36 2011
@@ -16,36 +16,30 @@
  */
 package org.apache.jackrabbit.mk.index;
 
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.json.JsopTest;
-
 import java.util.Iterator;
 import java.util.Random;
 import java.util.TreeMap;
+import junit.framework.Assert;
+import org.apache.jackrabbit.mk.MicroKernelFactory;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.json.JsopTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Tests the indexing mechanism.
  */
-public class IndexTest extends TestCase {
+@RunWith(Parameterized.class)
+public class IndexTest extends MultiMkTestBase {
 
-    // private static final String URL = "fs:{homeDir}/target;clean";
-    // private static final String URL = "mem:fs:target/temp;clean";
-    private static final String URL = "mem:;clean";
-
-    public void test() {
-        testCreateIndexAfterAddingData(URL);
-        testNonUnique(URL);
-        testAscending(URL);
-        testRandom(URL);
-        testDuplicateKey(URL, true);
-        testDuplicateKey(URL, false);
-        testNestedAddNode(URL);
+    public IndexTest(String url) {
+        super(url);
     }
 
-    private void testCreateIndexAfterAddingData(String url) {
-        MicroKernel mk = MicroKernelFactory.getInstance(url);
+    @Test
+    public void createIndexAfterAddingData() {
         Indexer indexer = new Indexer(mk);
         PropertyIndex indexOld = indexer.createPropertyIndex("x", false);
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 1 }, \"id\": 1 }", mk.getHeadRevision(), "");
@@ -53,41 +47,38 @@ public class IndexTest extends TestCase 
         indexOld.getPath("x", mk.getHeadRevision());
         PropertyIndex index = indexer.createPropertyIndex("id", false);
         Iterator<String> it = index.getPaths("1", mk.getHeadRevision());
-        assertTrue(it.hasNext());
-        assertEquals("/test", it.next());
-        assertTrue(it.hasNext());
-        assertEquals("/test/test2", it.next());
-        assertFalse(it.hasNext());
-        mk.dispose();
+        Assert.assertTrue(it.hasNext());
+        Assert.assertEquals("/test", it.next());
+        Assert.assertTrue(it.hasNext());
+        Assert.assertEquals("/test/test2", it.next());
+        Assert.assertFalse(it.hasNext());
     }
 
-    private void testNonUnique(String url) {
-        MicroKernel mk = MicroKernelFactory.getInstance(url);
+    @Test
+    public void nonUnique() {
         Indexer indexer = new Indexer(mk);
         PropertyIndex index = indexer.createPropertyIndex("id", false);
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 1 }, \"id\": 1 }", mk.getHeadRevision(), "");
         mk.commit("/", "+ \"test3\": { \"test2\": { \"id\": 2 }, \"id\": 2 }", mk.getHeadRevision(), "");
         Iterator<String> it = index.getPaths("1", mk.getHeadRevision());
-        assertTrue(it.hasNext());
-        assertEquals("/test", it.next());
-        assertTrue(it.hasNext());
-        assertEquals("/test/test2", it.next());
-        assertFalse(it.hasNext());
-        mk.dispose();
+        Assert.assertTrue(it.hasNext());
+        Assert.assertEquals("/test", it.next());
+        Assert.assertTrue(it.hasNext());
+        Assert.assertEquals("/test/test2", it.next());
+        Assert.assertFalse(it.hasNext());
     }
 
-    private void testNestedAddNode(String url) {
-        MicroKernel mk = MicroKernelFactory.getInstance(url);
+    @Test
+    public void nestedAddNode() {
         Indexer indexer = new Indexer(mk);
         PropertyIndex index = indexer.createPropertyIndex("id", true);
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 2 }, \"id\": 1 }", mk.getHeadRevision(), "");
-        assertEquals("/test", index.getPath("1", mk.getHeadRevision()));
-        assertEquals("/test/test2", index.getPath("2", mk.getHeadRevision()));
-        mk.dispose();
+        Assert.assertEquals("/test", index.getPath("1", mk.getHeadRevision()));
+        Assert.assertEquals("/test/test2", index.getPath("2", mk.getHeadRevision()));
     }
 
-    private void testAscending(String url) {
-        MicroKernel mk = MicroKernelFactory.getInstance(url);
+    @Test
+    public void testAscending() {
         Indexer indexer = new Indexer(mk);
         BTree tree = new BTree(indexer, "test", true);
         tree.setMinSize(2);
@@ -102,24 +93,32 @@ public class IndexTest extends TestCase 
             // log("#test " + i);
             Cursor c = tree.findFirst("" + i);
             if (c.hasNext()) {
-                assertEquals("" + i, c.next());
+                Assert.assertEquals("" + i, c.next());
             }
         }
         print(mk, tree);
         for (int i = 0; i < len; i++) {
-            assertTrue("not found when removing " + i, tree.remove("" + i, null));
+            Assert.assertTrue("not found when removing " + i, tree.remove("" + i, null));
             // print(mk, index);
         }
         print(mk, tree);
         for (int i = 0; i < len; i++) {
             Cursor c = tree.findFirst("" + i);
-            assertFalse(c.hasNext());
+            Assert.assertFalse(c.hasNext());
         }
-        mk.dispose();
     }
 
-    private void testDuplicateKey(String url, boolean unique) {
-        MicroKernel mk = MicroKernelFactory.getInstance(url);
+    @Test
+    public void duplicateKeyUnique() {
+        duplicateKey(true);
+    }
+
+    @Test
+    public void duplicateKeyNonUnique() {
+        duplicateKey(false);
+    }
+
+    private void duplicateKey(boolean unique) {
         Indexer indexer = new Indexer(mk);
         BTree tree = new BTree(indexer, "test", unique);
         tree.setMinSize(2);
@@ -129,7 +128,7 @@ public class IndexTest extends TestCase 
         if (unique) {
             try {
                 tree.add("1", "p2");
-                fail();
+                Assert.fail();
             } catch (UnsupportedOperationException e) {
                 // expected
             }
@@ -139,30 +138,30 @@ public class IndexTest extends TestCase 
 
         // search
         Cursor c = tree.findFirst("1");
-        assertEquals("1", c.next());
-        assertEquals("p1", c.getValue());
+        Assert.assertEquals("1", c.next());
+        Assert.assertEquals("p1", c.getValue());
         if (unique) {
-            assertFalse(c.hasNext());
+            Assert.assertFalse(c.hasNext());
         } else {
-            assertEquals("1", c.next());
-            assertEquals("p2", c.getValue());
+            Assert.assertEquals("1", c.next());
+            Assert.assertEquals("p2", c.getValue());
         }
         try {
             c.remove();
-            fail();
+            Assert.fail();
         } catch (UnsupportedOperationException e) {
             // expected
         }
-        assertFalse(c.hasNext());
-        assertEquals(null, c.next());
+        Assert.assertFalse(c.hasNext());
+        Assert.assertEquals(null, c.next());
 
         // remove
         tree.remove("1", "p1");
 
-        mk.dispose();
     }
 
-    private void testRandom(String url) {
+    @Test
+    public void testRandom() {
         MicroKernel mk = MicroKernelFactory.getInstance(url);
         Indexer indexer = new Indexer(mk);
         BTree tree = new BTree(indexer, "test", true);
@@ -183,10 +182,10 @@ public class IndexTest extends TestCase 
                     gotExists = false;
                 }
             }
-            assertEquals("find " + x, exists, gotExists);
+            Assert.assertEquals("find " + x, exists, gotExists);
             if (exists) {
-                assertEquals("" + x, x2);
-                assertEquals(treeMap.get(x), c.getValue());
+                Assert.assertEquals("" + x, x2);
+                Assert.assertEquals(treeMap.get(x), c.getValue());
             }
             boolean add = r.nextBoolean();
             if (add) {
@@ -203,7 +202,6 @@ public class IndexTest extends TestCase 
                 }
             }
         }
-        mk.dispose();
     }
 
     static void log(String s) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java Wed Sep 21 10:01:36 2011
@@ -17,60 +17,57 @@
 package org.apache.jackrabbit.mk.index;
 
 import java.util.Iterator;
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
+import junit.framework.Assert;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test the prefix index.
  */
-public class PrefixIndexTest extends TestCase {
+@RunWith(Parameterized.class)
+public class PrefixIndexTest extends MultiMkTestBase {
 
-    // private static final String URL = "fs:{homeDir}/target";
-    // private static final String URL = "mem:fs:target/temp";
-    private static final String URL = "mem:";
-
-    public void test() {
-        test(URL);
+    public PrefixIndexTest(String url) {
+        super(url);
     }
 
-    private void test(String url) {
-        MicroKernel mk = MicroKernelFactory.getInstance(url + ";clean");
+    @Test
+    public void test() {
         Indexer indexer = new Indexer(mk);
         PrefixIndex index = indexer.createPrefixIndex("d:");
 
         String head = mk.getHeadRevision();
 
-        assertEquals("", getPathList(index, "d:1", head));
+        Assert.assertEquals("", getPathList(index, "d:1", head));
 
         head = mk.commit("/", "+\"test\" : {\"blob\":\"d:1\"}", head, null);
         head = mk.commit("/", "+\"test2\" : {\"blob2\":\"d:2\"}", head, null);
 
-        assertEquals("/test/blob", getPathList(index, "d:1", head));
-        assertEquals("/test2/blob2", getPathList(index, "d:2", head));
+        Assert.assertEquals("/test/blob", getPathList(index, "d:1", head));
+        Assert.assertEquals("/test2/blob2", getPathList(index, "d:2", head));
 
         head = mk.commit("/", "^\"test2/blob2\" : null", head, null);
-        assertEquals("", getPathList(index, "d:2", head));
+        Assert.assertEquals("", getPathList(index, "d:2", head));
 
         head = mk.commit("/", "^\"test2/blob2\" : \"d:2\" ", head, null);
-        assertEquals("/test2/blob2", getPathList(index, "d:2", head));
+        Assert.assertEquals("/test2/blob2", getPathList(index, "d:2", head));
 
         head = mk.commit("/", "+\"test3\" : {\"blob3\":\"d:1\"}", head, null);
         head = mk.commit("/", "+\"test4\" : {\"blob4\":\"d:2\"}", head, null);
 
-        assertEquals("/test/blob, /test3/blob3", getPathList(index, "d:1", head));
-        assertEquals("/test2/blob2, /test4/blob4", getPathList(index, "d:2", head));
+        Assert.assertEquals("/test/blob, /test3/blob3", getPathList(index, "d:1", head));
+        Assert.assertEquals("/test2/blob2, /test4/blob4", getPathList(index, "d:2", head));
 
         head = mk.commit("/", "+\"test5\" : {\"blobs\":[\"a:0\",\"d:2\"]}", head, null);
         head = mk.commit("/", "+\"test6\" : {\"data\":[true, false, null, 1, -1]}", head, null);
-        assertEquals("/test2/blob2, /test4/blob4, /test5/blobs", getPathList(index, "d:2", head));
+        Assert.assertEquals("/test2/blob2, /test4/blob4, /test5/blobs", getPathList(index, "d:2", head));
 
         head = mk.commit("/", "+\"test7\" : {\"a\":\"d:4\", \"b\":\"d:4\"}", head, null);
-        assertEquals("/test7/a, /test7/b", getPathList(index, "d:4", head));
+        Assert.assertEquals("/test7/a, /test7/b", getPathList(index, "d:4", head));
         head = mk.commit("/", "^\"test7/a\" : null", head, null);
-        assertEquals("/test7/b", getPathList(index, "d:4", head));
-
-        mk.dispose();
+        Assert.assertEquals("/test7/b", getPathList(index, "d:4", head));
     }
 
     private String getPathList(PrefixIndex index, String value, String revision) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java Wed Sep 21 10:01:36 2011
@@ -16,70 +16,66 @@
  */
 package org.apache.jackrabbit.mk.index;
 
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
+import junit.framework.Assert;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test the property index.
  */
-public class PropertyIndexTest extends TestCase {
+@RunWith(Parameterized.class)
+public class PropertyIndexTest extends MultiMkTestBase {
 
-    private static final String URL = "fs:{homeDir}/target";
-    // private static final String URL = "mem:fs:target/temp";
-    // private static final String URL = "mem:test";
-
-    public void test() {
-        test(URL);
+    public PropertyIndexTest(String url) {
+        super(url);
     }
 
-    private void test(String url) {
-        MicroKernel mk = MicroKernelFactory.getInstance(url + ";clean");
+    @Test
+    public void test() {
         Indexer indexer = new Indexer(mk);
         PropertyIndex index = indexer.createPropertyIndex("id", true);
 
         String head = mk.getHeadRevision();
         String oldHead = head;
 
-        assertEquals(null, index.getPath("1", head));
+        Assert.assertEquals(null, index.getPath("1", head));
 
         head = mk.commit("/", "+\"test\" : {\"id\":\"1\"}", head, null);
         head = mk.commit("/", "+\"test2\" : {\"id\":\"2\"}", head, null);
 
-        assertEquals("/test", index.getPath("1", head));
-        assertEquals("/test2", index.getPath("2", head));
+        Assert.assertEquals("/test", index.getPath("1", head));
+        Assert.assertEquals("/test2", index.getPath("2", head));
 
-        assertEquals("/test", index.getPath("1", oldHead));
-        assertEquals("/test2", index.getPath("2", oldHead));
+        Assert.assertEquals("/test", index.getPath("1", oldHead));
+        Assert.assertEquals("/test2", index.getPath("2", oldHead));
 
-        assertEquals("/test", index.getPath("1", head));
-        assertEquals("/test2", index.getPath("2", head));
+        Assert.assertEquals("/test", index.getPath("1", head));
+        Assert.assertEquals("/test2", index.getPath("2", head));
 
         head = mk.commit("/", "-\"test2\"", head, null);
         head = mk.commit("/test", "+\"test\" : {\"id\":\"3\"}", head, null);
 
-        assertEquals("/test/test", index.getPath("3", head));
+        Assert.assertEquals("/test/test", index.getPath("3", head));
 
-        mk.dispose();
+        reconnect();
 
-        mk = MicroKernelFactory.getInstance(url);
         indexer = new Indexer(mk);
         index = indexer.createPropertyIndex("id", true);
         head = mk.getHeadRevision();
-        assertEquals("/test/test", index.getPath("3", head));
-        assertEquals(null, index.getPath("0", head));
+        Assert.assertEquals("/test/test", index.getPath("3", head));
+        Assert.assertEquals(null, index.getPath("0", head));
 
-        assertEquals("/test", index.getPath("1", head));
+        Assert.assertEquals("/test", index.getPath("1", head));
         head = mk.commit("/", "^ \"test/id\": 100", head, null);
-        assertEquals(null, index.getPath("1", head));
-        assertEquals("/test", index.getPath("100", head));
+        Assert.assertEquals(null, index.getPath("1", head));
+        Assert.assertEquals("/test", index.getPath("100", head));
 
-        assertEquals("/test/test", index.getPath("3", head));
+        Assert.assertEquals("/test/test", index.getPath("3", head));
         head = mk.commit("/", "- \"test\"", head, null);
-        assertEquals(null, index.getPath("100", head));
-        assertEquals(null, index.getPath("3", head));
-
-        mk.dispose();
+        Assert.assertEquals(null, index.getPath("100", head));
+        Assert.assertEquals(null, index.getPath("3", head));
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java Wed Sep 21 10:01:36 2011
@@ -13,43 +13,29 @@
  */
 package org.apache.jackrabbit.mk.large;
 
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test creating nodes and traversing.
  */
-public class CreateNodesTraverseTest extends TestCase {
+@RunWith(Parameterized.class)
+public class CreateNodesTraverseTest extends MultiMkTestBase {
 
     // -Xmx512m -Dmk.fastDb=true
 
-    private static final String URL = "mem:;clean";
-    // created 200000 nodes in 3 seconds (62617 nodes/sec)
-    // read 200000 nodes in 0 seconds (213219 nodes/sec)
-
-    // private static final String URL = "fs:target/temp;clean";
-    // created 200000 nodes in 20 seconds (9783 nodes/sec)
-    // read 200000 nodes in 12 seconds (16129 nodes/sec)
-
-    // private static final String URL = "mem:fs:target/temp;clean";
-
     // private int totalCount = 200000;
 
     private int totalCount = 200;
 
     private int width = 30, count;
     private long start, last;
-    private MicroKernel mk;
     private String head;
 
-    public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(URL);
-        head = mk.getHeadRevision();
-    }
-
-    public void tearDown() throws InterruptedException {
-        mk.dispose();
+    public CreateNodesTraverseTest(String url) {
+        super(url);
     }
 
     public void test1() throws Exception {
@@ -64,7 +50,10 @@ public class CreateNodesTraverseTest ext
         // System.out.println(s);
     }
 
+    @Test
     public void test() throws Exception {
+        head = mk.getHeadRevision();
+
         int depth = (int) Math.ceil(Math.log(totalCount) / Math.log(width));
         log("depth: " + depth);
         head = mk.commit("/", "+\"test\":{}", head, "");

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/LargeNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/LargeNodeTest.java?rev=1173551&r1=1173550&r2=1173551&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/LargeNodeTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/LargeNodeTest.java Wed Sep 21 10:01:36 2011
@@ -16,53 +16,55 @@
  */
 package org.apache.jackrabbit.mk.large;
 
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
+import junit.framework.Assert;
+import org.apache.jackrabbit.mk.MultiMkTestBase;
 import org.apache.jackrabbit.mk.mem.NodeImpl;
 import org.apache.jackrabbit.mk.mem.NodeMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test moving nodes.
  */
-public class LargeNodeTest extends TestCase {
+@RunWith(Parameterized.class)
+public class LargeNodeTest extends MultiMkTestBase {
 
-    // private static final String URL = "fs:{homeDir};clean";
-    private static final String URL = "mem:;clean";
-    // private static final String URL = "mem:fs:target/temp;clean";
-
-    private MicroKernel mk;
     private String head;
 
+    public LargeNodeTest(String url) {
+        super(url);
+    }
+
+    @Before
     public void setUp() throws Exception {
-        mk = MicroKernelFactory.getInstance(URL);
+        super.setUp();
         head = mk.getHeadRevision();
         commit("/", "+ \"test\": {\"a\":{}, \"b\":{}, \"c\":{}}");
     }
 
-    public void tearDown() throws InterruptedException {
-        mk.dispose();
-    }
-
-    public void testGetNodes() {
+    @Test
+    public void getNodes() {
         head = mk.commit("/", "+\"x0\" : {\"x\": 0, \"x1\":{\"x\":1, \"x2\": {\"x\": -3}}}", head, null);
         String s = mk.getNodes("/x0", head);
-        assertEquals("{\"x\":0,\":childNodeCount\":1,\"x1\":{\"x\":1,\":childNodeCount\":1,\"x2\":{}}}", s);
+        Assert.assertEquals("{\"x\":0,\":childNodeCount\":1,\"x1\":{\"x\":1,\":childNodeCount\":1,\"x2\":{}}}", s);
         s = mk.getNodes("/x0", head, 1, 0, -1);
-        assertEquals("{\"x\":0,\":childNodeCount\":1,\"x1\":{\"x\":1,\":childNodeCount\":1,\"x2\":{}}}", s);
+        Assert.assertEquals("{\"x\":0,\":childNodeCount\":1,\"x1\":{\"x\":1,\":childNodeCount\":1,\"x2\":{}}}", s);
         s = mk.getNodes("/x0", head, 0, 0, -1);
-        assertEquals("{\"x\":0,\":childNodeCount\":1,\"x1\":{}}", s);
+        Assert.assertEquals("{\"x\":0,\":childNodeCount\":1,\"x1\":{}}", s);
         s = mk.getNodes("/x0", head, 0, 0, 0);
-        assertEquals("{\"x\":0,\":childNodeCount\":1}", s);
+        Assert.assertEquals("{\"x\":0,\":childNodeCount\":1}", s);
         head = mk.commit("/", "-\"x0\"", head, null);
     }
 
-    public void testVeryLargeNodeList() {
-        if (URL.startsWith("mem:")) {
+    @Test
+    public void veryLargeNodeList() {
+        if (url.startsWith("mem:")) {
             int max = 2000;
-            assertEquals("{\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
+            Assert.assertEquals("{\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
             head = mk.commit("/:root/head/config", "^ \"maxMemoryChildren\":" + max, head, "");
-            assertEquals("{\"maxMemoryChildren\":"+max+",\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
+            Assert.assertEquals("{\"maxMemoryChildren\":"+max+",\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
         }
         head = mk.commit("/", "+ \"t\": {}", head, "");
 
@@ -92,24 +94,25 @@ public class LargeNodeTest extends TestC
         if (buff.length() > 0) {
             head = mk.commit("/", buff.toString(), head, "");
         }
-        assertEquals("{\":childNodeCount\":"+count+"}", mk.getNodes("/t", head, 1, 0, 0));
+        Assert.assertEquals("{\":childNodeCount\":"+count+"}", mk.getNodes("/t", head, 1, 0, 0));
     }
 
     private static void log(String s) {
         // System.out.println(s);
     }
 
-    public void testLargeNodeList() {
-        if (URL.startsWith("fs:")) {
+    @Test
+    public void largeNodeList() {
+        if (url.startsWith("fs:")) {
             return;
         }
-        assertEquals("{\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
+        Assert.assertEquals("{\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
         head = mk.commit("/:root/head/config", "^ \"maxMemoryChildren\": 10", head, "");
-        assertEquals("{\"maxMemoryChildren\":10,\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
+        Assert.assertEquals("{\"maxMemoryChildren\":10,\":childNodeCount\":0}", mk.getNodes("/:root/head/config", head));
         for (int i = 0; i < 100; i++) {
             head = mk.commit("/", "+ \"t" + i + "\": {\"x\":" + i + "}", head, "");
         }
-        assertEquals("{\":childNodeCount\":101,\"test\":{\":childNodeCount\":3,\"a\":{},\"b\":{},\"c\":{}}," +
+        Assert.assertEquals("{\":childNodeCount\":101,\"test\":{\":childNodeCount\":3,\"a\":{},\"b\":{},\"c\":{}}," +
                 "\"t0\":{\"x\":0,\":childNodeCount\":0}," +
                 "\"t1\":{\"x\":1,\":childNodeCount\":0}," +
                 "\"t2\":{\"x\":2,\":childNodeCount\":0}," +
@@ -119,30 +122,31 @@ public class LargeNodeTest extends TestC
                 "\"t6\":{\"x\":6,\":childNodeCount\":0}," +
                 "\"t7\":{\"x\":7,\":childNodeCount\":0}," +
                 "\"t8\":{\"x\":8,\":childNodeCount\":0}}", mk.getNodes("/", head, 1, 0, -1));
-        assertEquals("{\":childNodeCount\":101," +
+        Assert.assertEquals("{\":childNodeCount\":101," +
                 "\"t0\":{\"x\":0,\":childNodeCount\":0}," +
                 "\"t1\":{\"x\":1,\":childNodeCount\":0}}", mk.getNodes("/", head, 1, 1, 2));
-        assertEquals("{\":childNodeCount\":101," +
+        Assert.assertEquals("{\":childNodeCount\":101," +
                 "\"t9\":{\"x\":9,\":childNodeCount\":0}," +
                 "\"t10\":{\"x\":10,\":childNodeCount\":0}}", mk.getNodes("/", head, 1, 10, 2));
-        assertEquals("{\":childNodeCount\":101," +
+        Assert.assertEquals("{\":childNodeCount\":101," +
                 "\"t19\":{\"x\":19,\":childNodeCount\":0}," +
                 "\"t20\":{\"x\":20,\":childNodeCount\":0}}", mk.getNodes("/", head, 1, 20, 2));
-        assertEquals("{\":childNodeCount\":101," +
+        Assert.assertEquals("{\":childNodeCount\":101," +
                 "\"t39\":{\"x\":39,\":childNodeCount\":0}," +
                 "\"t40\":{\"x\":40,\":childNodeCount\":0}}", mk.getNodes("/", head, 1, 40, 2));
-        assertEquals("{\":childNodeCount\":101," +
+        Assert.assertEquals("{\":childNodeCount\":101," +
                 "\"t89\":{\"x\":89,\":childNodeCount\":0}," +
                 "\"t90\":{\"x\":90,\":childNodeCount\":0}}", mk.getNodes("/", head, 1, 90, 2));
     }
 
-    public void testOffsetLimit() {
-        assertEquals("{a,b,c}", getNode("/test", 0, 0, -1));
-        assertEquals("{b,c}", getNode("/test", 0, 1, -1));
-        assertEquals("{c}", getNode("/test", 0, 2, -1));
-        assertEquals("{a}", getNode("/test", 0, 0, 1));
-        assertEquals("{a,b}", getNode("/test", 0, 0, 2));
-        assertEquals("{b}", getNode("/test", 0, 1, 1));
+    @Test
+    public void offsetLimit() {
+        Assert.assertEquals("{a,b,c}", getNode("/test", 0, 0, -1));
+        Assert.assertEquals("{b,c}", getNode("/test", 0, 1, -1));
+        Assert.assertEquals("{c}", getNode("/test", 0, 2, -1));
+        Assert.assertEquals("{a}", getNode("/test", 0, 0, 1));
+        Assert.assertEquals("{a,b}", getNode("/test", 0, 0, 2));
+        Assert.assertEquals("{b}", getNode("/test", 0, 1, 1));
     }
 
     private void commit(String root, String diff) {
@@ -157,19 +161,20 @@ public class LargeNodeTest extends TestC
         return s;
     }
 
-    public void testAddChildNodes() {
+    @Test
+    public void addChildNodes() {
         NodeMap map = new NodeMap();
 
         map.setMaxMemoryChildren(2);
 
         NodeImpl n = new NodeImpl(map, 0);
-        assertEquals("n0={}", n.asString());
+        Assert.assertEquals("n0={}", n.asString());
         n.setId(255);
-        assertEquals("nff={}", n.asString());
+        Assert.assertEquals("nff={}", n.asString());
         n.setPath("/test");
-        assertEquals("nff={}/* /test */", n.toString());
+        Assert.assertEquals("nff={}/* /test */", n.toString());
         n = n.createClone(10);
-        assertEquals("n0={}", n.asString());
+        Assert.assertEquals("n0={}", n.asString());
         NodeImpl a = new NodeImpl(map, 0);
         NodeImpl b = new NodeImpl(map, 0);
         NodeImpl c = new NodeImpl(map, 0);
@@ -177,27 +182,27 @@ public class LargeNodeTest extends TestC
         n = n.cloneAndAddChildNode("a", false, null, a, 11);
         n = n.cloneAndSetProperty("x", "1", 12);
         n.setId(3);
-        assertEquals("n3={\"x\":1,\"a\":n1}", n.asString());
+        Assert.assertEquals("n3={\"x\":1,\"a\":n1}", n.asString());
         NodeImpl n2 = NodeImpl.fromString(map, n.asString());
-        assertEquals("n3={\"x\":1,\"a\":n1}", n2.asString());
+        Assert.assertEquals("n3={\"x\":1,\"a\":n1}", n2.asString());
 
         n = new NodeImpl(map, 0);
         n = n.cloneAndAddChildNode("a", false, null, a, 1);
-        assertEquals("n0={\"a\":n1}", n.asString());
+        Assert.assertEquals("n0={\"a\":n1}", n.asString());
         n = n.cloneAndAddChildNode("b", false, null, b, 2);
-        assertEquals("n0={\"a\":n1,\"b\":n2}", n.asString());
+        Assert.assertEquals("n0={\"a\":n1,\"b\":n2}", n.asString());
         n = n.cloneAndAddChildNode("c", false, null, c, 3);
-        assertEquals("n0={\"a\":n1,\"b\":n2,\"c\":n3}", n.asString());
+        Assert.assertEquals("n0={\"a\":n1,\"b\":n2,\"c\":n3}", n.asString());
         n = n.cloneAndAddChildNode("d", false, null, d, 4);
-        assertEquals("n0={\":children\":n4,\":names\":\"63\",\":children\":n6,\":names\":\"64\",\":childCount\":4}",
+        Assert.assertEquals("n0={\":children\":n4,\":names\":\"63\",\":children\":n6,\":names\":\"64\",\":childCount\":4}",
                 n.asString());
         n2 = NodeImpl.fromString(map, n.asString());
-        assertEquals("n0={\":children\":n4,\":names\":\"63\",\":children\":n6,\":names\":\"64\",\":childCount\":4}",
+        Assert.assertEquals("n0={\":children\":n4,\":names\":\"63\",\":children\":n6,\":names\":\"64\",\":childCount\":4}",
                 n2.asString());
-        assertTrue(n2.exists("a"));
-        assertTrue(n2.exists("b"));
-        assertTrue(n2.exists("c"));
-        assertTrue(n2.exists("d"));
+        Assert.assertTrue(n2.exists("a"));
+        Assert.assertTrue(n2.exists("b"));
+        Assert.assertTrue(n2.exists("c"));
+        Assert.assertTrue(n2.exists("d"));
 
     }
 

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java?rev=1173551&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java (added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java Wed Sep 21 10:01:36 2011
@@ -0,0 +1,77 @@
+/*
+ * 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.mk.util;
+
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * A concurrency test tool.
+ */
+public class Concurrent {
+
+    /**
+     * Run a task concurrently in 2 threads for 1 second.
+     *
+     * @param task the task
+     * @throws Exception the first exception that is thrown (if any)
+     */
+    public static void run(Task task) throws Exception {
+        run(task, 2, 1000);
+    }
+
+    private static void run(final Task task, int threadCount, int millis) throws Exception {
+        final AtomicBoolean stopped = new AtomicBoolean();
+        final AtomicReference<Exception> exception = new AtomicReference<Exception>();
+        ArrayList<Thread> threads = new ArrayList<Thread>();
+        for (int i = 0; i < threadCount; i++) {
+            Thread t = new Thread("Test") {
+                public void run() {
+                    while (!stopped.get()) {
+                        try {
+                            task.call();
+                        } catch (Exception e) {
+                            exception.set(e);
+                            stopped.set(true);
+                        }
+                    }
+                }
+            };
+            t.start();
+            threads.add(t);
+        }
+        Exception e = null;
+        while (e == null && millis > 0) {
+            Thread.sleep(10);
+            millis -= 10;
+            e = exception.get();
+        }
+        stopped.set(true);
+        for (Thread t : threads) {
+            t.join();
+        }
+        if (e != null) {
+            throw e;
+        }
+    }
+
+    public interface Task {
+        void call() throws Exception;
+    }
+
+}



Mime
View raw message