Search in sources :

Example 1 with ArrayBasedBlob

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

the class NodeStateJsonUtilsTest method toJson.

@Test
public void toJson() throws Exception {
    NodeBuilder builder = EMPTY_NODE.builder();
    builder.child("a").setProperty("foo", 10);
    builder.child("a").setProperty("foo2", "bar");
    builder.child("a").setProperty("foo3", true);
    builder.child("a").setProperty("foo4", new ArrayBasedBlob("foo".getBytes()));
    builder.child("a").child("b").setProperty("foo", Lists.newArrayList(1L, 2L, 3L), Type.LONGS);
    builder.child("a").child("b").setProperty("foo2", Lists.newArrayList("x", "y", "z"), Type.STRINGS);
    builder.child("a").child("b").setProperty("foo3", Lists.newArrayList(true, false), Type.BOOLEANS);
    builder.child("a").child(":c").setProperty("foo", "bar");
    String jsop = NodeStateJsonUtils.toJson(builder.getNodeState(), false);
    JSONObject json = (JSONObject) JSONValue.parseWithException(jsop);
    assertTrue(json.containsKey("a"));
    JSONObject a = (JSONObject) json.get("a");
    JSONObject b = (JSONObject) a.get("b");
    assertEquals(Lists.newArrayList(1L, 2L, 3L), b.get("foo"));
    assertEquals(Lists.newArrayList("x", "y", "z"), b.get("foo2"));
    assertEquals(Lists.newArrayList(true, false), b.get("foo3"));
}
Also used : JSONObject(org.json.simple.JSONObject) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with ArrayBasedBlob

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

the class OakDirectoryTest 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) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) 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 3 with ArrayBasedBlob

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

the class OakDirectoryTest 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) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) 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 4 with ArrayBasedBlob

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

the class OakDirectoryTest method testOverflow.

//OAK-2388
@Test
public void testOverflow() throws Exception {
    Directory dir = createDir(builder, false, "/foo");
    NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt");
    int blobSize = 32768;
    int dataSize = 90844;
    file.setProperty(OakDirectory.PROP_BLOB_SIZE, blobSize);
    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);
    assertEquals((long) blobSize * (dataSize - 1), input.length());
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) 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 5 with ArrayBasedBlob

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

the class ExcerptTest method binaryExcerpt.

@Test
public void binaryExcerpt() throws Exception {
    Tree contentRoot = root.getTree("/").addChild("testRoot");
    String binaryText = "is fox foxing as a fox cub";
    Blob blob = new ArrayBasedBlob(binaryText.getBytes());
    TestUtil.createFileNode(contentRoot, "binaryNode", blob, "text/plain");
    root.commit();
    String query = "SELECT [rep:excerpt] FROM [nt:base] WHERE CONTAINS(*, 'fox')";
    Result result = executeQuery(query, SQL2, NO_BINDINGS);
    Iterator<? extends ResultRow> resultIter = result.getRows().iterator();
    assertTrue(resultIter.hasNext());
    ResultRow firstRow = resultIter.next();
    PropertyValue nodeExcerpt;
    String excerpt;
    nodeExcerpt = firstRow.getValue("rep:excerpt");
    assertNotNull("rep:excerpt not evaluated", nodeExcerpt);
    excerpt = nodeExcerpt.getValue(STRING);
    String expected = binaryText.replaceAll(" fox ", " <strong>fox</strong> ");
    assertTrue("rep:excerpt didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains(expected));
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) Result(org.apache.jackrabbit.oak.api.Result) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

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