Search in sources :

Example 21 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class Base64BlobSerializer method deserialize.

@Override
public Blob deserialize(String value) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    StringReader reader = new StringReader(value);
    try {
        Base64.decode(reader, baos);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new ArrayBasedBlob(baos.toByteArray());
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 22 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method testCloseOnOriginalIndexInput.

@Test
public void testCloseOnOriginalIndexInput() throws Exception {
    Directory dir = createDir(builder, false, "/foo");
    NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt");
    int dataSize = 1024;
    List<? super Blob> blobs = new ArrayList<Blob>(dataSize);
    for (int i = 0; i < dataSize; i++) {
        blobs.add(new ArrayBasedBlob(new byte[0]));
    }
    file.setProperty(PropertyStates.createProperty("jcr:data", blobs, Type.BINARIES));
    IndexInput input = dir.openInput("test.txt", IOContext.DEFAULT);
    input.close();
    assertClosed(input);
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 23 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method blobsCreatedWhenActiveDeletionIsUnsafe.

// OAK-6950
@Test
public void blobsCreatedWhenActiveDeletionIsUnsafe() throws Exception {
    final int fileSize = 1;
    IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
    BlobFactory factory = in -> {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        byte[] data = out.toByteArray();
        return new ArrayBasedBlob(data);
    };
    final AtomicBoolean markingForceActiveDeletionUnsafe = new AtomicBoolean();
    OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {

        @Override
        public void deleted(String blobId, Iterable<String> ids) {
        }

        @Override
        public void commitProgress(IndexProgress indexProgress) {
        }

        @Override
        public boolean isMarkingForActiveDeletionUnsafe() {
            return markingForceActiveDeletionUnsafe.get();
        }
    }).build();
    // file1 created before marking was flagged as unsafe
    writeFile(dir, "file1", fileSize);
    markingForceActiveDeletionUnsafe.set(true);
    // file2 created after marking was flagged as unsafe
    writeFile(dir, "file2", fileSize);
    dir.close();
    NodeBuilder dataBuilder = builder.getChildNode(INDEX_DATA_CHILD_NAME);
    assertNull("file1 must not get flagged to be unsafe to be actively deleted", dataBuilder.getChildNode("file1").getProperty(PROP_UNSAFE_FOR_ACTIVE_DELETION));
    assertTrue("file2 must get flagged to be unsafe to be actively deleted", dataBuilder.getChildNode("file2").getProperty(PROP_UNSAFE_FOR_ACTIVE_DELETION).getValue(Type.BOOLEAN));
}
Also used : JCR_DATA(org.apache.jackrabbit.JcrConstants.JCR_DATA) Arrays(java.util.Arrays) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Random(java.util.Random) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Directory(org.apache.lucene.store.Directory) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) UNIQUE_KEY_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.UNIQUE_KEY_SIZE) Assert.fail(org.junit.Assert.fail) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) IOContext(org.apache.lucene.store.IOContext) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) PROP_BLOB_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_BLOB_SIZE) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Type(org.apache.jackrabbit.oak.api.Type) Set(java.util.Set) ONE_MB(org.apache.commons.io.FileUtils.ONE_MB) FileNotFoundException(java.io.FileNotFoundException) Sets(com.google.common.collect.Sets) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) NullInputStream(org.apache.commons.io.input.NullInputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Iterables(com.google.common.collect.Iterables) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) LuceneIndexConstants(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants) SegmentNodeStoreBuilders(org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) SegmentTestConstants(org.apache.jackrabbit.oak.segment.SegmentTestConstants) PropertyStates(org.apache.jackrabbit.oak.plugins.memory.PropertyStates) IndexOutput(org.apache.lucene.store.IndexOutput) PROP_UNSAFE_FOR_ACTIVE_DELETION(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNSAFE_FOR_ACTIVE_DELETION) INDEX_DATA_CHILD_NAME(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME) ONE_GB(org.apache.commons.io.FileUtils.ONE_GB) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) IndexInput(org.apache.lucene.store.IndexInput) Assert.assertTrue(org.junit.Assert.assertTrue) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) IOException(java.io.IOException) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) File(java.io.File) InputStreamDataInput(org.apache.lucene.store.InputStreamDataInput) PROP_UNIQUE_KEY(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNIQUE_KEY) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Blob(org.apache.jackrabbit.oak.api.Blob) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) INITIAL_CONTENT(org.apache.jackrabbit.oak.InitialContent.INITIAL_CONTENT) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Test(org.junit.Test)

Example 24 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method dontMarkNonBlobStoreBlobsAsDeleted.

// OAK-6503
@Test
public void dontMarkNonBlobStoreBlobsAsDeleted() throws Exception {
    final String deletedBlobId = "blobIdentifier";
    final String blobIdToString = "NeverEver-Ever-Ever-ShouldThisBeMarkedAsDeleted";
    final int fileSize = 1;
    final AtomicBoolean identifiableBlob = new AtomicBoolean(false);
    IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
    BlobFactory factory = new BlobFactory() {

        @Override
        public Blob createBlob(InputStream in) throws IOException {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            IOUtils.copy(in, out);
            byte[] data = out.toByteArray();
            return new ArrayBasedBlob(data) {

                @Override
                public String getContentIdentity() {
                    return identifiableBlob.get() ? deletedBlobId : null;
                }

                @Override
                public String toString() {
                    return blobIdToString;
                }
            };
        }
    };
    OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {

        @Override
        public void deleted(String blobId, Iterable<String> ids) {
            assertEquals("Only blobs with content identity must be reported as deleted", deletedBlobId, blobId);
        }

        @Override
        public void commitProgress(IndexProgress indexProgress) {
        }

        @Override
        public boolean isMarkingForActiveDeletionUnsafe() {
            return false;
        }
    }).build();
    writeFile(dir, "file1", fileSize);
    writeFile(dir, "file2", fileSize);
    dir.deleteFile("file1");
    identifiableBlob.set(true);
    dir.deleteFile("file2");
    dir.close();
}
Also used : NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Test(org.junit.Test)

Example 25 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method testCloseOnClonedIndexInputs.

@Test
public void testCloseOnClonedIndexInputs() throws Exception {
    Directory dir = createDir(builder, false, "/foo");
    NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt");
    int dataSize = 1024;
    List<? super Blob> blobs = new ArrayList<Blob>(dataSize);
    for (int i = 0; i < dataSize; i++) {
        blobs.add(new ArrayBasedBlob(new byte[0]));
    }
    file.setProperty(PropertyStates.createProperty("jcr:data", blobs, Type.BINARIES));
    IndexInput input = dir.openInput("test.txt", IOContext.DEFAULT);
    IndexInput clone1 = input.clone();
    IndexInput clone2 = input.clone();
    input.close();
    assertClosed(input);
    assertClosed(clone1);
    assertClosed(clone2);
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Aggregations

ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)27 Test (org.junit.Test)24 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)12 Blob (org.apache.jackrabbit.oak.api.Blob)9 Directory (org.apache.lucene.store.Directory)9 ArrayList (java.util.ArrayList)8 IndexInput (org.apache.lucene.store.IndexInput)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 InputStream (java.io.InputStream)6 NullInputStream (org.apache.commons.io.input.NullInputStream)5 BlobStoreBlob (org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)5 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 File (java.io.File)3 IOException (java.io.IOException)3 Random (java.util.Random)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Iterables (com.google.common.collect.Iterables)2