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