use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doDeleteAllOlderThan.
/**
* Asserts that {@link DataStore#deleteAllOlderThan(long)} only deleted
* records older than argument passed.
*/
protected void doDeleteAllOlderThan() 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));
// sleep for some time to ensure that async upload completes in backend.
sleep(10000);
long updateTime = System.currentTimeMillis();
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());
ds.clearInUse();
Assert.assertEquals("only rec2 should be deleted", 1, ds.deleteAllOlderThan(updateTime));
assertNull("rec2 should be null", ds.getRecordIfStored(rec2.getIdentifier()));
Iterator<DataIdentifier> itr = ds.getAllIdentifiers();
List<DataIdentifier> list = new ArrayList<DataIdentifier>();
list.add(rec1.getIdentifier());
list.add(rec3.getIdentifier());
list.add(rec4.getIdentifier());
while (itr.hasNext()) {
assertTrue("record found on list", list.remove(itr.next()));
}
Assert.assertEquals("touched records found", 0, list.size());
Assert.assertEquals("rec1 touched", true, rec1.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 SharedDataStoreUtilsTest method testAddMetadata.
@Test
public void testAddMetadata() throws Exception {
File rootFolder = folder.newFolder();
dataStore = getBlobStore(rootFolder);
String repoId = UUID.randomUUID().toString();
Set<String> refs = Sets.newHashSet("1_1", "1_2");
File f = folder.newFile();
FileIOUtils.writeStrings(refs.iterator(), f, false);
dataStore.addMetadataRecord(new FileInputStream(f), SharedStoreRecordType.REFERENCES.getNameFromId(repoId));
DataRecord rec = dataStore.getMetadataRecord(SharedStoreRecordType.REFERENCES.getNameFromId(repoId));
Set<String> refsReturned = FileIOUtils.readStringsAsSet(rec.getStream(), false);
Assert.assertEquals(refs, refsReturned);
dataStore.deleteAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType());
dataStore.addMetadataRecord(f, SharedStoreRecordType.REFERENCES.getNameFromId(repoId));
rec = dataStore.getMetadataRecord(SharedStoreRecordType.REFERENCES.getNameFromId(repoId));
refsReturned = FileIOUtils.readStringsAsSet(rec.getStream(), false);
Assert.assertEquals(refs, refsReturned);
assertEquals(SharedStoreRecordType.REFERENCES.getIdFromName(rec.getIdentifier().toString()), repoId);
dataStore.deleteAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType());
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class SharedDataStoreUtilsTest method testStreamFromGetAllRecords.
@Test
public void testStreamFromGetAllRecords() 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((dataStore.getAllRecords()));
assertRecords(added, retrieved);
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class DataStoreBlobStoreTest method testGetAllChunks.
@Test
public void testGetAllChunks() throws Exception {
DataIdentifier d10 = new DataIdentifier("d-10");
DataIdentifier d20 = new DataIdentifier("d-20");
DataIdentifier d30 = new DataIdentifier("d-30");
List<DataIdentifier> dis = ImmutableList.of(d10, d20, d30);
List<DataRecord> recs = Lists.newArrayList(Iterables.transform(dis, new Function<DataIdentifier, DataRecord>() {
@Nullable
@Override
public DataRecord apply(@Nullable DataIdentifier input) {
return new TimeDataRecord(input);
}
}));
OakFileDataStore mockedDS = mock(OakFileDataStore.class);
when(mockedDS.getAllRecords()).thenReturn(recs.iterator());
when(mockedDS.getRecord(new DataIdentifier("d-10"))).thenReturn(new TimeDataRecord(d10));
when(mockedDS.getRecord(new DataIdentifier("d-20"))).thenReturn(new TimeDataRecord(d20));
when(mockedDS.getRecord(new DataIdentifier("d-30"))).thenReturn(new TimeDataRecord(d30));
DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
Iterator<String> chunks = ds.getAllChunkIds(25);
Set<String> expected = Sets.newHashSet("d-10", "d-20");
assertEquals(expected, Sets.newHashSet(chunks));
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class DataStoreBlobStoreTest method testExternalBinary.
@Test
public void testExternalBinary() throws DataStoreException, IOException {
int maxInlineSize = 300;
int actualSize = maxInlineSize + 10;
byte[] data = new byte[actualSize];
new Random().nextBytes(data);
DataIdentifier testDI = new DataIdentifier("test");
DataRecord testDR = new ByteArrayDataRecord(data, testDI, "testReference");
DataStore mockedDS = mock(DataStore.class);
when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize);
when(mockedDS.getRecord(testDI)).thenReturn(testDR);
when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR);
when(mockedDS.addRecord(any(InputStream.class))).thenReturn(testDR);
DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
DataRecord dr = ds.addRecord(new ByteArrayInputStream(data));
assertFalse(InMemoryDataRecord.isInstance(dr.getIdentifier().toString()));
assertEquals(testDI, dr.getIdentifier());
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()));
// assertTrue(ds.getInputStream(dr.getIdentifier().toString()) instanceof BufferedInputStream);
assertEquals(actualSize, ds.getBlobLength(dr.getIdentifier().toString()));
assertEquals(testDI.toString(), BlobId.of(ds.writeBlob(new ByteArrayInputStream(data))).blobId);
}
Aggregations