diff --git oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java index 59a725c..c3e3c33 100644 --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java @@ -29,6 +29,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.util.Random; +import java.util.concurrent.ScheduledExecutorService; import org.apache.jackrabbit.core.data.FileDataStore; import org.apache.jackrabbit.oak.api.Blob; @@ -46,6 +47,7 @@ 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.spi.state.NodeStore; +import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -61,7 +63,7 @@ public class DataStoreTestBase extends TestBase { setUpServerAndClient(); } - protected FileStore setupFileDataStore(File d, String path) throws Exception { + protected FileStore setupFileDataStore(ScheduledExecutorService executor, File d, String path) throws Exception { FileDataStore fds = new FileDataStore(); fds.setMinRecordLength(4092); fds.init(path); @@ -74,6 +76,7 @@ public class DataStoreTestBase extends TestBase { .withStringCacheSize(0) .withTemplateCacheSize(0) .withBlobStore(blobStore) + .withStatisticsProvider(new DefaultStatisticsProvider(executor)) .build(); } diff --git oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalPrivateStoreIT.java oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalPrivateStoreIT.java index 8e74d3b..ed9c6f6 100644 --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalPrivateStoreIT.java +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalPrivateStoreIT.java @@ -22,6 +22,7 @@ import static org.apache.jackrabbit.oak.segment.SegmentTestUtils.createTmpTarget import java.io.File; import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.segment.file.FileStore; @@ -31,11 +32,16 @@ import org.junit.After; public class ExternalPrivateStoreIT extends DataStoreTestBase { private File primaryStore; + private ScheduledExecutorService primaryExecutor; + private File secondaryStore; + private ScheduledExecutorService secondaryExecutor; @After public void after() { closeServerAndClient(); + closeExecutor(primaryExecutor); + closeExecutor(secondaryExecutor); try { FileUtils.deleteDirectory(primaryStore); FileUtils.deleteDirectory(secondaryStore); @@ -44,15 +50,17 @@ public class ExternalPrivateStoreIT extends DataStoreTestBase { } @Override - protected FileStore setupPrimary(File d) throws Exception { + protected FileStore setupPrimary(ScheduledExecutorService executor, File d) throws Exception { primaryStore = createTmpTargetDir("ExternalStoreITPrimary"); - return setupFileDataStore(d, primaryStore.getAbsolutePath()); + primaryExecutor = newExecutor(); + return setupFileDataStore(primaryExecutor, d, primaryStore.getAbsolutePath()); } @Override - protected FileStore setupSecondary(File d) throws Exception { + protected FileStore setupSecondary(ScheduledExecutorService executor, File d) throws Exception { secondaryStore = createTmpTargetDir("ExternalStoreITSecondary"); - return setupFileDataStore(d, secondaryStore.getAbsolutePath()); + secondaryExecutor = newExecutor(); + return setupFileDataStore(secondaryExecutor, d, secondaryStore.getAbsolutePath()); } } diff --git oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalSharedStoreIT.java oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalSharedStoreIT.java index e6635b5..21debe1 100644 --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalSharedStoreIT.java +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/ExternalSharedStoreIT.java @@ -22,22 +22,32 @@ import static org.apache.jackrabbit.oak.segment.SegmentTestUtils.createTmpTarget import java.io.File; import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.segment.file.FileStore; import org.junit.After; +import org.junit.Before; public class ExternalSharedStoreIT extends DataStoreTestBase { private File externalStore; + private ScheduledExecutorService executor; public ExternalSharedStoreIT() { super(); this.storesCanBeEqual = true; } + @Before + public void setUp() throws Exception { + super.setUp(); + executor = newExecutor(); + } + @After public void after() { closeServerAndClient(); + closeExecutor(executor); try { FileUtils.deleteDirectory(externalStore); } catch (IOException e) { @@ -45,13 +55,13 @@ public class ExternalSharedStoreIT extends DataStoreTestBase { } @Override - protected FileStore setupPrimary(File d) throws Exception { + protected FileStore setupPrimary(ScheduledExecutorService executor, File d) throws Exception { externalStore = createTmpTargetDir("ExternalCommonStoreIT"); - return setupFileDataStore(d, externalStore.getAbsolutePath()); + return setupFileDataStore(executor, d, externalStore.getAbsolutePath()); } @Override - protected FileStore setupSecondary(File d) throws Exception { - return setupFileDataStore(d, externalStore.getAbsolutePath()); + protected FileStore setupSecondary(ScheduledExecutorService executor, File d) throws Exception { + return setupFileDataStore(executor, d, externalStore.getAbsolutePath()); } } diff --git oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java index a0d9616..1acd2d6 100644 --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java @@ -25,12 +25,15 @@ import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.SystemUtils; import org.apache.jackrabbit.oak.commons.CIHelper; import org.apache.jackrabbit.oak.segment.file.FileStore; import org.apache.jackrabbit.oak.segment.standby.client.StandbyClient; +import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider; import org.junit.BeforeClass; public class TestBase { @@ -47,12 +50,15 @@ public class TestBase { File directoryS; FileStore storeS; + ScheduledExecutorService executorS; File directoryC; FileStore storeC; + ScheduledExecutorService executorC; File directoryC2; FileStore storeC2; + ScheduledExecutorService executorC2; /* Java 6 on Windows doesn't support dual IP stacks, so we will skip our IPv6 @@ -68,14 +74,16 @@ public class TestBase { public void setUpServerAndClient() throws Exception { // server directoryS = createTmpTargetDir(getClass().getSimpleName()+"-Server"); - storeS = setupPrimary(directoryS); + executorS = newExecutor(); + storeS = setupPrimary(executorS, directoryS); // client directoryC = createTmpTargetDir(getClass().getSimpleName()+"-Client"); - storeC = setupSecondary(directoryC); + executorC = newExecutor(); + storeC = setupSecondary(executorC, directoryC); } - private static FileStore newFileStore(File directory) throws Exception { + private static FileStore newFileStore(ScheduledExecutorService executor, File directory) throws Exception { return fileStoreBuilder(directory) .withMaxFileSize(1) .withMemoryMapping(false) @@ -83,19 +91,30 @@ public class TestBase { .withSegmentCacheSize(0) .withStringCacheSize(0) .withTemplateCacheSize(0) + .withStatisticsProvider(new DefaultStatisticsProvider(executor)) .build(); } - protected FileStore setupPrimary(File directory) throws Exception { - return newFileStore(directory); + protected FileStore setupPrimary(ScheduledExecutorService executor, File directory) throws Exception { + return newFileStore(executor, directory); } protected FileStore getPrimary() { return storeS; } - protected FileStore setupSecondary(File directory) throws Exception { - return newFileStore(directoryC); + protected FileStore setupSecondary(ScheduledExecutorService executor, File directory) throws Exception { + return newFileStore(executor, directoryC); + } + + protected ScheduledExecutorService newExecutor() { + return Executors.newSingleThreadScheduledExecutor(); + } + + protected void closeExecutor(ScheduledExecutorService executor) { + if (executor != null) { + executor.shutdownNow(); + } } protected FileStore getSecondary() { @@ -106,12 +125,15 @@ public class TestBase { setUpServerAndClient(); directoryC2 = createTmpTargetDir(getClass().getSimpleName()+"-Client2"); - storeC2 = newFileStore(directoryC2); + executorC2 = newExecutor(); + storeC2 = newFileStore(executorC2, directoryC2); } public void closeServerAndClient() { storeS.close(); storeC.close(); + closeExecutor(executorS); + closeExecutor(executorC); try { FileUtils.deleteDirectory(directoryS); FileUtils.deleteDirectory(directoryC); @@ -122,6 +144,7 @@ public class TestBase { public void closeServerAndTwoClients() { closeServerAndClient(); storeC2.close(); + closeExecutor(executorC2); try { FileUtils.deleteDirectory(directoryC2); } catch (IOException e) {