use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_DRAFT_2 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithConcurrentModificationException_ShouldRetryToUpdateNewCartDiscountWithSuccess.
@Test
void sync_WithConcurrentModificationException_ShouldRetryToUpdateNewCartDiscountWithSuccess() {
// Preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
final CartDiscountDraft draft2 = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_2).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CART_DISCOUNT_TYPE_KEY, createCustomFieldsJsonMap())).build();
CTP_TARGET_CLIENT.execute(CartDiscountCreateCommand.of(draft2)).toCompletableFuture().join();
final CartDiscountDraft updatedDraft = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_2).description(CART_DISCOUNT_DESC_1).build();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(spyClient).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
// test
final CartDiscountSyncStatistics statistics = cartDiscountSync.sync(singletonList(updatedDraft)).toCompletableFuture().join();
// assertion
assertThat(statistics).hasValues(1, 0, 1, 0);
// Assert CTP state.
final PagedQueryResult<CartDiscount> queryResult = CTP_TARGET_CLIENT.execute(CartDiscountQuery.of().plusPredicates(queryModel -> queryModel.key().is(CART_DISCOUNT_KEY_1))).toCompletableFuture().join();
assertThat(queryResult.head()).hasValueSatisfying(cartDiscount -> assertThat(cartDiscount.getKey()).isEqualTo(CART_DISCOUNT_KEY_1));
}
use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_DRAFT_2 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate.
@Test
void sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndFailedFetchOnRetry();
final CartDiscountDraft draft2 = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_2).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CART_DISCOUNT_TYPE_KEY, createCustomFieldsJsonMap())).build();
CTP_TARGET_CLIENT.execute(CartDiscountCreateCommand.of(draft2)).toCompletableFuture().join();
final CartDiscountDraft updatedDraft = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_2).description(CART_DISCOUNT_DESC_1).build();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, actions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception);
}).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
// test
final CartDiscountSyncStatistics statistics = cartDiscountSync.sync(singletonList(updatedDraft)).toCompletableFuture().join();
// assertion
assertThat(statistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1);
assertThat(exceptions).hasSize(1);
assertThat(exceptions.get(0).getCause()).hasCauseExactlyInstanceOf(BadGatewayException.class);
assertThat(errorMessages.get(0)).contains(format("Failed to update cart discount with key: '%s'. Reason: Failed to fetch from CTP while retrying " + "after concurrency modification.", CART_DISCOUNT_KEY_2));
}
use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_DRAFT_2 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.
@Test
void sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndNotFoundFetchOnRetry();
final CartDiscountDraft draft2 = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_2).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CART_DISCOUNT_TYPE_KEY, createCustomFieldsJsonMap())).build();
CTP_TARGET_CLIENT.execute(CartDiscountCreateCommand.of(draft2)).toCompletableFuture().join();
final CartDiscountDraft updatedDraft = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_2).description(CART_DISCOUNT_DESC_1).build();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, actions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception);
}).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
// test
final CartDiscountSyncStatistics statistics = cartDiscountSync.sync(singletonList(updatedDraft)).toCompletableFuture().join();
// Assertion
assertThat(statistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1);
assertThat(exceptions).hasSize(1);
assertThat(errorMessages.get(0)).contains(format("Failed to update cart discount with key: '%s'. Reason: Not found when attempting to fetch while " + "retrying after concurrency modification.", CART_DISCOUNT_KEY_2));
}
Aggregations