@Test @Deploy("org.nuxeo.ecm.core.api") @Deploy("org.nuxeo.ecm.core.api.tests:OSGI-INF/test-default-blob-provider.xml") public void testDefaultBinaryManager() throws Exception { DefaultBinaryManager binaryManager = new DefaultBinaryManager(); binaryManager.initialize("repo", Collections.emptyMap()); assertEquals(0, countFiles(binaryManager.getStorageDir())); Binary binary = binaryManager.getBinary(CONTENT_MD5); assertNull(binary); assertEquals("MD5", binaryManager.getDigestAlgorithm()); byte[] bytes = CONTENT.getBytes("UTF-8"); binary = binaryManager.getBinary(Blobs.createBlob(CONTENT)); assertNotNull(binary); assertEquals(1, countFiles(binaryManager.getStorageDir())); binary = binaryManager.getBinary(CONTENT_MD5); assertNotNull(binary); try (InputStream stream = binary.getStream()) { assertEquals(CONTENT, IOUtils.toString(stream, "UTF-8")); } assertEquals("MD5", binary.getDigestAlgorithm()); assertEquals(CONTENT_MD5, binary.getDigest()); Binary sha1Binary = new Binary(CONTENT_SHA1, "repo"); assertEquals("SHA-1", sha1Binary.getDigestAlgorithm()); assertEquals(CONTENT_SHA1, sha1Binary.getDigest()); binaryManager.getBinary(Blobs.createBlob("abc")); assertEquals(2, countFiles(binaryManager.getStorageDir())); Thread.sleep(3 * 1000); binaryManager.getBinary(Blobs.createBlob("defg")); assertEquals(3, countFiles(binaryManager.getStorageDir())); BinaryGarbageCollector gc = binaryManager.getGarbageCollector(); assertFalse(gc.isInProgress()); gc.start(); assertTrue(gc.isInProgress()); gc.mark(CONTENT_MD5); assertTrue(gc.isInProgress()); gc.stop(false); assertFalse(gc.isInProgress()); BinaryManagerStatus status = gc.getStatus(); assertEquals(2, status.numBinaries); assertEquals(bytes.length + 4, status.sizeBinaries); assertEquals(1, status.numBinariesGC); assertEquals(3, status.sizeBinariesGC); assertEquals(3, countFiles(binaryManager.getStorageDir())); gc = binaryManager.getGarbageCollector(); assertFalse(gc.isInProgress()); gc.start(); assertTrue(gc.isInProgress()); gc.mark(CONTENT_MD5); assertTrue(gc.isInProgress()); gc.stop(true); assertFalse(gc.isInProgress()); status = gc.getStatus(); assertEquals(2, status.numBinaries); assertEquals(bytes.length + 4, status.sizeBinaries); assertEquals(1, status.numBinariesGC); assertEquals(3, status.sizeBinariesGC); assertEquals(2, countFiles(binaryManager.getStorageDir())); binaryManager.close(); }
@Override public Binary getBinary(Blob blob) throws IOException { if (!(blob instanceof FileBlob) || !((FileBlob) blob).isTemporary()) { return super.getBinary(blob); } String digest = storeAndDigest((FileBlob) blob); File file = getFileForDigest(digest, false); return new Binary(file, digest, blobProviderId); }
DefaultBinaryManager extends LocalBinaryManager { @Override public Binary getBinary(Blob blob) throws IOException { if (!(blob instanceof FileBlob) || !((FileBlob) blob).isTemporary()) { return super.getBinary(blob); } String digest = storeAndDigest((FileBlob) blob); File file = getFileForDigest(digest, false); return new Binary(file, digest, blobProviderId); } }
DefaultBinaryManager extends LocalBinaryManager { @Override public Binary getBinary(Blob blob) throws IOException { if (!(blob instanceof FileBlob) || !((FileBlob) blob).isTemporary()) { return super.getBinary(blob); } String digest = storeAndDigest((FileBlob) blob); File file = getFileForDigest(digest, false); return new Binary(file, digest, blobProviderId); }  }
DefaultBinaryManager extends LocalBinaryManager { @Override public Binary getBinary(Blob blob) throws IOException { if (!(blob instanceof FileBlob) || !((FileBlob) blob).isTemporary()) { return super.getBinary(blob); } String digest = storeAndDigest((FileBlob) blob); File file = getFileForDigest(digest, false); return new Binary(file, digest, blobProviderId); }  @Override Binary getBinary(Blob blob); }
DefaultBinaryManager extends LocalBinaryManager { @Override public Binary getBinary(Blob blob) throws IOException { if (!(blob instanceof FileBlob) || !((FileBlob) blob).isTemporary()) { return super.getBinary(blob); } String digest = storeAndDigest((FileBlob) blob); File file = getFileForDigest(digest, false); return new Binary(file, digest, blobProviderId); }  @Override Binary getBinary(Blob blob);  }