@Test public void migrationPurgeDipFilesFromOffersTest() throws StorageServerClientException { StorageClientFactory storageClientFactory = mock(StorageClientFactory.class); StorageClient storageClient = mock(StorageClient.class); doReturn(storageClient).when(storageClientFactory).getClient(); List<OfferLog> offerLogs = Arrays.asList( new OfferLog(1L, LocalDateUtil.now(), "container", "file1", OfferLogAction.WRITE), new OfferLog(2L, LocalDateUtil.now(), "container", "file2", OfferLogAction.WRITE), new OfferLog(3L, LocalDateUtil.now(), "container", "file2", OfferLogAction.DELETE) ); doReturn(new RequestResponseOK<OfferLog>().addAllResults(offerLogs)) .when(storageClient).getOfferLogs(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, null, VitamConfiguration.getChunkSize(), Order.ASC); ExportsPurgeService exportsPurgeService = new ExportsPurgeService(null, storageClientFactory, 10); exportsPurgeService.migrationPurgeDipFilesFromOffers(); verify(storageClient).delete(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, "file1"); verify(storageClient).delete(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, "file2"); }
public void migrationPurgeDipFilesFromOffers() throws StorageServerClientException { try (StorageClient storageClient = storageClientFactory.getClient()) { Iterator<OfferLog> offerLogIterator = OfferLogHelper.getListing( storageClientFactory, VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, null, Order.ASC, VitamConfiguration.getChunkSize(), null); while(offerLogIterator.hasNext()) { OfferLog offerLog = offerLogIterator.next(); switch (offerLog.getAction()) { case WRITE: LOGGER.info("Deleting DIP file " + offerLog.getFileName()); storageClient.delete(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, offerLog.getFileName()); break; case DELETE: break; default: throw new IllegalStateException("Unexpected value: " + offerLog.getAction()); } } } }
ExportsPurgeService { public void migrationPurgeDipFilesFromOffers() throws StorageServerClientException { try (StorageClient storageClient = storageClientFactory.getClient()) { Iterator<OfferLog> offerLogIterator = OfferLogHelper.getListing( storageClientFactory, VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, null, Order.ASC, VitamConfiguration.getChunkSize(), null); while(offerLogIterator.hasNext()) { OfferLog offerLog = offerLogIterator.next(); switch (offerLog.getAction()) { case WRITE: LOGGER.info("Deleting DIP file " + offerLog.getFileName()); storageClient.delete(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, offerLog.getFileName()); break; case DELETE: break; default: throw new IllegalStateException("Unexpected value: " + offerLog.getAction()); } } } } }
ExportsPurgeService { public void migrationPurgeDipFilesFromOffers() throws StorageServerClientException { try (StorageClient storageClient = storageClientFactory.getClient()) { Iterator<OfferLog> offerLogIterator = OfferLogHelper.getListing( storageClientFactory, VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, null, Order.ASC, VitamConfiguration.getChunkSize(), null); while(offerLogIterator.hasNext()) { OfferLog offerLog = offerLogIterator.next(); switch (offerLog.getAction()) { case WRITE: LOGGER.info("Deleting DIP file " + offerLog.getFileName()); storageClient.delete(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, offerLog.getFileName()); break; case DELETE: break; default: throw new IllegalStateException("Unexpected value: " + offerLog.getAction()); } } } } ExportsPurgeService(int timeToLiveInMinutes); @VisibleForTesting  ExportsPurgeService(WorkspaceClientFactory workspaceClientFactory,
        StorageClientFactory storageClientFactory, int timeToLiveInMinutes); }
ExportsPurgeService { public void migrationPurgeDipFilesFromOffers() throws StorageServerClientException { try (StorageClient storageClient = storageClientFactory.getClient()) { Iterator<OfferLog> offerLogIterator = OfferLogHelper.getListing( storageClientFactory, VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, null, Order.ASC, VitamConfiguration.getChunkSize(), null); while(offerLogIterator.hasNext()) { OfferLog offerLog = offerLogIterator.next(); switch (offerLog.getAction()) { case WRITE: LOGGER.info("Deleting DIP file " + offerLog.getFileName()); storageClient.delete(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, offerLog.getFileName()); break; case DELETE: break; default: throw new IllegalStateException("Unexpected value: " + offerLog.getAction()); } } } } ExportsPurgeService(int timeToLiveInMinutes); @VisibleForTesting  ExportsPurgeService(WorkspaceClientFactory workspaceClientFactory,
        StorageClientFactory storageClientFactory, int timeToLiveInMinutes); void purgeExpiredFiles(String container); void migrationPurgeDipFilesFromOffers(); }
ExportsPurgeService { public void migrationPurgeDipFilesFromOffers() throws StorageServerClientException { try (StorageClient storageClient = storageClientFactory.getClient()) { Iterator<OfferLog> offerLogIterator = OfferLogHelper.getListing( storageClientFactory, VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, null, Order.ASC, VitamConfiguration.getChunkSize(), null); while(offerLogIterator.hasNext()) { OfferLog offerLog = offerLogIterator.next(); switch (offerLog.getAction()) { case WRITE: LOGGER.info("Deleting DIP file " + offerLog.getFileName()); storageClient.delete(VitamConfiguration.getDefaultStrategy(), DataCategory.DIP, offerLog.getFileName()); break; case DELETE: break; default: throw new IllegalStateException("Unexpected value: " + offerLog.getAction()); } } } } ExportsPurgeService(int timeToLiveInMinutes); @VisibleForTesting  ExportsPurgeService(WorkspaceClientFactory workspaceClientFactory,
        StorageClientFactory storageClientFactory, int timeToLiveInMinutes); void purgeExpiredFiles(String container); void migrationPurgeDipFilesFromOffers();  }