Search in sources :

Example 21 with DataStoreBlobStore

use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.

the class DefaultIndexReaderFactoryTest method indexDirWithBlobStore.

@Test
public void indexDirWithBlobStore() throws Exception {
    /* Register a blob store */
    CachingFileDataStore ds = DataStoreUtils.createCachingFDS(folder.newFolder().getAbsolutePath(), folder.newFolder().getAbsolutePath());
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, new DataStoreBlobStore(ds));
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    writer.updateDocument("/content/en", newDoc("/content/en"));
    writer.close(0);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    assertEquals(1, readers.size());
    LuceneIndexReader reader = readers.get(0);
    assertNotNull(reader.getReader());
    assertNull(reader.getSuggestDirectory());
    assertNull(reader.getLookup());
    assertEquals(1, reader.getReader().numDocs());
    final AtomicBoolean closed = new AtomicBoolean();
    reader.getReader().addReaderClosedListener(new IndexReader.ReaderClosedListener() {

        @Override
        public void onClose(IndexReader reader) {
            closed.set(true);
        }
    });
    reader.close();
    assertTrue(closed.get());
}
Also used : LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) CachingFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexReader(org.apache.lucene.index.IndexReader) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Example 22 with DataStoreBlobStore

use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.

the class ExternalBlobIT method testDataStoreBlob.

@Test
public void testDataStoreBlob() throws Exception {
    FileDataStore fds = createFileDataStore();
    DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
    nodeStore = getNodeStore(dbs);
    //Test for Blob which get inlined
    Blob b1 = testCreateAndRead(createBlob(fds.getMinRecordLength() - 2));
    assertTrue(b1 instanceof SegmentBlob);
    assertNull(((SegmentBlob) b1).getBlobId());
    //Test for Blob which need to be pushed to BlobStore
    byte[] data2 = new byte[Segment.MEDIUM_LIMIT + 1];
    new Random().nextBytes(data2);
    Blob b2 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data2)));
    assertTrue(b2 instanceof SegmentBlob);
    assertNotNull(b2.getReference());
    assertEquals(b2.getContentIdentity(), ((SegmentBlob) b2).getBlobId());
    InputStream is = dbs.getInputStream(((SegmentBlob) b2).getBlobId());
    assertNotNull(IOUtils.contentEquals(new ByteArrayInputStream(data2), is));
    is.close();
}
Also used : FileBlob(org.apache.jackrabbit.oak.segment.file.FileBlob) Blob(org.apache.jackrabbit.oak.api.Blob) AbstractBlob(org.apache.jackrabbit.oak.plugins.memory.AbstractBlob) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Example 23 with DataStoreBlobStore

use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.

the class ExternalBlobIT method testSize.

@Test
public void testSize() throws Exception {
    FileDataStore fds = createFileDataStore();
    DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
    nodeStore = getNodeStore(dbs);
    int size = Segment.MEDIUM_LIMIT + 1;
    byte[] data2 = new byte[size];
    new Random().nextBytes(data2);
    Blob b = nodeStore.createBlob(new ByteArrayInputStream(data2));
    NodeBuilder builder = nodeStore.getRoot().builder();
    builder.child("hello").setProperty("world", b);
    nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    PropertyState ps = nodeStore.getRoot().getChildNode("hello").getProperty("world");
    // world = {2318851547697882338 bytes}
    assertEquals(size, ps.size());
// assertEquals("{" + size + " bytes}", ps.toString());
}
Also used : FileBlob(org.apache.jackrabbit.oak.segment.file.FileBlob) Blob(org.apache.jackrabbit.oak.api.Blob) AbstractBlob(org.apache.jackrabbit.oak.plugins.memory.AbstractBlob) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 24 with DataStoreBlobStore

use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.

the class ExternalBlobIT method testNullBlobId.

@Test
public void testNullBlobId() throws Exception {
    FileDataStore fds = createFileDataStore();
    DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
    nodeStore = getNodeStore(dbs);
    NodeBuilder nb = nodeStore.getRoot().builder();
    NodeBuilder cb = nb.child("hello");
    cb.setProperty("blob1", createBlob(Segment.MEDIUM_LIMIT - 1));
    int noOfBlobs = 4000;
    for (int i = 0; i < noOfBlobs; i++) {
        cb.setProperty("blob" + i, createBlob(Segment.MEDIUM_LIMIT + 1));
    }
    cb.setProperty("anotherBlob2", createBlob(Segment.MEDIUM_LIMIT + 1));
    cb.setProperty("anotherBlob3", createBlob(Segment.MEDIUM_LIMIT + 1));
    nodeStore.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    final List<String> refrences = Lists.newArrayList();
    store.collectBlobReferences(new ReferenceCollector() {

        @Override
        public void addReference(String reference, String nodeId) {
            assertNotNull(reference);
            refrences.add(reference);
        }
    });
    assertEquals(noOfBlobs + 2, refrences.size());
}
Also used : ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Example 25 with DataStoreBlobStore

use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore 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

DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)33 File (java.io.File)12 Properties (java.util.Properties)12 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)11 Test (org.junit.Test)10 DataStore (org.apache.jackrabbit.core.data.DataStore)5 OakFileDataStore (org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore)5 Before (org.junit.Before)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Random (java.util.Random)4 CachingFileDataStore (org.apache.jackrabbit.oak.plugins.blob.datastore.CachingFileDataStore)4 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)4 Blob (org.apache.jackrabbit.oak.api.Blob)3 AbstractBlob (org.apache.jackrabbit.oak.plugins.memory.AbstractBlob)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)3 Closer (com.google.common.io.Closer)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2