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