Search in sources :

Example 11 with ExecutorCloser

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

the class FileCacheTest method retrievePutConcurrent.

/**
     * Retrieve and put different files concurrently.
     * @throws Exception
     */
@Test
public void retrievePutConcurrent() throws Exception {
    LOG.info("Started retrievePutConcurrent");
    //Create load
    final File f = createFile(0, loader, cache, folder);
    File f2 = copyToFile(randomStream(1, 4 * 1024), folder.newFile());
    ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
    closer.register(new ExecutorCloser(executorService, 5, TimeUnit.MILLISECONDS));
    CountDownLatch thread1Start = new CountDownLatch(1);
    SettableFuture<File> future1 = retrieveThread(executorService, ID_PREFIX + 0, cache, thread1Start);
    CountDownLatch thread2Start = new CountDownLatch(1);
    SettableFuture<Boolean> future2 = putThread(executorService, 1, f2, cache, thread2Start);
    thread1Start.countDown();
    thread2Start.countDown();
    future1.get();
    future2.get();
    LOG.info("Async tasks finished");
    assertCacheIfPresent(0, cache, f);
    assertCacheIfPresent(1, cache, copyToFile(randomStream(1, 4 * 1024), folder.newFile()));
    assertCacheStats(cache, 2, 8 * 1024, 1, 1);
    LOG.info("Finished retrievePutConcurrent");
}
Also used : ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) Test(org.junit.Test)

Example 12 with ExecutorCloser

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

the class FileCacheTest method getDifferentConcurrent.

/**
     * Retrieves different files concurrently.
     * @throws Exception
     */
@Test
public void getDifferentConcurrent() throws Exception {
    LOG.info("Started getDifferentConcurrent");
    File f = createFile(0, loader, cache, folder);
    File f2 = createFile(1, loader, cache, folder);
    ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
    closer.register(new ExecutorCloser(executorService, 5, TimeUnit.MILLISECONDS));
    CountDownLatch thread1Start = new CountDownLatch(1);
    SettableFuture<File> future1 = retrieveThread(executorService, ID_PREFIX + 0, cache, thread1Start);
    CountDownLatch thread2Start = new CountDownLatch(1);
    SettableFuture<File> future2 = retrieveThread(executorService, ID_PREFIX + 1, cache, thread2Start);
    thread1Start.countDown();
    thread2Start.countDown();
    future1.get();
    future2.get();
    LOG.info("Async tasks finished");
    assertCacheIfPresent(0, cache, f);
    assertCacheIfPresent(1, cache, f2);
    assertCacheStats(cache, 2, 8 * 1024, 2, 2);
    LOG.info("Finished getDifferentConcurrent");
}
Also used : ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) Test(org.junit.Test)

Example 13 with ExecutorCloser

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

the class Oak method getExecutor.

private synchronized Executor getExecutor() {
    if (executor == null) {
        ExecutorService executorService = defaultExecutorService();
        executor = executorService;
        closer.register(new ExecutorCloser(executorService));
    }
    return executor;
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser)

Example 14 with ExecutorCloser

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

the class Oak method getScheduledExecutor.

private synchronized ScheduledExecutorService getScheduledExecutor() {
    if (scheduledExecutor == null) {
        scheduledExecutor = defaultScheduledExecutor();
        closer.register(new ExecutorCloser(scheduledExecutor));
    }
    return scheduledExecutor;
}
Also used : ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser)

Example 15 with ExecutorCloser

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

the class DocumentStoreStatsTest method shutDown.

@After
public void shutDown() {
    statsProvider.close();
    new ExecutorCloser(executor).close();
}
Also used : ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) After(org.junit.After)

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