@RunWithCustomExecutor @Test public void should_throw_VitamRuntimeException_when_loading_and_storage_throws_StorageServerClientException() throws StorageServerClientException, StorageNotFoundException { Mockito .when(storageClientFactory.getClient().getContainerAsync(VitamConfiguration.getDefaultStrategy(), "100.json", DataCategory.BACKUP_OPERATION, AccessLogUtils.getNoLogAccessLog())) .thenThrow(new StorageServerClientException("storage error")); RestoreBackupService restoreBackupService = new RestoreBackupService(storageClientFactory); assertThatCode(() -> restoreBackupService.loadData(VitamConfiguration.getDefaultStrategy(), "100.json", 100L)) .isInstanceOf(VitamRuntimeException.class); }
public LogbookBackupModel loadData(String strategy, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, DataCategory.BACKUP_OPERATION.name(), strategy)); InputStream inputStream = null; Response response = null; try (StorageClient storageClient = storageClientFactory.getClient()) { DataCategory type = DataCategory.BACKUP_OPERATION; response = storageClient.getContainerAsync(strategy, filename, type, AccessLogUtils.getNoLogAccessLog()); inputStream = response.readEntity(InputStream.class); LogbookOperation logbookOperationDocument = new LogbookOperation(JsonHandler.getFromInputStream(inputStream, JsonNode.class)); LogbookBackupModel logbookBackupModel = new LogbookBackupModel(); logbookBackupModel.setLogbookOperation(logbookOperationDocument); logbookBackupModel.setLogbookId(logbookOperationDocument.getId()); logbookBackupModel.setOffset(offset); return logbookBackupModel; } catch (StorageServerClientException | InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { StreamUtils.closeSilently(inputStream); StreamUtils.consumeAnyEntityAndClose(response); } }
RestoreBackupService { public LogbookBackupModel loadData(String strategy, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, DataCategory.BACKUP_OPERATION.name(), strategy)); InputStream inputStream = null; Response response = null; try (StorageClient storageClient = storageClientFactory.getClient()) { DataCategory type = DataCategory.BACKUP_OPERATION; response = storageClient.getContainerAsync(strategy, filename, type, AccessLogUtils.getNoLogAccessLog()); inputStream = response.readEntity(InputStream.class); LogbookOperation logbookOperationDocument = new LogbookOperation(JsonHandler.getFromInputStream(inputStream, JsonNode.class)); LogbookBackupModel logbookBackupModel = new LogbookBackupModel(); logbookBackupModel.setLogbookOperation(logbookOperationDocument); logbookBackupModel.setLogbookId(logbookOperationDocument.getId()); logbookBackupModel.setOffset(offset); return logbookBackupModel; } catch (StorageServerClientException | InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { StreamUtils.closeSilently(inputStream); StreamUtils.consumeAnyEntityAndClose(response); } } }
RestoreBackupService { public LogbookBackupModel loadData(String strategy, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, DataCategory.BACKUP_OPERATION.name(), strategy)); InputStream inputStream = null; Response response = null; try (StorageClient storageClient = storageClientFactory.getClient()) { DataCategory type = DataCategory.BACKUP_OPERATION; response = storageClient.getContainerAsync(strategy, filename, type, AccessLogUtils.getNoLogAccessLog()); inputStream = response.readEntity(InputStream.class); LogbookOperation logbookOperationDocument = new LogbookOperation(JsonHandler.getFromInputStream(inputStream, JsonNode.class)); LogbookBackupModel logbookBackupModel = new LogbookBackupModel(); logbookBackupModel.setLogbookOperation(logbookOperationDocument); logbookBackupModel.setLogbookId(logbookOperationDocument.getId()); logbookBackupModel.setOffset(offset); return logbookBackupModel; } catch (StorageServerClientException | InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { StreamUtils.closeSilently(inputStream); StreamUtils.consumeAnyEntityAndClose(response); } } RestoreBackupService(); @VisibleForTesting  RestoreBackupService(StorageClientFactory storageClientFactory); }
RestoreBackupService { public LogbookBackupModel loadData(String strategy, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, DataCategory.BACKUP_OPERATION.name(), strategy)); InputStream inputStream = null; Response response = null; try (StorageClient storageClient = storageClientFactory.getClient()) { DataCategory type = DataCategory.BACKUP_OPERATION; response = storageClient.getContainerAsync(strategy, filename, type, AccessLogUtils.getNoLogAccessLog()); inputStream = response.readEntity(InputStream.class); LogbookOperation logbookOperationDocument = new LogbookOperation(JsonHandler.getFromInputStream(inputStream, JsonNode.class)); LogbookBackupModel logbookBackupModel = new LogbookBackupModel(); logbookBackupModel.setLogbookOperation(logbookOperationDocument); logbookBackupModel.setLogbookId(logbookOperationDocument.getId()); logbookBackupModel.setOffset(offset); return logbookBackupModel; } catch (StorageServerClientException | InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { StreamUtils.closeSilently(inputStream); StreamUtils.consumeAnyEntityAndClose(response); } } RestoreBackupService(); @VisibleForTesting  RestoreBackupService(StorageClientFactory storageClientFactory); Iterator<List<OfferLog>> getListing(String strategy, long offset, int limit); LogbookBackupModel loadData(String strategy, String filename,
        long offset); }
RestoreBackupService { public LogbookBackupModel loadData(String strategy, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, DataCategory.BACKUP_OPERATION.name(), strategy)); InputStream inputStream = null; Response response = null; try (StorageClient storageClient = storageClientFactory.getClient()) { DataCategory type = DataCategory.BACKUP_OPERATION; response = storageClient.getContainerAsync(strategy, filename, type, AccessLogUtils.getNoLogAccessLog()); inputStream = response.readEntity(InputStream.class); LogbookOperation logbookOperationDocument = new LogbookOperation(JsonHandler.getFromInputStream(inputStream, JsonNode.class)); LogbookBackupModel logbookBackupModel = new LogbookBackupModel(); logbookBackupModel.setLogbookOperation(logbookOperationDocument); logbookBackupModel.setLogbookId(logbookOperationDocument.getId()); logbookBackupModel.setOffset(offset); return logbookBackupModel; } catch (StorageServerClientException | InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { StreamUtils.closeSilently(inputStream); StreamUtils.consumeAnyEntityAndClose(response); } } RestoreBackupService(); @VisibleForTesting  RestoreBackupService(StorageClientFactory storageClientFactory); Iterator<List<OfferLog>> getListing(String strategy, long offset, int limit); LogbookBackupModel loadData(String strategy, String filename,
        long offset);  }