@Test @RunWithCustomExecutor public void testStoreData_NotFoundAndWorspaceErrorToTechnicalError() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(0); final String objectId = "id1"; final ObjectDescription createObjectDescription = new ObjectDescription(); createObjectDescription.setWorkspaceContainerGUID("container1" + this); createObjectDescription.setWorkspaceObjectURI("SIP/content/test.pdf"); reset(workspaceClient); when(workspaceClient.getObject("container1" + this, "SIP/content/test.pdf")) .thenThrow(ContentAddressableStorageNotFoundException.class); try { customDistribution .storeDataInAllOffers(VitamConfiguration.getDefaultStrategy(), objectId, createObjectDescription, DataCategory.OBJECT, "testRequester"); fail("Should produce exception"); } catch (final StorageException exc) { } reset(workspaceClient); when(workspaceClient.getObject("container1" + this, "SIP/content/test.pdf")) .thenThrow(ContentAddressableStorageServerException.class); try { customDistribution .storeDataInAllOffers(VitamConfiguration.getDefaultStrategy(), objectId, createObjectDescription, DataCategory.OBJECT, "testRequester"); fail("Should produce exception"); } catch (final StorageTechnicalException exc) { } final FileInputStream stream = new FileInputStream(PropertiesUtils.findFile("object.zip")); IOUtils.closeQuietly(stream); reset(workspaceClient); when(workspaceClient.getObject("container1" + this, "SIP/content/test.pdf")) .thenReturn(Response.status(Status.OK).entity(stream) .header(VitamHttpHeader.X_CONTENT_LENGTH.getName(), (long) 6349).build()); try { customDistribution .storeDataInAllOffers(VitamConfiguration.getDefaultStrategy(), objectId, createObjectDescription, DataCategory.OBJECT, "testRequester"); fail("Should produce exception"); } catch (final StorageTechnicalException exc) { } }
@Override public StoredInfoResult storeDataInAllOffers(String strategyId, String objectId, ObjectDescription createObjectDescription, DataCategory category, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); checkStoreDataParams(createObjectDescription, strategyId, objectId, category); List<StorageOffer> storageOffers = getStorageOffers(strategyId); OffersToCopyIn offersToCopyIn = new OffersToCopyIn(storageOffers); final DataContext dataContext = new DataContext(objectId, category, requester, tenantId, strategyId); StorageLogbookParameters parameters = sendDataToOffersWithRetries(dataContext, offersToCopyIn, createObjectDescription); try { logStorage(tenantId, parameters); } catch (IOException e) { LOGGER.error(e); } return buildStoreDataResponse(objectId, category, parameters.getMapParameters().get(StorageLogbookParameterName.digest), strategyId, offersToCopyIn.getGlobalOfferResult()); }
StorageDistributionImpl implements StorageDistribution { @Override public StoredInfoResult storeDataInAllOffers(String strategyId, String objectId, ObjectDescription createObjectDescription, DataCategory category, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); checkStoreDataParams(createObjectDescription, strategyId, objectId, category); List<StorageOffer> storageOffers = getStorageOffers(strategyId); OffersToCopyIn offersToCopyIn = new OffersToCopyIn(storageOffers); final DataContext dataContext = new DataContext(objectId, category, requester, tenantId, strategyId); StorageLogbookParameters parameters = sendDataToOffersWithRetries(dataContext, offersToCopyIn, createObjectDescription); try { logStorage(tenantId, parameters); } catch (IOException e) { LOGGER.error(e); } return buildStoreDataResponse(objectId, category, parameters.getMapParameters().get(StorageLogbookParameterName.digest), strategyId, offersToCopyIn.getGlobalOfferResult()); } }
StorageDistributionImpl implements StorageDistribution { @Override public StoredInfoResult storeDataInAllOffers(String strategyId, String objectId, ObjectDescription createObjectDescription, DataCategory category, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); checkStoreDataParams(createObjectDescription, strategyId, objectId, category); List<StorageOffer> storageOffers = getStorageOffers(strategyId); OffersToCopyIn offersToCopyIn = new OffersToCopyIn(storageOffers); final DataContext dataContext = new DataContext(objectId, category, requester, tenantId, strategyId); StorageLogbookParameters parameters = sendDataToOffersWithRetries(dataContext, offersToCopyIn, createObjectDescription); try { logStorage(tenantId, parameters); } catch (IOException e) { LOGGER.error(e); } return buildStoreDataResponse(objectId, category, parameters.getMapParameters().get(StorageLogbookParameterName.digest), strategyId, offersToCopyIn.getGlobalOfferResult()); } StorageDistributionImpl(StorageConfiguration configuration, StorageLog storageLogService); @VisibleForTesting  StorageDistributionImpl(WorkspaceClientFactory workspaceClientFactory, DigestType digestType,
        StorageLog storageLogService,
        ExecutorService batchExecutorService, int batchDigestComputationTimeout,
        BulkStorageDistribution bulkStorageDistribution); }
