use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class SharedDataStoreUtilsTest method test.
@Test
public void test() throws Exception {
File rootFolder = folder.newFolder();
dataStore = getBlobStore(rootFolder);
String repoId1 = UUID.randomUUID().toString();
String repoId2 = UUID.randomUUID().toString();
// Add repository records
dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REPOSITORY.getNameFromId(repoId1));
DataRecord repo1 = dataStore.getMetadataRecord(SharedStoreRecordType.REPOSITORY.getNameFromId(repoId1));
dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REPOSITORY.getNameFromId(repoId2));
DataRecord repo2 = dataStore.getMetadataRecord(SharedStoreRecordType.REPOSITORY.getNameFromId(repoId2));
// Add reference marker record for repo1
dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.MARKED_START_MARKER.getNameFromId(repoId1));
DataRecord markerRec1 = dataStore.getMetadataRecord(SharedStoreRecordType.MARKED_START_MARKER.getNameFromId(repoId1));
assertEquals(SharedStoreRecordType.MARKED_START_MARKER.getIdFromName(markerRec1.getIdentifier().toString()), repoId1);
long lastModifiedMarkerRec1 = markerRec1.getLastModified();
TimeUnit.MILLISECONDS.sleep(100);
// Add reference records
dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REFERENCES.getNameFromId(repoId1));
DataRecord rec1 = dataStore.getMetadataRecord(SharedStoreRecordType.REFERENCES.getNameFromId(repoId1));
long lastModifiedRec1 = rec1.getLastModified();
TimeUnit.MILLISECONDS.sleep(25);
dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REFERENCES.getNameFromId(repoId2));
DataRecord rec2 = dataStore.getMetadataRecord(SharedStoreRecordType.REFERENCES.getNameFromId(repoId2));
long lastModifiedRec2 = rec2.getLastModified();
assertEquals(SharedStoreRecordType.REPOSITORY.getIdFromName(repo1.getIdentifier().toString()), repoId1);
assertEquals(SharedStoreRecordType.REPOSITORY.getIdFromName(repo2.getIdentifier().toString()), repoId2);
assertEquals(SharedStoreRecordType.REFERENCES.getIdFromName(rec1.getIdentifier().toString()), repoId1);
assertEquals(SharedStoreRecordType.REFERENCES.getIdFromName(rec2.getIdentifier().toString()), repoId2);
// All the references from registered repositories are available
Assert.assertTrue(SharedDataStoreUtils.refsNotAvailableFromRepos(dataStore.getAllMetadataRecords(SharedStoreRecordType.REPOSITORY.getType()), dataStore.getAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType())).isEmpty());
// Since, we don't care about which file specifically but only the earliest timestamped record
// Earliest time should be the min timestamp from the 2 reference files
long minRefTime = (lastModifiedRec1 <= lastModifiedRec2 ? lastModifiedRec1 : lastModifiedRec2);
assertEquals(SharedDataStoreUtils.getEarliestRecord(dataStore.getAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType())).getLastModified(), minRefTime);
// the marker timestamp should be the minimum
long minMarkerTime = SharedDataStoreUtils.getEarliestRecord(dataStore.getAllMetadataRecords(SharedStoreRecordType.MARKED_START_MARKER.getType())).getLastModified();
Assert.assertTrue(minRefTime >= minMarkerTime);
// Delete references and check back if deleted
dataStore.deleteAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType());
Assert.assertTrue(dataStore.getAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType()).isEmpty());
// Delete markers and check back if deleted
dataStore.deleteAllMetadataRecords(SharedStoreRecordType.MARKED_START_MARKER.getType());
Assert.assertTrue(dataStore.getAllMetadataRecords(SharedStoreRecordType.MARKED_START_MARKER.getType()).isEmpty());
// Repository ids should still be available
assertEquals(2, dataStore.getAllMetadataRecords(SharedStoreRecordType.REPOSITORY.getType()).size());
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class SharedDataStoreUtilsTest method testGetAllRecords.
@Test
public void testGetAllRecords() throws Exception {
File rootFolder = folder.newFolder();
dataStore = getBlobStore(rootFolder);
int number = 10;
Set<String> added = newHashSet();
for (int i = 0; i < number; i++) {
String rec = dataStore.addRecord(randomStream(i, 16516)).getIdentifier().toString();
added.add(rec);
}
Set<String> retrieved = newHashSet(Iterables.transform(newHashSet(dataStore.getAllRecords()), new Function<DataRecord, String>() {
@Nullable
@Override
public String apply(@Nullable DataRecord input) {
return input.getIdentifier().toString();
}
}));
assertEquals(added, retrieved);
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class SharedDataStoreUtilsTest method testGetRecordForId.
@Test
public void testGetRecordForId() throws Exception {
File rootFolder = folder.newFolder();
dataStore = getBlobStore(rootFolder);
int number = 10;
Set<DataRecord> added = newHashSet();
for (int i = 0; i < number; i++) {
added.add(dataStore.addRecord(randomStream(i, 16516)));
}
Set<DataRecord> retrieved = newHashSet();
for (DataRecord rec : added) {
retrieved.add(dataStore.getRecordForId(rec.getIdentifier()));
}
assertRecords(added, retrieved);
}
use of org.apache.jackrabbit.core.data.DataRecord 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.DataRecord 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");
}
Aggregations