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