use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class DataStoreBlobStore method getDataRecord.
protected DataRecord getDataRecord(String blobId) throws DataStoreException {
DataRecord id;
if (InMemoryDataRecord.isInstance(blobId)) {
id = InMemoryDataRecord.getInstance(blobId);
} else {
id = delegate.getRecord(new DataIdentifier(blobId));
}
checkNotNull(id, "No DataRecord found for blobId [%s]", blobId);
return id;
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class S3DataStoreStatsTest method testGetMultilpleActiveS3FileSyncMetric.
@Test
public void testGetMultilpleActiveS3FileSyncMetric() throws Exception {
stats = new S3DataStoreStats();
stats.nodeStore = nodeStore;
stats.s3ds = manualSyncMockS3ds;
final Set<DataRecord> records = Sets.newHashSet();
try {
records.add(manualSyncMockS3ds.addRecord(getStream("test1")));
records.add(manualSyncMockS3ds.addRecord(getStream("test2")));
records.add(manualSyncMockS3ds.addRecord(getStream("test3")));
assertTrue(3 == stats.getActiveSyncs());
} finally {
for (final DataRecord record : records) {
manualSyncMockS3ds.deleteRecord(record.getIdentifier());
}
}
((ManuallySyncingInMemoryBackend) manualSyncMockS3ds.getBackend()).clearInProgressWrites();
assertTrue(0 == stats.getActiveSyncs());
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doAddRecordTest.
/**
* Test {@link DataStore#addRecord(InputStream)} and assert length of added
* record.
*/
protected void doAddRecordTest() throws Exception {
byte[] data = new byte[dataLength];
randomGen.nextBytes(data);
DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
Assert.assertEquals(data.length, rec.getLength());
assertRecord(data, rec);
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doTest.
/**
* Assert randomly read stream from record.
*/
void doTest(DataStore ds, int offset) throws Exception {
ArrayList<DataRecord> list = new ArrayList<DataRecord>();
HashMap<DataRecord, Integer> map = new HashMap<DataRecord, Integer>();
for (int i = 0; i < 10; i++) {
int size = 100000 - (i * 100);
RandomInputStream in = new RandomInputStream(size + offset, size);
DataRecord rec = ds.addRecord(in);
list.add(rec);
map.put(rec, size);
}
Random random = new Random(1);
for (int i = 0; i < list.size(); i++) {
int pos = random.nextInt(list.size());
DataRecord rec = list.get(pos);
int size = map.get(rec);
rec = ds.getRecord(rec.getIdentifier());
Assert.assertEquals(size, rec.getLength());
RandomInputStream expected = new RandomInputStream(size + offset, size);
InputStream in = rec.getStream();
// Workaround for race condition that can happen with low cache size relative to the test
// read immediately
byte[] buffer = new byte[1];
in.read(buffer);
in = new SequenceInputStream(new ByteArrayInputStream(buffer), in);
if (random.nextBoolean()) {
in = readInputStreamRandomly(in, random);
}
assertEquals(expected, in);
}
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doReferenceTest.
/**
* Test if record can be accessed via
* {@link DataStore#getRecordFromReference(String)}
*/
protected void doReferenceTest() throws Exception {
byte[] data = new byte[dataLength];
randomGen.nextBytes(data);
String reference;
DataRecord record = ds.addRecord(new ByteArrayInputStream(data));
reference = record.getReference();
assertReference(data, reference, ds);
}
Aggregations