use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.
the class DataStoreServiceTest method registerAndCheckReferenceKey.
/**
* Tests the regitration of CachingFileDataStore and checks existence of
* reference.key file on first access of getOrCreateReference.
* @throws Exception
*/
@Test
public void registerAndCheckReferenceKey() throws Exception {
context.registerService(StatisticsProvider.class, StatisticsProvider.NOOP);
String nasPath = folder.getRoot().getAbsolutePath() + "/NASPath";
String cachePath = folder.getRoot().getAbsolutePath() + "/cachePath";
DataStore ds = getAssertCachingFileDataStore(nasPath, cachePath);
final CachingFileDataStore dataStore = (CachingFileDataStore) ds;
byte[] key = dataStore.getBackend().getOrCreateReferenceKey();
// Check bytes retrieved from reference.key file
File refFile = new File(nasPath, "reference.key");
byte[] keyRet = FileUtils.readFileToByteArray(refFile);
assertArrayEquals(key, keyRet);
assertArrayEquals(key, dataStore.getBackend().getOrCreateReferenceKey());
}
use of org.apache.jackrabbit.core.data.DataStore 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.DataStore in project jackrabbit-oak by apache.
the class DataStoreServiceTest method configFileDataStore.
/**
*
* Test to verify @FileDataStore is returned if cacheSize is not configured.
*/
@Test
public void configFileDataStore() throws Exception {
String nasPath = folder.getRoot().getAbsolutePath() + "/NASPath";
String cachePath = folder.getRoot().getAbsolutePath() + "/cachePath";
Map<String, Object> config = new HashMap<String, Object>();
config.put("repository.home", folder.getRoot().getAbsolutePath());
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 FileDataStore", ds instanceof FileDataStore);
FileDataStore fds = (FileDataStore) ds;
assertEquals("path not equal", nasPath, fds.getPath());
}
use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.
the class DataStoreUtils method getBlobStore.
public static DataStoreBlobStore getBlobStore(String homeDir) throws Exception {
String className = System.getProperty(DS_CLASS_NAME, OakFileDataStore.class.getName());
DataStore ds = Class.forName(className).asSubclass(DataStore.class).newInstance();
PropertiesUtil.populate(ds, getConfig(), false);
ds.init(homeDir);
return new DataStoreBlobStore(ds);
}
use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.
the class DataStoreServiceTest method configCachingFileDataStore.
/**
*
* Test {@link CachingFileDataStore} is returned when cacheSize > 0 by default.
*/
@Test
public void configCachingFileDataStore() throws Exception {
String nasPath = folder.getRoot().getAbsolutePath() + "/NASPath";
String cachePath = folder.getRoot().getAbsolutePath() + "/cachePath";
DataStore ds = getAssertCachingFileDataStore(nasPath, cachePath);
CachingFileDataStore cds = (CachingFileDataStore) ds;
SharedBackend backend = cds.getBackend();
Properties props = (Properties) getField(backend);
assertEquals("path not equal", nasPath, props.getProperty(FSBackend.FS_BACKEND_PATH));
}
Aggregations