use of org.apache.jackrabbit.core.data.DataIdentifier 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.DataIdentifier 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);
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit by apache.
the class VFSBackend method deleteOlderRecursive.
/**
* Deletes any descendant record files under {@code folderObject} if the record files are older than {@code timestamp},
* and push all the deleted record identifiers into {@code deleteIdSet}.
* @param deleteIdSet set to store all the deleted record identifiers
* @param folderObject folder object to start with
* @param timestamp timestamp
* @throws FileSystemException if any file system exception occurs
* @throws DataStoreException if any file system exception occurs
*/
private void deleteOlderRecursive(Set<DataIdentifier> deleteIdSet, FileObject folderObject, long timestamp) throws FileSystemException, DataStoreException {
FileType type;
DataIdentifier identifier;
for (FileObject fileObject : VFSUtils.getChildFileOrFolders(folderObject)) {
type = fileObject.getType();
if (type == FileType.FOLDER) {
deleteOlderRecursive(deleteIdSet, fileObject, timestamp);
synchronized (this) {
if (!VFSUtils.hasAnyChildFileOrFolder(fileObject)) {
fileObject.delete();
}
}
} else if (type == FileType.FILE) {
long lastModified = getLastModifiedTime(fileObject);
if (lastModified < timestamp) {
identifier = new DataIdentifier(fileObject.getName().getBaseName());
if (getDataStore().confirmDelete(identifier)) {
getDataStore().deleteFromCache(identifier);
if (LOG.isInfoEnabled()) {
LOG.info("Deleting old file " + fileObject.getName().getFriendlyURI() + " modified: " + new Timestamp(lastModified).toString() + " length: " + fileObject.getContent().getSize());
}
if (deleteRecordFileObject(fileObject)) {
deleteIdSet.add(identifier);
} else {
LOG.warn("Failed to delete old file " + fileObject.getName().getFriendlyURI());
}
}
}
}
}
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class AzureDataStoreTest method testBackendGetRecordInvalidIdentifierThrowsDataStoreException.
@Test
public void testBackendGetRecordInvalidIdentifierThrowsDataStoreException() {
try {
backend.getRecord(new DataIdentifier("invalid"));
fail();
} catch (DataStoreException e) {
}
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class AzureDataStoreTest method testBackendGetAllRecordsReturnsAll.
// GetAllRecords (Backend)
@Test
public void testBackendGetAllRecordsReturnsAll() throws DataStoreException, IOException {
for (int recCount : Lists.newArrayList(0, 1, 2, 5)) {
Map<DataIdentifier, String> addedRecords = Maps.newHashMap();
if (0 < recCount) {
for (int i = 0; i < recCount; i++) {
String data = String.format("testData%d", i);
DataRecord record = ds.addRecord(new ByteArrayInputStream(data.getBytes()));
addedRecords.put(record.getIdentifier(), data);
}
}
Iterator<DataRecord> iter = backend.getAllRecords();
List<DataIdentifier> identifiers = Lists.newArrayList();
int actualCount = 0;
while (iter.hasNext()) {
DataRecord record = iter.next();
identifiers.add(record.getIdentifier());
assertTrue(addedRecords.containsKey(record.getIdentifier()));
StringWriter writer = new StringWriter();
IOUtils.copy(record.getStream(), writer);
assertTrue(writer.toString().equals(addedRecords.get(record.getIdentifier())));
actualCount++;
}
for (DataIdentifier identifier : identifiers) {
ds.deleteRecord(identifier);
}
assertEquals(recCount, actualCount);
}
}
Aggregations