Search in sources :

Example 11 with ArrayBasedBlob

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

the class OakDirectoryTestBase method blobFactory.

@Test
public void blobFactory() throws Exception {
    final AtomicInteger numBlobs = new AtomicInteger();
    final int fileSize = 1024;
    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();
            assertEquals(fileSize + UNIQUE_KEY_SIZE, data.length);
            numBlobs.incrementAndGet();
            return new ArrayBasedBlob(data);
        }
    };
    OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).build();
    numBlobs.set(0);
    writeFile(dir, "file", fileSize);
    assertEquals(1, numBlobs.get());
    dir.close();
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 12 with ArrayBasedBlob

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

the class IndexConsistencyCheckerTest method badFile.

@Test
public void badFile() throws Exception {
    IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx.getNodeState(), "/fooIndex").build();
    Directory dir = new OakDirectory(idx, ":data", defn, false);
    createIndex(dir, 10);
    NodeBuilder builder = rootState.builder();
    NodeBuilder file = idx.getChildNode(":data").getChildNode("_0.cfe");
    List<Blob> blobs = Lists.newArrayList(file.getProperty("jcr:data").getValue(Type.BINARIES));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOUtils.copy(blobs.get(0).getNewStream(), baos);
    byte[] bytes = baos.toByteArray();
    // Flip the 3rd bit to make it corrupt
    bytes[0] = (byte) (bytes[0] ^ (1 << 3));
    blobs.set(0, new ArrayBasedBlob(bytes));
    file.setProperty("jcr:data", blobs, Type.BINARIES);
    builder.setChildNode("fooIndex", idx.getNodeState());
    NodeState indexState = builder.getNodeState();
    IndexConsistencyChecker checker = new IndexConsistencyChecker(indexState, "/fooIndex", temporaryFolder.getRoot());
    Result result = checker.check(Level.FULL);
    assertFalse(result.clean);
    assertEquals(0, result.dirStatus.get(0).missingFiles.size());
    assertFalse(result.dirStatus.get(0).status.clean);
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Result(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Result) Test(org.junit.Test)

Example 13 with ArrayBasedBlob

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

the class BlobTest method testBlobSerialization.

@Test
public void testBlobSerialization() throws Exception {
    TestBlobStore blobStore = new TestBlobStore();
    DocumentMK mk = builderProvider.newBuilder().setBlobStore(blobStore).open();
    BlobSerializer blobSerializer = mk.getNodeStore().getBlobSerializer();
    Blob blob = new BlobStoreBlob(blobStore, "foo");
    assertEquals("foo", blobSerializer.serialize(blob));
    assertEquals(0, blobStore.writeCount);
    blob = new ArrayBasedBlob("foo".getBytes());
    blobSerializer.serialize(blob);
    assertEquals(1, blobStore.writeCount);
    byte[] bytes = "foo".getBytes();
    String blobId = blobStore.writeBlob(new ByteArrayInputStream(bytes));
    String reference = blobStore.getReference(blobId);
    blob = new ReferencedBlob("foo".getBytes(), reference);
    blobStore.writeCount = 0;
    blobSerializer.serialize(blob);
    // Using reference so no reference should be written
    assertEquals(0, blobStore.writeCount);
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) BlobSerializer(org.apache.jackrabbit.oak.json.BlobSerializer) Test(org.junit.Test)

Example 14 with ArrayBasedBlob

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

the class BlobIdSerializerTest method inMemoryBlob.

@Test
public void inMemoryBlob() throws Exception {
    Blob b = new ArrayBasedBlob("hello world".getBytes());
    String value = serializer.serialize(b);
    Blob b2 = serializer.deserialize(value);
    assertTrue(AbstractBlob.equal(b, b2));
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) AbstractBlob(org.apache.jackrabbit.oak.plugins.memory.AbstractBlob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Test(org.junit.Test)

Example 15 with ArrayBasedBlob

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

the class FSBlobSerializerTest method blobs.

@Test
public void blobs() throws Exception {
    int maxInlineSize = 100;
    FSBlobSerializer serializer = new FSBlobSerializer(folder.getRoot(), maxInlineSize);
    String data = Strings.repeat("x", maxInlineSize * 10);
    Blob b = new ArrayBasedBlob(data.getBytes(UTF_8));
    String id = serializer.serialize(b);
    Blob b2 = serializer.deserialize(id);
    assertTrue(AbstractBlob.equal(b, b2));
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) AbstractBlob(org.apache.jackrabbit.oak.plugins.memory.AbstractBlob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) FSBlobSerializer(org.apache.jackrabbit.oak.plugins.blob.serializer.FSBlobSerializer) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) 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