Search in sources :

Example 21 with ExecutorCloser

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

the class UploadStagingCacheTest method init.

private void init(int i, TestStagingUploader testUploader, File homeDir) {
    // uploader
    uploader = testUploader;
    // create executor
    taskLatch = new CountDownLatch(1);
    callbackLatch = new CountDownLatch(1);
    afterExecuteLatch = new CountDownLatch(i);
    executor = new TestExecutor(1, taskLatch, callbackLatch, afterExecuteLatch);
    // stats
    ScheduledExecutorService statsExecutor = Executors.newSingleThreadScheduledExecutor();
    closer.register(new ExecutorCloser(statsExecutor, 500, TimeUnit.MILLISECONDS));
    statsProvider = new DefaultStatisticsProvider(statsExecutor);
    removeExecutor = Executors.newSingleThreadScheduledExecutor();
    closer.register(new ExecutorCloser(removeExecutor, 500, TimeUnit.MILLISECONDS));
    //cache instance
    stagingCache = UploadStagingCache.build(root, homeDir, 1, /*threads*/
    8 * 1024, /* bytes */
    uploader, null, /*cache*/
    statsProvider, executor, null, 3000, 6000);
    closer.register(stagingCache);
}
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)

Example 22 with ExecutorCloser

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

the class BlobIdTrackerTest method snapshotRetrieveIgnored.

@Test
public void snapshotRetrieveIgnored() throws Exception {
    System.setProperty("oak.datastore.skipTracker", "true");
    // Close and open a new object to use the system property
    closer.close();
    this.tracker = new BlobIdTracker(root.getAbsolutePath(), repoId, 100 * 60, dataStore);
    this.scheduler = newSingleThreadScheduledExecutor();
    closer.register(tracker);
    closer.register(new ExecutorCloser(scheduler));
    try {
        Set<String> initAdd = add(tracker, range(0, 10000));
        ScheduledFuture<?> scheduledFuture = scheduler.schedule(tracker.new SnapshotJob(), 0, TimeUnit.MILLISECONDS);
        scheduledFuture.get();
        assertEquals("References file not empty", 0, tracker.store.getBlobRecordsFile().length());
        Set<String> retrieved = retrieveFile(tracker, folder);
        assertTrue(retrieved.isEmpty());
        retrieved = retrieve(tracker);
        assertTrue(retrieved.isEmpty());
    } finally {
        //reset the skip tracker system prop
        System.clearProperty("oak.datastore.skipTracker");
    }
}
Also used : ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) Test(org.junit.Test)

Example 23 with ExecutorCloser

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

the class BlobIdTrackerTest method externalAddOffline.

@Test
public void externalAddOffline() throws Exception {
    // Close and open a new object to use the system property
    closer.close();
    root = folder.newFolder();
    File blobIdRoot = new File(root, "blobids");
    blobIdRoot.mkdirs();
    //Add file offline
    File offline = new File(blobIdRoot, "blob-offline123456.gen");
    List<String> offlineLoad = range(0, 1000);
    FileIOUtils.writeStrings(offlineLoad.iterator(), offline, false);
    this.tracker = new BlobIdTracker(root.getAbsolutePath(), repoId, 100 * 60, dataStore);
    this.scheduler = newSingleThreadScheduledExecutor();
    closer.register(tracker);
    closer.register(new ExecutorCloser(scheduler));
    Set<String> initAdd = add(tracker, range(1001, 1005));
    ScheduledFuture<?> scheduledFuture = scheduler.schedule(tracker.new SnapshotJob(), 0, TimeUnit.MILLISECONDS);
    scheduledFuture.get();
    initAdd.addAll(offlineLoad);
    assertEquals(initAdd.size(), Iterators.size(tracker.get()));
    Set<String> retrieved = retrieve(tracker);
    assertEquals("Extra elements after add", initAdd, retrieved);
    assertTrue(read(dataStore.getAllMetadataRecords(BLOBREFERENCES.getType())).isEmpty());
}
Also used : File(java.io.File) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) Test(org.junit.Test)

Example 24 with ExecutorCloser

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

the class BlobIdTrackerTest method setup.

@Before
public void setup() throws Exception {
    this.root = folder.newFolder();
    if (dataStore == null) {
        dataStore = getBlobStore(folder.newFolder());
    }
    this.repoId = randomUUID().toString();
    this.tracker = new BlobIdTracker(root.getAbsolutePath(), repoId, 100 * 60, dataStore);
    this.scheduler = newSingleThreadScheduledExecutor();
    closer.register(tracker);
    closer.register(new ExecutorCloser(scheduler));
}
Also used : ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) Before(org.junit.Before)

Example 25 with ExecutorCloser

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

the class FileCacheTest method retrieveSameConcurrent.

/**
     * Retrieves same file concurrently.
     * @throws Exception
     */
@Test
public void retrieveSameConcurrent() throws Exception {
    LOG.info("Started retrieveSameConcurrent");
    File f = createFile(0, 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 + 0, cache, thread2Start);
    thread1Start.countDown();
    thread2Start.countDown();
    future1.get();
    future2.get();
    LOG.info("Async tasks finished");
    assertCacheIfPresent(0, cache, f);
    assertCacheStats(cache, 1, 4 * 1024, 1, 1);
    LOG.info("Finished retrieveSameConcurrent");
}
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