use of org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob in project jackrabbit-oak by apache.
the class BlobReferenceIteratorTest method testBlobIterator.
@Test
public void testBlobIterator() throws Exception {
List<ReferencedBlob> blobs = Lists.newArrayList();
// 1. Set some single value Binary property
for (int i = 0; i < 10; i++) {
NodeBuilder b1 = store.getRoot().builder();
Blob b = store.createBlob(randomStream(i, 4096));
b1.child("x").child("y" + 1).setProperty("b" + i, b);
blobs.add(new ReferencedBlob(b, "/x/y" + 1));
store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
List<ReferencedBlob> collectedBlobs = ImmutableList.copyOf(store.getReferencedBlobsIterator());
assertEquals(blobs.size(), collectedBlobs.size());
assertEquals(new HashSet<ReferencedBlob>(blobs), new HashSet<ReferencedBlob>(collectedBlobs));
}
use of org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob in project jackrabbit-oak by apache.
the class DocumentBlobReferenceRetriever method collectReferences.
@Override
public void collectReferences(ReferenceCollector collector) {
int referencesFound = 0;
Iterator<ReferencedBlob> blobIterator = null;
try {
blobIterator = nodeStore.getReferencedBlobsIterator();
while (blobIterator.hasNext()) {
ReferencedBlob refBlob = blobIterator.next();
Blob blob = refBlob.getBlob();
referencesFound++;
if (blob instanceof BlobStoreBlob) {
collector.addReference(((BlobStoreBlob) blob).getBlobId(), refBlob.getId());
} else {
// TODO Should not rely on toString. Instead obtain
// secure reference and convert that to blobId using
// blobStore
collector.addReference(blob.toString(), refBlob.getId());
}
}
} finally {
Utils.closeIfCloseable(blobIterator);
}
log.debug("Total blob references found (including chunk resolution) [{}]", referencesFound);
}
use of org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob in project jackrabbit-oak by apache.
the class BlobCollector method loadValue.
private void loadValue(String v, Collection<ReferencedBlob> blobs, String nodeId) {
JsopReader reader = new JsopTokenizer(v);
PropertyState p;
if (reader.matches('[')) {
p = DocumentPropertyState.readArrayProperty("x", nodeStore, reader);
if (p.getType() == Type.BINARIES) {
for (int i = 0; i < p.count(); i++) {
Blob b = p.getValue(Type.BINARY, i);
blobs.add(new ReferencedBlob(b, nodeId));
}
}
} else {
p = DocumentPropertyState.readProperty("x", nodeStore, reader);
if (p.getType() == Type.BINARY) {
Blob b = p.getValue(Type.BINARY);
blobs.add(new ReferencedBlob(b, nodeId));
}
}
}
use of org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob in project jackrabbit-oak by apache.
the class BlobCollectorTest method testCollect.
@Test
public void testCollect() throws Exception {
NodeBuilder b1 = store.getRoot().builder();
List<ReferencedBlob> blobs = Lists.newArrayList();
b1.child("x").child("y");
store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
//1. Set some single value Binary property
for (int i = 0; i < 2; i++) {
b1 = store.getRoot().builder();
Blob b = store.createBlob(randomStream(i, 4096));
b1.child("x").child("y").setProperty("b" + i, b);
blobs.add(new ReferencedBlob(b, "/x/y"));
store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
//2. Set some multi value property
PropertyBuilder<Blob> p1 = PropertyBuilder.array(Type.BINARY).setName("barr");
for (int i = 0; i < 2; i++) {
Blob b = store.createBlob(randomStream(i, 4096));
p1.addValue(b);
blobs.add(new ReferencedBlob(b, "/x/y"));
}
b1 = store.getRoot().builder();
b1.child("x").child("y").setProperty(p1.getPropertyState());
store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
//3. Create some new rev for the property b1 and b2
for (int i = 0; i < 2; i++) {
b1 = store.getRoot().builder();
//Change the see to create diff binary
Blob b = store.createBlob(randomStream(i + 1, 4096));
b1.child("x").child("y").setProperty("b" + i, b);
blobs.add(new ReferencedBlob(b, "/x/y"));
store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
NodeDocument doc = store.getDocumentStore().find(Collection.NODES, Utils.getIdFromPath("/x/y"));
List<ReferencedBlob> collectedBlobs = Lists.newArrayList();
blobCollector.collect(doc, collectedBlobs);
assertEquals(blobs.size(), collectedBlobs.size());
assertEquals(new HashSet<ReferencedBlob>(blobs), new HashSet<ReferencedBlob>(collectedBlobs));
}
use of org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob in project jackrabbit-oak by apache.
the class BlobReferenceTest method test.
@Test
public void test() throws Exception {
DocumentNodeStore s = new DocumentMK.Builder().getNodeStore();
NodeBuilder a = s.getRoot().builder();
HashSet<String> set = new HashSet<String>();
for (int i = 0; i < 100; i++) {
Blob b = a.createBlob(randomStream(i, 10));
set.add(new ReferencedBlob(b, "/c" + i).toString());
a.child("c" + i).setProperty("x", b);
}
s.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
Iterator<ReferencedBlob> it = s.getReferencedBlobsIterator();
while (it.hasNext()) {
ReferencedBlob b = it.next();
set.remove(b.toString());
}
assertTrue(set.isEmpty());
s.dispose();
}
Aggregations