Search in sources :

Example 6 with ExecutorCloser

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

the class AsyncIndexUpdateTest 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)

Example 7 with ExecutorCloser

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

the class UploadStagingCacheTest method testConcurrentGetDelete.

/**
     * Concurrently retrieve after stage but before upload.
     * @throws Exception
     */
@Test
public void testConcurrentGetDelete() throws Exception {
    ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
    closer.register(new ExecutorCloser(executorService));
    // Add load
    List<ListenableFuture<Integer>> futures = put(folder);
    // Get a handle to the file and open stream
    File file = stagingCache.getIfPresent(ID_PREFIX + 0);
    final InputStream fStream = Files.asByteSource(file).openStream();
    // task to copy the steam to a file simulating read from the stream
    File temp = folder.newFile();
    CountDownLatch copyThreadLatch = new CountDownLatch(1);
    SettableFuture<File> future1 = copyStreamThread(executorService, fStream, temp, copyThreadLatch);
    //start
    taskLatch.countDown();
    callbackLatch.countDown();
    waitFinish(futures);
    // trying copying now
    copyThreadLatch.countDown();
    future1.get();
    assertTrue(Files.equal(temp, uploader.read(ID_PREFIX + 0)));
}
Also used : InputStream(java.io.InputStream) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) File(java.io.File) Test(org.junit.Test)

Example 8 with ExecutorCloser

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

the class CompositeDataStoreCacheTest method concurrentGetCached.

/**
     * Concurrently retrieves 2 different files from cache.
     * @throws Exception
     */
@Test
public void concurrentGetCached() throws Exception {
    LOG.info("Starting concurrentGetCached");
    // Add 2 files to backend
    // Concurrently get both
    ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
    closer.register(new ExecutorCloser(executorService, 5, TimeUnit.MILLISECONDS));
    File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
    loader.write(ID_PREFIX + 0, f);
    assertTrue(f.exists());
    File f2 = copyToFile(randomStream(1, 4 * 1024), folder.newFile());
    loader.write(ID_PREFIX + 1, f2);
    assertTrue(f2.exists());
    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();
    File cached = future1.get();
    File cached2 = future2.get();
    LOG.info("Async tasks finished");
    assertTrue(Files.equal(f, cached));
    assertTrue(Files.equal(f2, cached2));
    assertCacheStats(cache.getStagingCacheStats(), 0, 0, 0, 0);
    assertEquals(2, cache.getStagingCacheStats().getLoadCount());
    assertEquals(0, cache.getStagingCacheStats().getLoadSuccessCount());
    assertCacheStats(cache.getCacheStats(), 2, 8 * 1024, 0, 4);
    assertEquals(2, cache.getCacheStats().getLoadCount());
    assertEquals(2, cache.getCacheStats().getLoadSuccessCount());
    LOG.info("Finished concurrentGetCached");
}
Also used : ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) File(java.io.File) Test(org.junit.Test)

Example 9 with ExecutorCloser

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

the class CachingDataStoreTest method init.

private void init(int i, int cacheSize, int uploadSplit) throws Exception {
    LOG.info("Starting init");
    // create executor
    taskLatch = new CountDownLatch(1);
    callbackLatch = new CountDownLatch(1);
    afterExecuteLatch = new CountDownLatch(i);
    TestExecutor listeningExecutor = new TestExecutor(1, taskLatch, callbackLatch, afterExecuteLatch);
    // stats
    ScheduledExecutorService statsExecutor = Executors.newSingleThreadScheduledExecutor();
    closer.register(new ExecutorCloser(statsExecutor, 500, TimeUnit.MILLISECONDS));
    StatisticsProvider statsProvider = new DefaultStatisticsProvider(statsExecutor);
    scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
    closer.register(new ExecutorCloser(scheduledExecutor, 500, TimeUnit.MILLISECONDS));
    final File datastoreRoot = folder.newFolder();
    final TestMemoryBackend testBackend = new TestMemoryBackend(datastoreRoot);
    this.backend = testBackend;
    dataStore = new AbstractSharedCachingDataStore() {

        @Override
        protected AbstractSharedBackend createBackend() {
            return testBackend;
        }

        @Override
        public int getMinRecordLength() {
            return 0;
        }
    };
    dataStore.setStatisticsProvider(statsProvider);
    dataStore.setCacheSize(cacheSize);
    dataStore.setStagingSplitPercentage(uploadSplit);
    dataStore.listeningExecutor = listeningExecutor;
    dataStore.schedulerExecutor = scheduledExecutor;
    dataStore.executor = sameThreadExecutor();
    dataStore.init(root.getAbsolutePath());
    LOG.info("Finished init");
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DefaultStatisticsProvider(org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) DefaultStatisticsProvider(org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) File(java.io.File) AbstractSharedBackend(org.apache.jackrabbit.oak.spi.blob.AbstractSharedBackend)

Example 10 with ExecutorCloser

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

the class FileCacheTest method getInvalidateConcurrent.

/**
     * Retrieve and invalidate concurrently.
     * @throws Exception
     */
@Test
public void getInvalidateConcurrent() throws Exception {
    LOG.info("Started getInvalidateConcurrent");
    //Create load
    for (int i = 0; i < 15; i++) {
        if (i != 4) {
            File f = createFile(i, loader, cache, folder);
            assertCache(i, cache, f);
        }
    }
    LOG.info("Finished creating load");
    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 + 10, cache, thread1Start);
    thread1Start.countDown();
    File f = createFile(4, loader, cache, folder);
    CountDownLatch thread2Start = new CountDownLatch(1);
    SettableFuture<File> future2 = retrieveThread(executorService, ID_PREFIX + 4, cache, thread2Start);
    thread2Start.countDown();
    File f10 = future1.get();
    File f4 = future2.get();
    LOG.info("Async tasks finished");
    if (f10.exists()) {
        assertCacheIfPresent(10, cache, f10);
    }
    if (f4.exists()) {
        assertCacheIfPresent(4, cache, f4);
    }
    LOG.info("Finished getInvalidateConcurrent");
}
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)

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