DatastoreOrphanedBlobFinder extends ComponentSupport implements OrphanedBlobFinder { @Override public void delete() { log.info("Starting delete of orphaned blobs for all known blob stores"); blobStoreManager.browse().forEach(this::delete); log.info("Finished deleting orphaned blobs"); } @Inject  DatastoreOrphanedBlobFinder(final RepositoryManager repositoryManager, final BlobStoreManager blobStoreManager); @Override void delete(); @Override void delete(final Repository repository); @Override void detect(final Repository repository, final Consumer<String> handler);  }
@Test public void deleteOrphanedBlobs() { setupOrphanedBlob(); underTest.delete(repository); verify(blobStore).deleteHard(new BlobId(ORPHANED_BLOB_ID)); }
@Test public void ignoreSoftDeletedBlobs() { setupOrphanedBlob(blobStore, true); underTest.delete(repository); verify(blobStore, never()).deleteHard(new BlobId(ORPHANED_BLOB_ID)); }
@Test public void deleteOrphanedBlobsForAllBlobStores() { setupOrphanedBlob(blobStore, false); setupOrphanedBlob(blobStore2, false); when(blobStoreManager.browse()).thenReturn(ImmutableList.of(blobStore, blobStore2)); underTest.delete(); verify(blobStore).deleteHard(new BlobId(ORPHANED_BLOB_ID)); verify(blobStore2).deleteHard(new BlobId(ORPHANED_BLOB_ID)); }
@Test public void deleteBlobIfRepositoryNotFound() { setupOrphanedBlob(); when(repositoryManager.get(REPOSITORY_NAME)).thenReturn(null); underTest.delete(repository); verify(blobStore).deleteHard(new BlobId(ORPHANED_BLOB_ID)); verify(blobStore).deleteHard(new BlobId(USED_BLOB_ID)); }