Search in sources :

Example 11 with BlobStore

use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.

the class NodeStoreBinaryResourceProviderTest method countBinaries.

@Test
public void countBinaries() throws Exception {
    NodeBuilder builder = root.builder();
    createFileNode(builder, "a", new IdBlob("hello", null), "text/plain");
    createFileNode(builder, "b", new IdBlob("hello", "id1"), "text/plain");
    createFileNode(builder.child("a2"), "c", new IdBlob("hello", "id2"), "text/foo").setProperty(JcrConstants.JCR_ENCODING, "bar");
    NodeStore store = new MemoryNodeStore(builder.getNodeState());
    BlobStore blobStore = new MemoryBlobStore();
    NodeStoreBinaryResourceProvider extractor = new NodeStoreBinaryResourceProvider(store, blobStore);
    assertEquals(2, extractor.getBinaries("/").size());
    assertEquals(1, extractor.getBinaries("/a2").size());
    BinaryResource bs = extractor.getBinaries("/a2").first().get();
    assertEquals("text/foo", bs.getMimeType());
    assertEquals("bar", bs.getEncoding());
    assertEquals("id2", bs.getBlobId());
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Test(org.junit.Test)

Example 12 with BlobStore

use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.

the class NodeStoreBinaryResourceProviderTest method csvGenerator.

@Test
public void csvGenerator() throws Exception {
    File csv = new File(temporaryFolder.getRoot(), "test.csv");
    BlobStore blobStore = new MemoryBlobStore();
    NodeBuilder builder = root.builder();
    createFileNode(builder, "a", blobOf("foo", blobStore), "text/plain");
    createFileNode(builder, "b", blobOf("hello", blobStore), "text/plain");
    NodeStore store = new MemoryNodeStore(builder.getNodeState());
    NodeStoreBinaryResourceProvider extractor = new NodeStoreBinaryResourceProvider(store, blobStore);
    CSVFileGenerator generator = new CSVFileGenerator(csv);
    generator.generate(extractor.getBinaries("/"));
    CSVFileBinaryResourceProvider csvbrp = new CSVFileBinaryResourceProvider(csv, blobStore);
    assertEquals(2, csvbrp.getBinaries("/").size());
    csvbrp.close();
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) File(java.io.File) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Test(org.junit.Test)

Example 13 with BlobStore

use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.

the class DefaultStandbyBlobReaderTest method shouldReturnNullIfBlobDoesNotExist.

@Test
public void shouldReturnNullIfBlobDoesNotExist() throws Exception {
    BlobStore s = mock(BlobStore.class);
    when(s.getInputStream("id")).thenThrow(new IOException("blob not found"));
    DefaultStandbyBlobReader r = new DefaultStandbyBlobReader(s);
    assertNull(r.readBlob("id"));
}
Also used : IOException(java.io.IOException) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) Test(org.junit.Test)

Example 14 with BlobStore

use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.

the class DefaultStandbyBlobReaderTest method shouldReturnNullIfBlobIsUnreadable.

@Test
public void shouldReturnNullIfBlobIsUnreadable() throws Exception {
    BlobStore s = mock(BlobStore.class);
    when(s.getInputStream("id")).thenReturn(newFailingInputStream());
    DefaultStandbyBlobReader r = new DefaultStandbyBlobReader(s);
    assertNull(r.readBlob("id"));
}
Also used : BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) Test(org.junit.Test)

Example 15 with BlobStore

use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.

the class BlobStoreFixture method getDataStore.

public static BlobStoreFixture getDataStore(final File basedir, final int fdsCacheInMB, final StatisticsProvider statisticsProvider) {
    return new BlobStoreFixture("DS") {

        private DataStore dataStore;

        private BlobStore blobStore;

        private File storeDir;

        private Map<String, ?> config;

        @Override
        public BlobStore setUp() {
            String className = System.getProperty("dataStore");
            checkNotNull(className, "No system property named 'dataStore' defined");
            try {
                dataStore = Class.forName(className).asSubclass(DataStore.class).newInstance();
                config = getConfig();
                configure(dataStore, config);
                dataStore = configureIfCloudDataStore(className, dataStore, config, unique.toLowerCase(), statisticsProvider);
                storeDir = new File(basedir, unique);
                dataStore.init(storeDir.getAbsolutePath());
                blobStore = new DataStoreBlobStore(dataStore, true, fdsCacheInMB);
                configure(blobStore);
                return blobStore;
            } catch (Exception e) {
                throw new IllegalStateException("Cannot instantiate DataStore " + className, e);
            }
        }

        @Override
        public void tearDown() {
            if (blobStore instanceof DataStoreBlobStore) {
                try {
                    ((DataStoreBlobStore) blobStore).close();
                    cleanup(storeDir, config, unique.toLowerCase());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        @Override
        public long size() {
            throw new UnsupportedOperationException("Implementation pending");
        }
    };
}
Also used : DataStoreUtils.configureIfCloudDataStore(org.apache.jackrabbit.oak.fixture.DataStoreUtils.configureIfCloudDataStore) DataStore(org.apache.jackrabbit.core.data.DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) File(java.io.File) Map(java.util.Map) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) FileBlobStore(org.apache.jackrabbit.oak.spi.blob.FileBlobStore) IOException(java.io.IOException) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)

Aggregations

BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)31 Test (org.junit.Test)14 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)9 GarbageCollectableBlobStore (org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore)9 File (java.io.File)8 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataStoreUtils.getBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils.getBlobStore)6 IOException (java.io.IOException)5 MemoryBlobStore (org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore)4 DataStore (org.apache.jackrabbit.core.data.DataStore)3 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)3 Closer (com.google.common.io.Closer)2 Hashtable (java.util.Hashtable)2 Oak (org.apache.jackrabbit.oak.Oak)2 BlobTrackingStore (org.apache.jackrabbit.oak.plugins.blob.BlobTrackingStore)2 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)2 FileBlobStore (org.apache.jackrabbit.oak.spi.blob.FileBlobStore)2 DefaultSplitBlobStore (org.apache.jackrabbit.oak.spi.blob.split.DefaultSplitBlobStore)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2