StorageDistributionImpl implements StorageDistribution { @Override public StoredInfoResult storeDataInAllOffers(String strategyId, String objectId, ObjectDescription createObjectDescription, DataCategory category, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); checkStoreDataParams(createObjectDescription, strategyId, objectId, category); List<StorageOffer> storageOffers = getStorageOffers(strategyId); OffersToCopyIn offersToCopyIn = new OffersToCopyIn(storageOffers); final DataContext dataContext = new DataContext(objectId, category, requester, tenantId, strategyId); StorageLogbookParameters parameters = sendDataToOffersWithRetries(dataContext, offersToCopyIn, createObjectDescription); try { logStorage(tenantId, parameters); } catch (IOException e) { LOGGER.error(e); } return buildStoreDataResponse(objectId, category, parameters.getMapParameters().get(StorageLogbookParameterName.digest), strategyId, offersToCopyIn.getGlobalOfferResult()); } StorageDistributionImpl(StorageConfiguration configuration, StorageLog storageLogService); @VisibleForTesting  StorageDistributionImpl(WorkspaceClientFactory workspaceClientFactory, DigestType digestType,
        StorageLog storageLogService,
        ExecutorService batchExecutorService, int batchDigestComputationTimeout,
        BulkStorageDistribution bulkStorageDistribution); @Override StoredInfoResult copyObjectFromOfferToOffer(DataContext context, String sourceOffer, String destinationOffer); @Override StoredInfoResult storeDataInOffers(String strategyId, String objectId, DataCategory category,
        String requester,
        List<String> offerIds, Response response); @Override StoredInfoResult storeDataInOffers(String strategyId, StreamAndInfo streamAndInfo, String objectId,
        DataCategory category, String requester,
        List<String> offerIds); @Override StoredInfoResult storeDataInAllOffers(String strategyId, String objectId,
        ObjectDescription createObjectDescription, DataCategory category, String requester); @Override BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId,
        BulkObjectStoreRequest bulkObjectStoreRequest, String requester); @Override List<String> getOfferIds(String strategyId); @Override Map<String, StorageStrategy> getStrategies(); @Override JsonNode getContainerInformation(String strategyId); @Override CloseableIterator<ObjectEntry> listContainerObjects(String strategyId, DataCategory category); @Override CloseableIterator<ObjectEntry> listContainerObjectsForOffer(DataCategory category,
        String offerId, boolean includeDisabled); @Override RequestResponse<OfferLog> getOfferLogs(String strategyId, DataCategory category, Long offset, int limit,
        Order order); @Override RequestResponse<OfferLog> getOfferLogsByOfferId(String strategyId, String offerId,
        DataCategory category,
        Long offset, int limit, Order order); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category,
        AccessLogInfoModel logInformation); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category, String
        offerId); @Override JsonNode getContainerInformation(String strategyId, DataCategory type, String objectId,
        List<String> offerIds, boolean noCache); @Override Map<String, Boolean> checkObjectExisting(String strategyId, String objectId, DataCategory category,
        List<String> offerIds); @Override void deleteObjectInAllOffers(String strategyId, DataContext context); @Override void deleteObjectInOffers(String strategyId, DataContext context, List<String> offers); @Override List<BatchObjectInformationResponse> getBatchObjectInformation(String strategyId, DataCategory type,
        List<String> objectIds, List<String> offerIds); @Override void close(); }
