You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2012/04/09 09:23:25 UTC

svn commit: r1311153 - in /jackrabbit/oak/trunk/oak-it/mk: ./ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/jackrabbit/ src/main/java/org/apache/jackrabbit/mk/ src/main/java/org/apache/jackrabbit/mk/test/

Author: jukka
Date: Mon Apr  9 07:23:25 2012
New Revision: 1311153

URL: http://svn.apache.org/viewvc?rev=1311153&view=rev
Log:
OAK-12: Implement a test suite for the MicroKernel

Add a integration test base class and a service interface for different MK implementations

Added:
    jackrabbit/oak/trunk/oak-it/mk/src/main/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java
Modified:
    jackrabbit/oak/trunk/oak-it/mk/pom.xml

Modified: jackrabbit/oak/trunk/oak-it/mk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/pom.xml?rev=1311153&r1=1311152&r2=1311153&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-it/mk/pom.xml Mon Apr  9 07:23:25 2012
@@ -36,6 +36,10 @@
 
   <dependencies>
     <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>oak-mk</artifactId>
       <version>${project.version}</version>

Added: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java?rev=1311153&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java (added)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/AbstractMicroKernelIT.java Mon Apr  9 07:23:25 2012
@@ -0,0 +1,103 @@
+/*
+ * 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.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.ServiceLoader;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Abstract base class for {@link MicroKernel} integration tests.
+ */
+public abstract class AbstractMicroKernelIT {
+
+    /**
+     * Finds and returns all {@link MicroKernelFixture} services available
+     * in the current classpath.
+     *
+     * @return available {@link MicroKernelFixture} services
+     */
+    @Parameters
+    public static Collection<MicroKernelFixture> loadFixtures() {
+        Collection<MicroKernelFixture> fixtures =
+                new ArrayList<MicroKernelFixture>();
+
+        Class<MicroKernelFixture> iface = MicroKernelFixture.class;
+        ServiceLoader<MicroKernelFixture> loader =
+                ServiceLoader.load(iface, iface.getClassLoader());
+        for (MicroKernelFixture fixture : loader) {
+            fixtures.add(fixture);
+        }
+
+        return fixtures;
+    }
+
+    /**
+     * The {@link MicroKernelFixture} service used by this test case instance.
+     */
+    protected final MicroKernelFixture fixture;
+
+    /**
+     * The {@link MicroKernel} cluster node instances used by this test case.
+     */
+    protected final MicroKernel[] mks;
+
+    /**
+     * The {@link MicroKernel} instance used by this test case.
+     * In a clustered setup this is the first node of the cluster.
+     */
+    protected MicroKernel mk;
+
+    /**
+     * Creates a {@link MicroKernel} test case for a cluster of the given
+     * size created using the given {@link MicroKernelFixture} service.
+     *
+     * @param fixture {@link MicroKernelFixture} service
+     * @param nodeCount number of nodes that the test cluster should contain
+     */
+    protected AbstractMicroKernelIT(MicroKernelFixture fixture, int nodeCount) {
+        assert nodeCount > 0;
+        this.fixture = fixture;
+        this.mks = new MicroKernel[nodeCount];
+    }
+
+    /**
+     * Prepares the test case by initializing the {@link #mks} and
+     * {@link #mk} variables with a new {@link MicroKernel} cluster
+     * from the {@link MicroKernelFixture} service associated with
+     * this test case.
+     */
+    @Before
+    public void setUp() {
+        fixture.setUpCluster(mks);
+        mk = mks[0];
+    }
+
+    /**
+     * Releases the {@link MicroKernel} cluster used by this test case.
+     */
+    @After
+    public void tearDown() {
+        fixture.tearDownCluster(mks);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java?rev=1311153&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java (added)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelFixture.java Mon Apr  9 07:23:25 2012
@@ -0,0 +1,63 @@
+/*
+ * 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.test;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+/**
+ * Interface through which different {@link MicroKernel} implementations
+ * make themselves available for use by this integration test suite.
+ */
+public interface MicroKernelFixture {
+
+    /**
+     * Creates a new {@link MicroKernel} cluster with as many nodes as the
+     * given array has elements. References to the cluster nodes are stored
+     * in the given array. The initial state of the cluster consists of just
+     * an empty root node and a shared journal with only a single root
+     * revision. The caller of this method should have exclusive access to
+     * the created cluster. The caller is also responsible for calling
+     * {@link #tearDownCluster(MicroKernel[])} when the test cluster is
+     * no longer needed.
+     *
+     * @param cluster array to which references to all nodes of the
+     *                created cluster should be stored
+     */
+    void setUpCluster(MicroKernel[] cluster);
+
+    /**
+     * Ensures that all content changes seen by one of the given cluster
+     * nodes are seen also by all the other given nodes. Used to help
+     * testing features like eventual consistency where the standard
+     * {@link MicroKernel} API doesn't make strong enough guarantees to
+     * enable writing a test case without a potentially unbounded wait for
+     * changes to propagate across the cluster.
+     *
+     * @param nodes cluster nodes to be synchronized
+     */
+    void syncMicroKernelCluster(MicroKernel... nodes);
+
+    /**
+     * Releases resources associated with the given {@link MicroKernel}
+     * cluster. The caller of {@link #setUpCluster(MicroKernel[])} shall
+     * call this method once the cluster is no longer needed.
+     *
+     * @param cluster array containing references to all nodes of the cluster
+     */
+    void tearDownCluster(MicroKernel[] cluster);
+
+}