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();
}
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)));
}
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");
}
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");
}
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");
}
Aggregations