@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(); }
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)); } } } }
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)); } } } }
@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<>(blobs), new HashSet<>(collectedBlobs)); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ReferencedBlob that = (ReferencedBlob) o; if (!getBlob().equals(that.getBlob())) { return false; } return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
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); Blob b = store.createBlob(randomStream(i, 4096)); p1.addValue(b); blobs.add(new ReferencedBlob(b, "/x/y")); blobs.add(new ReferencedBlob(b, "/x/y")); store.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ReferencedBlob that = (ReferencedBlob) o; if (!getBlob().equals(that.getBlob())) { return false; } return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ReferencedBlob that = (ReferencedBlob) o; if (!getBlob().equals(that.getBlob())) { return false; } return !(getId() != null ? !getId().equals(that.getId()) : that.getId() != null); }
@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++; // TODO this mode would also add in memory blobId // Would that be an issue 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); } }
@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++; // TODO this mode would also add in memory blobId // Would that be an issue 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); } }