Search in sources :

Example 1 with DataStore

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

Example 2 with DataStore

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);
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 3 with DataStore

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

Example 4 with DataStore

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

Example 5 with DataStore

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

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