use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class CachingDataStoreTest method addStagingAndDelete.
/**
* Add in staging and delete.
* @throws Exception
*/
@Test
public void addStagingAndDelete() throws Exception {
LOG.info("Starting addStagingAndDelete");
File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
String id = getIdForInputStream(f);
FileInputStream fin = new FileInputStream(f);
closer.register(fin);
DataRecord rec = dataStore.addRecord(fin);
assertEquals(id, rec.getIdentifier().toString());
assertFile(rec.getStream(), f, folder);
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNotNull(rec);
assertFile(rec.getStream(), f, folder);
dataStore.deleteRecord(new DataIdentifier(id));
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNull(rec);
Thread.sleep(1000);
//start & finish
taskLatch.countDown();
callbackLatch.countDown();
waitFinish();
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNull(rec);
LOG.info("Finished addStagingAndDelete");
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class CachingDataStoreTest method getRecordNotAvailable.
/**
* {@link CompositeDataStoreCache#getIfPresent(String)} when no record.
*/
@Test
public void getRecordNotAvailable() throws DataStoreException {
LOG.info("Starting getRecordNotAvailable");
DataRecord rec = dataStore.getRecordIfStored(new DataIdentifier(ID_PREFIX + 0));
assertNull(rec);
LOG.info("Finished getRecordNotAvailable");
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class CachingDataStoreTest method getAllIdentifiers.
/**
* Get all Identifiers.
*/
@Test
public void getAllIdentifiers() throws Exception {
LOG.info("Starting getAllIdentifiers");
File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
String id = getIdForInputStream(f);
FileInputStream fin = new FileInputStream(f);
closer.register(fin);
DataRecord rec = dataStore.addRecord(fin);
assertEquals(id, rec.getIdentifier().toString());
assertTrue(Iterators.contains(dataStore.getAllIdentifiers(), new DataIdentifier(id)));
//start & finish
taskLatch.countDown();
callbackLatch.countDown();
waitFinish();
assertTrue(Iterators.contains(dataStore.getAllIdentifiers(), new DataIdentifier(id)));
LOG.info("Finished getAllIdentifiers");
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class CachingDataStoreTest method syncAddGetLoadCache.
/**
* Add, get forcing load in cache.
* @throws Exception
*/
@Test
public void syncAddGetLoadCache() throws Exception {
LOG.info("Starting syncAddGetForceFromCache");
File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
String id = getIdForInputStream(f);
FileInputStream fin = new FileInputStream(f);
closer.register(fin);
DataRecord rec = dataStore.addRecord(fin, new BlobOptions().setUpload(SYNCHRONOUS));
assertEquals(id, rec.getIdentifier().toString());
assertFile(rec.getStream(), f, folder);
// Invalidate from the local cache
dataStore.getCache().invalidate(id);
// Trigger load from backend
File cacheDownloaded = dataStore.getCache().get(id);
assertTrue(Files.equal(f, cacheDownloaded));
assertEquals(1, Iterators.size(dataStore.getAllIdentifiers()));
LOG.info("Finished syncAddGetLoadCache");
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class CachingDataStoreTest method lazyLoadStream.
/**
* Add in datastore, invalidate from cache and lazy load record stream.
*/
@Test
public void lazyLoadStream() throws Exception {
LOG.info("Starting lazyLoadStream");
File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
String id = getIdForInputStream(f);
FileInputStream fin = new FileInputStream(f);
closer.register(fin);
DataRecord rec = dataStore.addRecord(fin);
assertEquals(id, rec.getIdentifier().toString());
//start & finish
taskLatch.countDown();
callbackLatch.countDown();
waitFinish();
// Invalidate from the local cache
dataStore.getCache().invalidate(id);
// retrieve record from the datastore
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNotNull(rec);
assertEquals(id, rec.getIdentifier().toString());
// the file should not be in cache
File cached = dataStore.getCache().getIfPresent(id);
assertNull(cached);
// assert stream
assertFile(rec.getStream(), f, folder);
// Now should be available in the cache
cached = dataStore.getCache().getIfPresent(id);
assertNotNull(cached);
assertTrue(Files.equal(f, cached));
dataStore.deleteRecord(new DataIdentifier(id));
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNull(rec);
LOG.info("Finished lazyLoadStream");
}
Aggregations