use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.UNIQUE_KEY_SIZE 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