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 mr...@apache.org on 2017/03/30 08:06:45 UTC
svn commit: r1789446 - in
/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document:
AbstractTwoNodeTest.java LastRevRecoveryAgentTest.java
Author: mreutegg
Date: Thu Mar 30 08:06:45 2017
New Revision: 1789446
URL: http://svn.apache.org/viewvc?rev=1789446&view=rev
Log:
OAK-6008: Create test base with a two node cluster
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractTwoNodeTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractTwoNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractTwoNodeTest.java?rev=1789446&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractTwoNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractTwoNodeTest.java Thu Mar 30 08:06:45 2017
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import java.io.IOException;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ * A base class for two node cluster tests with a virtual clock.
+ */
+@RunWith(Parameterized.class)
+public class AbstractTwoNodeTest {
+
+ private final DocumentStoreFixture fixture;
+
+ protected DocumentStore store1;
+ protected DocumentStore store2;
+ protected DocumentNodeStore ds1;
+ protected DocumentNodeStore ds2;
+ protected int c1Id;
+ protected int c2Id;
+ protected Clock clock;
+
+ public AbstractTwoNodeTest(DocumentStoreFixture fixture) {
+ this.fixture = fixture;
+ }
+
+ /**
+ * Can be overwritten by tests to customize / wrap the store.
+ *
+ * @param store the store to customize.
+ * @return the customized store.
+ */
+ protected DocumentStore customize(DocumentStore store) {
+ return store;
+ }
+
+ //----------------------------------------< Set Up >
+
+ @Parameterized.Parameters(name = "{0}")
+ public static java.util.Collection<Object[]> fixtures() throws IOException {
+ List<Object[]> fixtures = Lists.newArrayList();
+ fixtures.add(new Object[] {new DocumentStoreFixture.MemoryFixture()});
+
+ DocumentStoreFixture rdb = new DocumentStoreFixture.RDBFixture("RDB-H2(file)", "jdbc:h2:file:./target/ds-test", "sa", "");
+ if (rdb.isAvailable()) {
+ fixtures.add(new Object[] { rdb });
+ }
+
+ DocumentStoreFixture mongo = new DocumentStoreFixture.MongoFixture();
+ if (mongo.isAvailable()) {
+ fixtures.add(new Object[] { mongo });
+ }
+ return fixtures;
+ }
+
+ @Before
+ public void setUp() throws InterruptedException {
+ clock = new Clock.Virtual();
+ clock.waitUntil(System.currentTimeMillis());
+
+ ClusterNodeInfo.setClock(clock);
+ Revision.setClock(clock);
+ store1 = fixture.createDocumentStore(1);
+ if (!fixture.hasSinglePersistence()) {
+ store2 = store1;
+ } else {
+ store2 = fixture.createDocumentStore(2);
+ }
+
+ ds1 = new DocumentMK.Builder()
+ .setAsyncDelay(0)
+ .clock(clock)
+ .setDocumentStore(wrap(customize(store1)))
+ .setLeaseCheck(false)
+ .setClusterId(1)
+ .getNodeStore();
+ c1Id = ds1.getClusterId();
+
+ ds2 = new DocumentMK.Builder()
+ .setAsyncDelay(0)
+ .clock(clock)
+ .setDocumentStore(wrap(customize(store2)))
+ .setLeaseCheck(false)
+ .setClusterId(2)
+ .getNodeStore();
+ c2Id = ds2.getClusterId();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ds1.dispose();
+ ds2.dispose();
+ store1.dispose();
+ store2.dispose();
+ fixture.dispose();
+ ClusterNodeInfo.resetClockToDefault();
+ Revision.resetClockToDefault();
+ }
+
+ private static DocumentStore wrap(DocumentStore ds) {
+ return new DocumentStoreTestWrapper(ds);
+ }
+
+ private static class DocumentStoreTestWrapper extends DocumentStoreWrapper {
+
+ DocumentStoreTestWrapper(DocumentStore store) {
+ super(store);
+ }
+
+ @Override
+ public void dispose() {
+ // ignore
+ }
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractTwoNodeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java?rev=1789446&r1=1789445&r2=1789446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgentTest.java Thu Mar 30 08:06:45 2017
@@ -19,23 +19,13 @@
package org.apache.jackrabbit.oak.plugins.document;
-import java.io.IOException;
-import java.util.List;
-
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.RDBFixture;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.stats.Clock;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getIdFromPath;
@@ -44,88 +34,12 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-@RunWith(Parameterized.class)
-public class LastRevRecoveryAgentTest {
- private final DocumentStoreFixture fixture;
-
- private DocumentNodeStore ds1;
- private DocumentNodeStore ds2;
- private int c1Id;
- private int c2Id;
- private DocumentStore sharedStore;
- private Clock clock;
+public class LastRevRecoveryAgentTest extends AbstractTwoNodeTest {
public LastRevRecoveryAgentTest(DocumentStoreFixture fixture) {
- this.fixture = fixture;
+ super(fixture);
}
- //----------------------------------------< Set Up >
-
- @Parameterized.Parameters
- public static java.util.Collection<Object[]> fixtures() throws IOException {
- List<Object[]> fixtures = Lists.newArrayList();
- fixtures.add(new Object[] {new DocumentStoreFixture.MemoryFixture()});
-
- DocumentStoreFixture rdb = new RDBFixture("RDB-H2(file)", "jdbc:h2:file:./target/ds-test", "sa", "");
- if (rdb.isAvailable()) {
- fixtures.add(new Object[] { rdb });
- }
-
- DocumentStoreFixture mongo = new DocumentStoreFixture.MongoFixture();
- if (mongo.isAvailable()) {
- fixtures.add(new Object[] { mongo });
- }
- return fixtures;
- }
-
- @Before
- public void setUp() throws InterruptedException {
- clock = new Clock.Virtual();
-
- //Quite a bit of logic relies on timestamp converted
- // to 5 sec resolutions
- clock.waitUntil(System.currentTimeMillis());
-
- ClusterNodeInfo.setClock(clock);
- Revision.setClock(clock);
- sharedStore = fixture.createDocumentStore();
- DocumentStoreWrapper store = new DocumentStoreWrapper(sharedStore) {
- @Override
- public void dispose() {
- // do not dispose when called by DocumentNodeStore
- }
- };
- ds1 = new DocumentMK.Builder()
- .setAsyncDelay(0)
- .clock(clock)
- .setDocumentStore(store)
- .setLeaseCheck(false)
- .setClusterId(1)
- .getNodeStore();
- c1Id = ds1.getClusterId();
-
- ds2 = new DocumentMK.Builder()
- .setAsyncDelay(0)
- .clock(clock)
- .setDocumentStore(store)
- .setLeaseCheck(false)
- .setClusterId(2)
- .getNodeStore();
- c2Id = ds2.getClusterId();
- }
-
- @After
- public void tearDown() throws Exception {
- ds1.dispose();
- ds2.dispose();
- sharedStore.dispose();
- fixture.dispose();
- ClusterNodeInfo.resetClockToDefault();
- Revision.resetClockToDefault();
- }
-
- //~------------------------------------------< Test Case >
-
@Test
public void testIsRecoveryRequired() throws Exception{
//1. Create base structure /x/y