Search in sources :

Example 11 with FileDataStore

use of org.apache.jackrabbit.core.data.FileDataStore in project jackrabbit-oak by apache.

the class LengthCachingDataStoreTest method writeBackNewEntries.

@Test
public void writeBackNewEntries() throws Exception {
    //1. Add some entries to FDS
    FileDataStore fds1 = new FileDataStore();
    File fds1Dir = tempFolder.newFolder();
    int minSize = fds1.getMinRecordLength();
    fds1.init(fds1Dir.getAbsolutePath());
    DataRecord dr1 = fds1.addRecord(byteStream(minSize + 10));
    DataRecord dr2 = fds1.addRecord(byteStream(minSize + 100));
    //2. Try reading them so as to populate the new mappings
    LengthCachingDataStore fds2 = new LengthCachingDataStore();
    fds2.setDelegateClass(FileDataStore.class.getName());
    fds2.init(fds1Dir.getAbsolutePath());
    fds2.getRecord(new DataIdentifier(dr1.getIdentifier().toString()));
    fds2.getRecord(new DataIdentifier(dr2.getIdentifier().toString()));
    File mappingFile = fds2.getMappingFile();
    //3. Get the mappings pushed to file
    fds2.close();
    //4. Open a new FDS pointing to new directory. Read should still work fine
    //as they would be served by the mapping data
    LengthCachingDataStore fds3 = new LengthCachingDataStore();
    fds3.setDelegateClass(FileDataStore.class.getName());
    fds3.setMappingFilePath(mappingFile.getAbsolutePath());
    fds3.init(tempFolder.newFolder().getAbsolutePath());
    fds3.setReadOnly(false);
    assertEquals(dr1.getLength(), fds3.getRecord(dr1.getIdentifier()).getLength());
    assertEquals(dr2.getLength(), fds3.getRecord(dr2.getIdentifier()).getLength());
    DataRecord dr3 = fds3.addRecord(byteStream(minSize + 200));
    //5. Close again so see if update of existing file works
    fds3.close();
    LengthCachingDataStore fds4 = new LengthCachingDataStore();
    fds4.setDelegateClass(FileDataStore.class.getName());
    fds4.setMappingFilePath(mappingFile.getAbsolutePath());
    fds4.init(tempFolder.newFolder().getAbsolutePath());
    assertEquals(dr3.getLength(), fds4.getRecord(dr3.getIdentifier()).getLength());
    assertEquals(dr2.getLength(), fds4.getRecord(dr2.getIdentifier()).getLength());
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) File(java.io.File) Test(org.junit.Test)

Example 12 with FileDataStore

use of org.apache.jackrabbit.core.data.FileDataStore in project jackrabbit-oak by apache.

the class TemporaryBlobStore method before.

@Override
protected void before() throws Throwable {
    FileDataStore fds = new FileDataStore();
    fds.setMinRecordLength(4092);
    fds.init(folder.newFolder().getAbsolutePath());
    store = new DataStoreBlobStore(fds);
}
Also used : FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)

Example 13 with FileDataStore

use of org.apache.jackrabbit.core.data.FileDataStore 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 14 with FileDataStore

use of org.apache.jackrabbit.core.data.FileDataStore 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 15 with FileDataStore

use of org.apache.jackrabbit.core.data.FileDataStore 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)

Aggregations

FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)18 Test (org.junit.Test)11 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)10 File (java.io.File)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 DataRecord (org.apache.jackrabbit.core.data.DataRecord)5 Random (java.util.Random)3 DataStore (org.apache.jackrabbit.core.data.DataStore)3 Blob (org.apache.jackrabbit.oak.api.Blob)3 AbstractBlob (org.apache.jackrabbit.oak.plugins.memory.AbstractBlob)3 FileBlob (org.apache.jackrabbit.oak.segment.file.FileBlob)3 Closer (com.google.common.io.Closer)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Function (com.google.common.base.Function)1 Closeable (java.io.Closeable)1 HashMap (java.util.HashMap)1