Search in sources :

Example 36 with ExecutorCloser

use of org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser in project jackrabbit-oak by apache.

the class CompactionAndCleanupIT method randomAccessFileConcurrentReadAndLength.

@Test
public void randomAccessFileConcurrentReadAndLength() throws Exception {
    final FileStore fileStore = fileStoreBuilder(getFileStoreFolder()).withGCOptions(defaultGCOptions().setRetainedGenerations(2)).withMaxFileSize(1).withMemoryMapping(false).build();
    final SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    ExecutorService executorService = newFixedThreadPool(300);
    final AtomicInteger counter = new AtomicInteger();
    final ReferenceCollector dummyCollector = new ReferenceCollector() {

        @Override
        public void addReference(String reference, String nodeId) {
        // do nothing
        }
    };
    try {
        Callable<Void> concurrentWriteTask = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                NodeBuilder builder = nodeStore.getRoot().builder();
                builder.setProperty("blob-" + counter.getAndIncrement(), createBlob(nodeStore, 25 * 25));
                nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
                fileStore.flush();
                return null;
            }
        };
        Callable<Void> concurrentCleanupTask = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                fileStore.cleanup();
                return null;
            }
        };
        Callable<Void> concurrentReferenceCollector = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                fileStore.collectBlobReferences(dummyCollector);
                return null;
            }
        };
        List<Future<?>> results = newArrayList();
        for (int i = 0; i < 100; i++) {
            results.add(executorService.submit(concurrentWriteTask));
            results.add(executorService.submit(concurrentCleanupTask));
            results.add(executorService.submit(concurrentReferenceCollector));
        }
        for (Future<?> result : results) {
            assertNull(result.get());
        }
    } finally {
        new ExecutorCloser(executorService).close();
        fileStore.close();
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Callable(java.util.concurrent.Callable) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) Test(org.junit.Test)

Aggregations

ExecutorCloser (org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser)36 Test (org.junit.Test)15 File (java.io.File)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)9 ExecutorService (java.util.concurrent.ExecutorService)6 DefaultStatisticsProvider (org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 After (org.junit.After)5 Callable (java.util.concurrent.Callable)4 Future (java.util.concurrent.Future)4 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 InputStream (java.io.InputStream)3 StatisticsProvider (org.apache.jackrabbit.oak.stats.StatisticsProvider)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Closeable (java.io.Closeable)2 IOException (java.io.IOException)2 List (java.util.List)2