Search in sources :

Example 1 with BlobStoreInputStream

use of org.apache.jackrabbit.oak.spi.blob.BlobStoreInputStream 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 2 with BlobStoreInputStream

use of org.apache.jackrabbit.oak.spi.blob.BlobStoreInputStream 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 Random (java.util.Random)2 DataRecord (org.apache.jackrabbit.core.data.DataRecord)2 DataStore (org.apache.jackrabbit.core.data.DataStore)2 AbstractBlobStoreTest (org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest)2 BlobStoreInputStream (org.apache.jackrabbit.oak.spi.blob.BlobStoreInputStream)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)1