Search in sources :

Example 16 with ArrayBasedBlob

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

the class FileStoreIT method testRecovery.

@Test
public void testRecovery() throws Exception {
    FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    store.flush();
    RandomAccessFile data0 = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "r");
    long pos0 = data0.length();
    SegmentNodeState base = store.getHead();
    SegmentNodeBuilder builder = base.builder();
    ArrayBasedBlob blob = new ArrayBasedBlob(new byte[SegmentTestConstants.MEDIUM_LIMIT]);
    builder.setProperty("blob", blob);
    builder.setProperty("step", "a");
    store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
    store.flush();
    long pos1 = data0.length();
    data0.close();
    base = store.getHead();
    builder = base.builder();
    builder.setProperty("step", "b");
    store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    assertEquals("b", store.getHead().getString("step"));
    store.close();
    RandomAccessFile file = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "rw");
    file.setLength(pos1);
    file.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    assertEquals("a", store.getHead().getString("step"));
    store.close();
    file = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "rw");
    file.setLength(pos0);
    file.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    assertFalse(store.getHead().hasProperty("step"));
    store.close();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 17 with ArrayBasedBlob

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

the class BlobIdRecordTest method longReferencesShouldHaveBlobIdType.

@Test
public void longReferencesShouldHaveBlobIdType() throws Exception {
    try (FileStore ss = newFileStore(new LongIdMappingBlobStore())) {
        SegmentWriter sw = defaultSegmentWriterBuilder("test").build(ss);
        byte[] content = new byte[Segment.MEDIUM_LIMIT + 1];
        SegmentBlob sb = new SegmentBlob(ss.getBlobStore(), sw.writeBlob(new ArrayBasedBlob(content)));
        assertRecordTypeEquals(sb, RecordType.BLOB_ID);
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Test(org.junit.Test)

Example 18 with ArrayBasedBlob

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

the class OakDirectoryTest 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");
    OakDirectory.BlobFactory factory = new OakDirectory.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 = new OakDirectory(builder, INDEX_DATA_CHILD_NAME, def, false, factory);
    numBlobs.set(0);
    writeFile(dir, "file", fileSize);
    assertEquals(1, numBlobs.get());
    dir.close();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 19 with ArrayBasedBlob

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

the class SegmentParserTest method createRandomBlob.

private static Blob createRandomBlob(int size) {
    byte[] bytes = new byte[size];
    new Random().nextBytes(bytes);
    return new ArrayBasedBlob(bytes);
}
Also used : Random(java.util.Random) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)

Example 20 with ArrayBasedBlob

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

the class NodeStateCopyUtilsTest method copyToJcrVariousProps.

@Test
public void copyToJcrVariousProps() throws Exception {
    repository = new Jcr().with(new OpenSecurityProvider()).createRepository();
    Calendar cal = ISO8601.parse(ISO8601.format(Calendar.getInstance()));
    Tree srcTree = TreeFactory.createTree(builder);
    srcTree.setOrderableChildren(true);
    srcTree.setProperty("fooString", "x");
    srcTree.setProperty("fooLong", 1L, Type.LONG);
    srcTree.setProperty("fooPath", "/fooNode", Type.PATH);
    srcTree.setProperty("fooName", "mix:title", Type.NAME);
    srcTree.setProperty("fooDouble", 1.0, Type.DOUBLE);
    srcTree.setProperty("fooDate", ISO8601.format(cal), Type.DATE);
    srcTree.setProperty("fooBoolean", true, Type.BOOLEAN);
    srcTree.setProperty("fooStrings", asList("a", "b"), Type.STRINGS);
    srcTree.setProperty("fooBlob", new ArrayBasedBlob("foo".getBytes()), Type.BINARY);
    srcTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_OAK_UNSTRUCTURED, Type.NAME);
    srcTree.setProperty(JcrConstants.JCR_MIXINTYPES, asList("mix:mimeType", "mix:title"), Type.NAMES);
    Session session = repository.login(null, null);
    Node node = session.getRootNode();
    Node test = node.addNode("test", NT_OAK_UNSTRUCTURED);
    Node fooNode = node.addNode("fooNode", NT_OAK_UNSTRUCTURED);
    NodeStateCopyUtils.copyToNode(builder.getNodeState(), test);
    session.save();
    test = session.getNode("/test");
    assertEquals("x", test.getProperty("fooString").getString());
    assertEquals("/fooNode", test.getProperty("fooPath").getNode().getPath());
    assertEquals("mix:title", test.getProperty("fooName").getString());
    assertEquals(1, test.getProperty("fooLong").getLong());
    assertEquals(cal, test.getProperty("fooDate").getDate());
    assertEquals("a", test.getProperty("fooStrings").getValues()[0].getString());
    assertEquals("b", test.getProperty("fooStrings").getValues()[1].getString());
    InputStream is = test.getProperty("fooBlob").getBinary().getStream();
    String streamVal = IOUtils.toString(is, "UTF-8");
    assertEquals("foo", streamVal);
}
Also used : InputStream(java.io.InputStream) Calendar(java.util.Calendar) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Node(javax.jcr.Node) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Tree(org.apache.jackrabbit.oak.api.Tree) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Session(javax.jcr.Session) 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