use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class DataStoreBlobStoreTest method testReference.
@Test
public void testReference() throws DataStoreException, IOException {
String reference = "testReference";
String blobId = "test";
DataIdentifier testDI = new DataIdentifier(blobId);
DataRecord testDR = new ByteArrayDataRecord("foo".getBytes(), testDI, reference);
DataStore mockedDS = mock(DataStore.class);
when(mockedDS.getRecordFromReference(reference)).thenReturn(testDR);
when(mockedDS.getRecord(testDI)).thenReturn(testDR);
when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR);
DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
assertEquals(reference, ds.getReference(blobId));
assertEquals(blobId, BlobId.of(ds.getBlobId(reference)).blobId);
assertEquals(BlobId.of(testDR).encodedValue(), ds.getBlobId(reference));
String inMemBlobId = InMemoryDataRecord.getInstance("foo".getBytes()).getIdentifier().toString();
//For in memory record the reference should be null
assertNull(ds.getReference(inMemBlobId));
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class SharedDataStoreUtilsTest method assertRecords.
private static void assertRecords(Set<DataRecord> expected, Set<DataRecord> retrieved) throws DataStoreException, IOException {
//assert streams
Map<DataIdentifier, DataRecord> retMap = Maps.newHashMap();
for (DataRecord ret : retrieved) {
retMap.put(ret.getIdentifier(), ret);
}
for (DataRecord rec : expected) {
assertEquals("Record id different for " + rec.getIdentifier(), rec.getIdentifier(), retMap.get(rec.getIdentifier()).getIdentifier());
assertEquals("Record length different for " + rec.getIdentifier(), rec.getLength(), retMap.get(rec.getIdentifier()).getLength());
assertEquals("Record lastModified different for " + rec.getIdentifier(), rec.getLastModified(), retMap.get(rec.getIdentifier()).getLastModified());
assertTrue("Record steam different for " + rec.getIdentifier(), IOUtils.contentEquals(rec.getStream(), retMap.get(rec.getIdentifier()).getStream()));
}
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class CachingDataStoreTest method zeroStagingCacheAddGetDelete.
/**
* Add, get, delete when staging cache is 0.
* @throws Exception
*/
@Test
public void zeroStagingCacheAddGetDelete() throws Exception {
LOG.info("Starting zeroStagingCacheAddGetDelete");
dataStore.close();
init(1, 64 * 1024 * 1024, 0);
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));
assertEquals(id, rec.getIdentifier().toString());
assertFile(rec.getStream(), f, folder);
assertEquals(1, Iterators.size(dataStore.getAllIdentifiers()));
dataStore.deleteRecord(new DataIdentifier(id));
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNull(rec);
LOG.info("Finished zeroStagingCacheAddGetDelete");
}
use of org.apache.jackrabbit.core.data.DataIdentifier 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.DataIdentifier 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");
}
Aggregations