Search in sources :

Example 1 with ReferencedBlob

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));
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) Blob(org.apache.jackrabbit.oak.api.Blob) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with ReferencedBlob

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);
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)

Example 3 with ReferencedBlob

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));
        }
    }
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) JsopReader(org.apache.jackrabbit.oak.commons.json.JsopReader) ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) Blob(org.apache.jackrabbit.oak.api.Blob) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 4 with ReferencedBlob

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));
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) Blob(org.apache.jackrabbit.oak.api.Blob) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with ReferencedBlob

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();
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) Blob(org.apache.jackrabbit.oak.api.Blob) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Blob (org.apache.jackrabbit.oak.api.Blob)5 ReferencedBlob (org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob)5 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 JsopReader (org.apache.jackrabbit.oak.commons.json.JsopReader)1 JsopTokenizer (org.apache.jackrabbit.oak.commons.json.JsopTokenizer)1 BlobStoreBlob (org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)1