DefaultBinaryManager extends LocalBinaryManager implements
        BinaryManagerStreamSupport { public DefaultBinaryManager() { super(); if (!(getBinaryScrambler() instanceof NullBinaryScrambler)) { throw new IllegalStateException( "DefaultBinaryManager cannot be used with a binary scrambler"); } } DefaultBinaryManager(); @Override Binary getBinary(FileSource source);  }
@Test public void testDefaultBinaryManager() throws Exception { DefaultBinaryManager binaryManager = new DefaultBinaryManager(); binaryManager.initialize(new BinaryManagerDescriptor()); assertEquals(0, countFiles(binaryManager.getStorageDir())); Binary binary = binaryManager.getBinary(CONTENT_MD5); assertNull(binary); byte[] bytes = CONTENT.getBytes("UTF-8"); binary = binaryManager.getBinary(new ByteArrayInputStream(bytes)); assertNotNull(binary); assertEquals(1, countFiles(binaryManager.getStorageDir())); binary = binaryManager.getBinary(CONTENT_MD5); assertNotNull(binary); assertEquals(bytes.length, binary.getLength()); assertEquals(CONTENT, IOUtils.toString(binary.getStream(), "UTF-8")); binaryManager.getBinary(new ByteArrayInputStream( "abc".getBytes("UTF-8"))); assertEquals(2, countFiles(binaryManager.getStorageDir())); Thread.sleep(3 * 1000); binaryManager.getBinary(new ByteArrayInputStream( "defg".getBytes("UTF-8"))); 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(); }