use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class ExtractedTextCacheTest method cacheEnabledNonIdBlob.
@Test
public void cacheEnabledNonIdBlob() throws Exception {
ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);
Blob b = new ArrayBasedBlob("hello".getBytes());
String text = cache.get("/a", "foo", b, false);
assertNull(text);
cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello"));
text = cache.get("/a", "foo", b, false);
assertNull(text);
}
use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class IndexDefinitionPrinterTest method binaryProps.
@Test
public void binaryProps() throws Exception {
NodeBuilder builder = store.getRoot().builder();
builder.child("a").setProperty("foo", new ArrayBasedBlob("hello".getBytes()));
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
when(pathService.getIndexPaths()).thenReturn(Lists.newArrayList("/a"));
String json = getJSON();
IndexDefinitionUpdater updater = new IndexDefinitionUpdater(json);
assertTrue(updater.getIndexPaths().contains("/a"));
}
use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class IndexTrackerTest method corruptIndex.
private NodeState corruptIndex(String indexPath) {
NodeBuilder dir = TestUtil.child(builder, PathUtils.concat(indexPath, ":data"));
for (String name : dir.getChildNodeNames()) {
if (!"segments.gen".equals(name)) {
dir.getChildNode(name).setProperty(PropertyStates.createProperty("jcr:data", Collections.singletonList(new ArrayBasedBlob("foo".getBytes())), Type.BINARIES));
}
}
TestUtil.child(builder, PathUtils.concat(indexPath, IndexDefinition.STATUS_NODE)).setProperty("foo", "bar");
return builder.getNodeState();
}
use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.
the class OakDirectoryTestBase 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 OakDirectoryTestBase method dontReportFilesMarkedUnsafeForActiveDeletion.
// OAK-6950
@Test
public void dontReportFilesMarkedUnsafeForActiveDeletion() throws Exception {
AtomicInteger blobIdSuffix = new AtomicInteger();
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) {
@Override
public String getContentIdentity() {
return Long.toString(length() - UNIQUE_KEY_SIZE) + "-id-" + blobIdSuffix.get();
}
};
};
final AtomicBoolean markingForceActiveDeletionUnsafe = new AtomicBoolean();
final Set<String> deletedBlobs = Sets.newHashSet();
OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {
@Override
public void deleted(String blobId, Iterable<String> ids) {
deletedBlobs.add(blobId);
}
@Override
public void commitProgress(IndexProgress indexProgress) {
}
@Override
public boolean isMarkingForActiveDeletionUnsafe() {
return markingForceActiveDeletionUnsafe.get();
}
}).build();
// file1 created before marking was flagged as unsafe
blobIdSuffix.set(1);
writeFile(dir, "file1", fileSize);
markingForceActiveDeletionUnsafe.set(true);
// file2 created after marking was flagged as unsafe
blobIdSuffix.set(1);
writeFile(dir, "file2", fileSize);
dir.deleteFile("file1");
dir.deleteFile("file2");
dir.close();
deletedBlobs.forEach(deletedBlob -> {
assertTrue("Deleted blob id " + deletedBlob + " must belong to file1", deletedBlob.endsWith("-id-1"));
});
}
Aggregations