use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doGetAllIdentifiersTest.
/**
* Test {@link DataStore#getAllIdentifiers()} and asserts all identifiers
* are returned.
*/
protected void doGetAllIdentifiersTest() throws Exception {
List<DataIdentifier> list = new ArrayList<DataIdentifier>();
Random random = randomGen;
byte[] data = new byte[dataLength];
random.nextBytes(data);
DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
list.add(rec.getIdentifier());
data = new byte[dataLength];
random.nextBytes(data);
rec = ds.addRecord(new ByteArrayInputStream(data));
list.add(rec.getIdentifier());
data = new byte[dataLength];
random.nextBytes(data);
rec = ds.addRecord(new ByteArrayInputStream(data));
list.add(rec.getIdentifier());
Iterator<DataIdentifier> itr = Sets.newHashSet(ds.getAllIdentifiers()).iterator();
while (itr.hasNext()) {
assertTrue("record found on list", list.remove(itr.next()));
}
Assert.assertEquals(0, list.size());
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doUpdateLastModifiedOnAccessTest.
/**
* Asserts that timestamp of all records accessed after
* {@link DataStore#updateModifiedDateOnAccess(long)} invocation.
*/
protected void doUpdateLastModifiedOnAccessTest() throws Exception {
Random random = randomGen;
byte[] data = new byte[dataLength];
random.nextBytes(data);
DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data));
data = new byte[dataLength];
random.nextBytes(data);
DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data));
LOG.debug("rec2 timestamp=" + rec2.getLastModified());
// sleep for some time to ensure that async upload completes in backend.
sleep(6000);
long updateTime = System.currentTimeMillis();
LOG.debug("updateTime=" + updateTime);
ds.updateModifiedDateOnAccess(updateTime);
// sleep to workaround System.currentTimeMillis granularity.
sleep(3000);
data = new byte[dataLength];
random.nextBytes(data);
DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data));
data = new byte[dataLength];
random.nextBytes(data);
DataRecord rec4 = ds.addRecord(new ByteArrayInputStream(data));
rec1 = ds.getRecord(rec1.getIdentifier());
Assert.assertEquals("rec1 touched", true, rec1.getLastModified() > updateTime);
LOG.debug("rec2 timestamp=" + rec2.getLastModified());
Assert.assertEquals("rec2 not touched", true, rec2.getLastModified() < updateTime);
Assert.assertEquals("rec3 touched", true, rec3.getLastModified() > updateTime);
Assert.assertEquals("rec4 touched", true, rec4.getLastModified() > updateTime);
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class CachingFileDataStoreTest method assertReferenceKey.
@Test
public void assertReferenceKey() 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);
DataRecord refRec = ds.getRecordFromReference(rec.getReference());
assertRecord(data, refRec);
// Check bytes retrieved from reference.key file
File refFile = new File(fsBackendPath, "reference.key");
assertTrue(refFile.exists());
byte[] keyRet = FileUtils.readFileToByteArray(refFile);
assertTrue(keyRet.length != 0);
}
use of org.apache.jackrabbit.core.data.DataRecord 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.DataRecord in project jackrabbit-oak by apache.
the class DataStoreBlobStoreTest method testInlineBinary.
@Test
public void testInlineBinary() throws DataStoreException, IOException {
int maxInlineSize = 300;
DataStore mockedDS = mock(DataStore.class);
when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize);
DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
byte[] data = new byte[maxInlineSize];
new Random().nextBytes(data);
DataRecord dr = ds.addRecord(new ByteArrayInputStream(data));
assertTrue(InMemoryDataRecord.isInstance(dr.getIdentifier().toString()));
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), dr.getStream()));
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), new BlobStoreInputStream(ds, dr.getIdentifier().toString(), 0)));
assertEquals(dr, ds.getRecordIfStored(dr.getIdentifier()));
assertEquals(dr, ds.getRecord(dr.getIdentifier()));
//Check for BlobStore methods
assertEquals(maxInlineSize, ds.getBlobLength(dr.getIdentifier().toString()));
assertEquals(dr.getIdentifier().toString(), BlobId.of(ds.writeBlob(new ByteArrayInputStream(data))).blobId);
}
Aggregations