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"));
}
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);
}
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);
}
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());
}
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));
}
Aggregations