@Override public Blob createBlob(InputStream stream) throws IOException { return builder.createBlob(stream); }
@Override public Blob createBlob(InputStream stream) throws IOException { return builder.createBlob(stream); }
@Override public Blob createBlob(InputStream stream) throws IOException { return builder.createBlob(stream); }
@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(); }
@Test public void multiValuedBinarySize() throws Exception { NodeBuilder builder = ns.getRoot().builder(); List<Blob> blobs = newArrayList(); for (int i = 0; i < 3; i++) { blobs.add(builder.createBlob(new RandomStream(BLOB_SIZE, i))); } builder.child("test").setProperty("p", blobs, Type.BINARIES); TestUtils.merge(ns, builder); PropertyState p = ns.getRoot().getChildNode("test").getProperty("p"); assertEquals(Type.BINARIES, p.getType()); assertEquals(3, p.count()); reads.clear(); assertEquals(BLOB_SIZE, p.size(0)); // must not read the blob via stream assertEquals(0, reads.size()); }
@Test public void testBinaryPropertyFromExternalSegmentStore() throws IOException, CommitFailedException { byte[] data = new byte[Segment.MEDIUM_LIMIT + 1]; random.nextBytes(data); SegmentNodeStore extStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build(); NodeBuilder extRootBuilder = extStore.getRoot().builder(); Blob extBlob = extRootBuilder.createBlob(new ByteArrayInputStream(data)); extRootBuilder.setProperty("binary", extBlob, BINARY); extStore.merge(extRootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); PropertyState extPropertyState = extStore.getRoot().getProperty("binary"); NodeBuilder builder = EMPTY_NODE.builder(); builder.setProperty(extPropertyState); NodeState state = new SegmentNodeState(store.getReader(), writer, store.getBlobStore(), writer.writeNode(builder.getNodeState())); try { InputStream is = state.getProperty("binary").getValue(BINARY).getNewStream(); is.read(); is.close(); } catch (SegmentNotFoundException e) { fail("OAK-4307 SegmentWriter saves references to external blobs"); } }
@Test public void inlineBinaryShouldNotBeDownloaded() throws Exception { SegmentNodeStore store = SegmentNodeStoreBuilders.builder(fileStore.fileStore()).build(); NodeBuilder root = store.getRoot().builder(); root.setProperty("b", root.createBlob(new NullInputStream(SegmentTestConstants.MEDIUM_LIMIT - 1))); store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY); RemoteBlobProcessor processor = new RemoteBlobProcessor(blobStore.blobStore(), blobId -> { Assert.fail("Inline binaries should not be downloaded"); return null; }); processor.processBinary(store.getRoot().getProperty("b").getValue(Type.BINARY)); }
root.setProperty("b", root.createBlob(new NullInputStream(SegmentTestConstants.MEDIUM_LIMIT))); store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);