StorageDistributionImpl implements StorageDistribution { @Override public StoredInfoResult storeDataInAllOffers(String strategyId, String objectId, ObjectDescription createObjectDescription, DataCategory category, String requester) throws StorageException { Integer tenantId = ParameterHelper.getTenantParameter(); checkStoreDataParams(createObjectDescription, strategyId, objectId, category); List<StorageOffer> storageOffers = getStorageOffers(strategyId); OffersToCopyIn offersToCopyIn = new OffersToCopyIn(storageOffers); final DataContext dataContext = new DataContext(objectId, category, requester, tenantId, strategyId); StorageLogbookParameters parameters = sendDataToOffersWithRetries(dataContext, offersToCopyIn, createObjectDescription); try { logStorage(tenantId, parameters); } catch (IOException e) { LOGGER.error(e); } return buildStoreDataResponse(objectId, category, parameters.getMapParameters().get(StorageLogbookParameterName.digest), strategyId, offersToCopyIn.getGlobalOfferResult()); } StorageDistributionImpl(StorageConfiguration configuration, StorageLog storageLogService); @VisibleForTesting  StorageDistributionImpl(WorkspaceClientFactory workspaceClientFactory, DigestType digestType,
        StorageLog storageLogService,
        ExecutorService batchExecutorService, int batchDigestComputationTimeout,
        BulkStorageDistribution bulkStorageDistribution); @Override StoredInfoResult copyObjectFromOfferToOffer(DataContext context, String sourceOffer, String destinationOffer); @Override StoredInfoResult storeDataInOffers(String strategyId, String objectId, DataCategory category,
        String requester,
        List<String> offerIds, Response response); @Override StoredInfoResult storeDataInOffers(String strategyId, StreamAndInfo streamAndInfo, String objectId,
        DataCategory category, String requester,
        List<String> offerIds); @Override StoredInfoResult storeDataInAllOffers(String strategyId, String objectId,
        ObjectDescription createObjectDescription, DataCategory category, String requester); @Override BulkObjectStoreResponse bulkCreateFromWorkspace(String strategyId,
        BulkObjectStoreRequest bulkObjectStoreRequest, String requester); @Override List<String> getOfferIds(String strategyId); @Override Map<String, StorageStrategy> getStrategies(); @Override JsonNode getContainerInformation(String strategyId); @Override CloseableIterator<ObjectEntry> listContainerObjects(String strategyId, DataCategory category); @Override CloseableIterator<ObjectEntry> listContainerObjectsForOffer(DataCategory category,
        String offerId, boolean includeDisabled); @Override RequestResponse<OfferLog> getOfferLogs(String strategyId, DataCategory category, Long offset, int limit,
        Order order); @Override RequestResponse<OfferLog> getOfferLogsByOfferId(String strategyId, String offerId,
        DataCategory category,
        Long offset, int limit, Order order); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category,
        AccessLogInfoModel logInformation); @Override Response getContainerByCategory(String strategyId, String objectId, DataCategory category, String
        offerId); @Override JsonNode getContainerInformation(String strategyId, DataCategory type, String objectId,
        List<String> offerIds, boolean noCache); @Override Map<String, Boolean> checkObjectExisting(String strategyId, String objectId, DataCategory category,
        List<String> offerIds); @Override void deleteObjectInAllOffers(String strategyId, DataContext context); @Override void deleteObjectInOffers(String strategyId, DataContext context, List<String> offers); @Override List<BatchObjectInformationResponse> getBatchObjectInformation(String strategyId, DataCategory type,
        List<String> objectIds, List<String> offerIds); @Override void close(); static final String DIGEST; }