Search in sources :

Example 1 with BlobStore

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

the class CacheTest method test.

@Test
public void test() throws Exception {
    FileUtils.deleteDirectory(new File("target/cacheTest"));
    PersistentCache cache = new PersistentCache("target/cacheTest,size=1,-compress");
    try {
        MemoryBlobStore mem = new MemoryBlobStore();
        mem.setBlockSizeMin(100);
        BlobStore b = cache.wrapBlobStore(mem);
        Random r = new Random();
        for (int i = 0; i < 10000; i++) {
            byte[] data = new byte[100];
            r.nextBytes(data);
            String id = b.writeBlob(new ByteArrayInputStream(data));
            b.readBlob(id, 0, new byte[1], 0, 1);
        }
    } finally {
        cache.close();
    }
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) 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 2 with BlobStore

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

the class SplitBlobStoreService method registerSplitBlobStore.

private void registerSplitBlobStore() {
    if (oldBlobStore == null && oldBlobStoreType == BlobStoreType.EXTERNAL) {
        log.info("No BlobStore with ({}=old)", PROP_SPLIT_BLOBSTORE);
        return;
    }
    if (newBlobStore == null) {
        log.info("No BlobStore with ({}=new)", PROP_SPLIT_BLOBSTORE);
        return;
    }
    if (reg != null) {
        log.info("SplitBlobStore already registered");
        return;
    }
    if (ctx == null) {
        log.info("Component not activated yet");
        return;
    }
    log.info("Registering SplitBlobStore with old={} ({}) and new={}", oldBlobStore, oldBlobStoreType, newBlobStore);
    BlobStore blobStore;
    if (oldBlobStoreType == EXTERNAL || oldBlobStoreType == SEGMENT) {
        blobStore = new DefaultSplitBlobStore(homeDir, oldBlobStore, newBlobStore);
    } else if (oldBlobStoreType == DOCUMENT) {
        blobStore = new WrappingSplitBlobStore(homeDir, newBlobStore);
    } else {
        throw new IllegalStateException("Illegal blob store type value: " + oldBlobStoreType);
    }
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("service.pid", "org.apache.jackrabbit.oak.spi.blob.split.SplitBlobStore");
    reg = ctx.registerService(new String[] { BlobStore.class.getName() }, blobStore, props);
}
Also used : DefaultSplitBlobStore(org.apache.jackrabbit.oak.spi.blob.split.DefaultSplitBlobStore) Hashtable(java.util.Hashtable) WrappingSplitBlobStore(org.apache.jackrabbit.oak.spi.blob.split.WrappingSplitBlobStore) DefaultSplitBlobStore(org.apache.jackrabbit.oak.spi.blob.split.DefaultSplitBlobStore) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) WrappingSplitBlobStore(org.apache.jackrabbit.oak.spi.blob.split.WrappingSplitBlobStore)

Example 3 with BlobStore

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

the class AbstractBlobTrackerRegistrationTest method reRegisterBlobTrackingStore.

@Test
public void reRegisterBlobTrackingStore() throws Exception {
    registerNodeStoreService();
    assertServiceNotActivated();
    registerTrackingBlobStore();
    assertServiceActivated();
    BlobStore blobStore = context.getService(BlobStore.class);
    assertTrue(blobStore instanceof BlobTrackingStore);
    BlobTrackingStore trackingStore = (BlobTrackingStore) blobStore;
    assertNotNull(trackingStore.getTracker());
    BlobTracker oldTracker = trackingStore.getTracker();
    unregisterNodeStoreService();
    registerNodeStoreService();
    blobStore = context.getService(BlobStore.class);
    trackingStore = (BlobTrackingStore) blobStore;
    BlobTracker newTracker = trackingStore.getTracker();
    assertNotEquals(oldTracker, newTracker);
    assertTrackerReinitialized();
}
Also used : BlobTracker(org.apache.jackrabbit.oak.plugins.blob.datastore.BlobTracker) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Example 4 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 5 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)

Aggregations

BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)49 Test (org.junit.Test)28 GarbageCollectableBlobStore (org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore)14 File (java.io.File)11 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)11 DataStoreUtils.getBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils.getBlobStore)11 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)8 IOException (java.io.IOException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Parameters (junitparams.Parameters)4 MemoryBlobStore (org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore)4 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 Closer (com.google.common.io.Closer)3 InputStream (java.io.InputStream)3 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)3 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)3 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)2 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)2 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)2 Hashtable (java.util.Hashtable)2