use of org.apache.jackrabbit.core.data.DataStore 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.DataStore 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);
}
use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.
the class DataStoreBlobStoreTest method testAddOnTrackError.
@Test
public void testAddOnTrackError() throws Exception {
int maxInlineSize = 300;
byte[] data = new byte[maxInlineSize];
new Random().nextBytes(data);
DataStore mockedDS = mock(DataStore.class);
when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize);
DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
BlobIdTracker mockedTracker = mock(BlobIdTracker.class);
doThrow(new IOException("Mocking tracking error")).when(mockedTracker).add(any(String.class));
ds.addTracker(mockedTracker);
String id = ds.writeBlob(new ByteArrayInputStream(data));
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), ds.getInputStream(id)));
}
use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.
the class DataStoreServiceTest method getAssertCachingFileDataStore.
private DataStore getAssertCachingFileDataStore(String nasPath, String cachePath) throws RepositoryException {
long cacheSize = 100L;
Map<String, Object> config = new HashMap<String, Object>();
config.put("repository.home", folder.getRoot().getAbsolutePath());
config.put(FileDataStoreService.CACHE_SIZE, cacheSize);
config.put(FileDataStoreService.PATH, nasPath);
config.put(FileDataStoreService.CACHE_PATH, cachePath);
FileDataStoreService fdsSvc = new FileDataStoreService();
DataStore ds = fdsSvc.createDataStore(context.componentContext(), config);
PropertiesUtil.populate(ds, config, false);
ds.init(folder.getRoot().getAbsolutePath());
assertTrue("not instance of CachingFDS", ds instanceof CachingFileDataStore);
return ds;
}
use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.
the class TestAzureDS method createDataStore.
@Override
protected DataStore createDataStore() throws RepositoryException {
DataStore azureds = null;
try {
azureds = AzureDataStoreUtils.getAzureDataStore(props, dataStoreDir);
} catch (Exception e) {
e.printStackTrace();
}
sleep(1000);
return azureds;
}
Aggregations