use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class Base64BlobSerializer method deserialize.
@Override
public Blob deserialize(String value) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StringReader reader = new StringReader(value);
try {
Base64.decode(reader, baos);
} catch (IOException e) {
throw new RuntimeException(e);
}
return new ArrayBasedBlob(baos.toByteArray());
}
use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class OakDirectoryTestBase 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 OakDirectoryTestBase method blobsCreatedWhenActiveDeletionIsUnsafe.
// OAK-6950
@Test
public void blobsCreatedWhenActiveDeletionIsUnsafe() throws Exception {
final int fileSize = 1;
IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
BlobFactory factory = in -> {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
byte[] data = out.toByteArray();
return new ArrayBasedBlob(data);
};
final AtomicBoolean markingForceActiveDeletionUnsafe = new AtomicBoolean();
OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {
@Override
public void deleted(String blobId, Iterable<String> ids) {
}
@Override
public void commitProgress(IndexProgress indexProgress) {
}
@Override
public boolean isMarkingForActiveDeletionUnsafe() {
return markingForceActiveDeletionUnsafe.get();
}
}).build();
// file1 created before marking was flagged as unsafe
writeFile(dir, "file1", fileSize);
markingForceActiveDeletionUnsafe.set(true);
// file2 created after marking was flagged as unsafe
writeFile(dir, "file2", fileSize);
dir.close();
NodeBuilder dataBuilder = builder.getChildNode(INDEX_DATA_CHILD_NAME);
assertNull("file1 must not get flagged to be unsafe to be actively deleted", dataBuilder.getChildNode("file1").getProperty(PROP_UNSAFE_FOR_ACTIVE_DELETION));
assertTrue("file2 must get flagged to be unsafe to be actively deleted", dataBuilder.getChildNode("file2").getProperty(PROP_UNSAFE_FOR_ACTIVE_DELETION).getValue(Type.BOOLEAN));
}
use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class OakDirectoryTestBase method dontMarkNonBlobStoreBlobsAsDeleted.
// OAK-6503
@Test
public void dontMarkNonBlobStoreBlobsAsDeleted() throws Exception {
final String deletedBlobId = "blobIdentifier";
final String blobIdToString = "NeverEver-Ever-Ever-ShouldThisBeMarkedAsDeleted";
final int fileSize = 1;
final AtomicBoolean identifiableBlob = new AtomicBoolean(false);
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();
return new ArrayBasedBlob(data) {
@Override
public String getContentIdentity() {
return identifiableBlob.get() ? deletedBlobId : null;
}
@Override
public String toString() {
return blobIdToString;
}
};
}
};
OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {
@Override
public void deleted(String blobId, Iterable<String> ids) {
assertEquals("Only blobs with content identity must be reported as deleted", deletedBlobId, blobId);
}
@Override
public void commitProgress(IndexProgress indexProgress) {
}
@Override
public boolean isMarkingForActiveDeletionUnsafe() {
return false;
}
}).build();
writeFile(dir, "file1", fileSize);
writeFile(dir, "file2", fileSize);
dir.deleteFile("file1");
identifiableBlob.set(true);
dir.deleteFile("file2");
dir.close();
}
use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class OakDirectoryTestBase 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);
}
Aggregations