Search in sources :

Example 16 with DataStore

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());
}
Also used : DataStore(org.apache.jackrabbit.core.data.DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) File(java.io.File) Test(org.junit.Test)

Example 17 with DataStore

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);
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreInputStream(org.apache.jackrabbit.oak.spi.blob.BlobStoreInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataStore(org.apache.jackrabbit.core.data.DataStore) BlobStoreInputStream(org.apache.jackrabbit.oak.spi.blob.BlobStoreInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) AbstractBlobStoreTest(org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest) Test(org.junit.Test)

Example 18 with DataStore

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());
}
Also used : HashMap(java.util.HashMap) DataStore(org.apache.jackrabbit.core.data.DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) Test(org.junit.Test)

Example 19 with DataStore

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);
}
Also used : DataStore(org.apache.jackrabbit.core.data.DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore)

Example 20 with DataStore

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));
}
Also used : SharedBackend(org.apache.jackrabbit.oak.spi.blob.SharedBackend) DataStore(org.apache.jackrabbit.core.data.DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

DataStore (org.apache.jackrabbit.core.data.DataStore)22 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)9 Test (org.junit.Test)8 File (java.io.File)7 Properties (java.util.Properties)6 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)5 IOException (java.io.IOException)4 RepositoryException (javax.jcr.RepositoryException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 Random (java.util.Random)3 DataRecord (org.apache.jackrabbit.core.data.DataRecord)3 SharedS3DataStore (org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore)3 AbstractBlobStoreTest (org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest)3 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)3 Closer (com.google.common.io.Closer)2 OptionParser (joptsimple.OptionParser)2 OptionSet (joptsimple.OptionSet)2 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2