use of com.commercetools.sync.categories.CategorySync in project commercetools-sync-java by commercetools.
the class CategorySyncIT method syncDrafts_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.
@Test
void syncDrafts_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
// Preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndNotFoundFetchOnRetry();
final CategoryDraft categoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "Modern Furniture"), LocalizedString.of(Locale.ENGLISH, "modern-furniture")).key(oldCategoryKey).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> errors = new ArrayList<>();
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
errors.add(exception.getCause());
}).build();
final CategorySync categorySync = new CategorySync(categorySyncOptions);
final CategorySyncStatistics statistics = categorySync.sync(Collections.singletonList(categoryDraft)).toCompletableFuture().join();
// Test and assertion
assertThat(statistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1);
assertThat(errors).hasSize(1);
assertThat(errorMessages.get(0)).contains(format("Failed to update Category with key: '%s'. Reason: Not found when attempting to fetch while" + " retrying after concurrency modification.", categoryDraft.getKey()));
}
use of com.commercetools.sync.categories.CategorySync in project commercetools-sync-java by commercetools.
the class CategorySyncIT method setupTest.
/**
* Deletes Categories and Types from target CTP project, then it populates it with category test
* data.
*/
@BeforeEach
void setupTest() {
deleteAllCategories(CTP_TARGET_CLIENT);
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
categorySync = new CategorySync(categorySyncOptions);
// Create a mock in the target project.
final CategoryDraft oldCategoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "furniture"), LocalizedString.of(Locale.ENGLISH, "furniture")).key(oldCategoryKey).custom(getCustomFieldsDraft()).build();
CTP_TARGET_CLIENT.execute(CategoryCreateCommand.of(oldCategoryDraft)).toCompletableFuture().join();
}
use of com.commercetools.sync.categories.CategorySync in project commercetools-sync-java by commercetools.
the class CategorySyncIT method syncDrafts_WithConcurrentModificationException_ShouldRetryToUpdateNewCategoryWithSuccess.
@Test
void syncDrafts_WithConcurrentModificationException_ShouldRetryToUpdateNewCategoryWithSuccess() {
// Preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
final LocalizedString newCategoryName = LocalizedString.of(Locale.ENGLISH, "Modern Furniture");
final CategoryDraft categoryDraft = CategoryDraftBuilder.of(newCategoryName, LocalizedString.of(Locale.ENGLISH, "modern-furniture")).key(oldCategoryKey).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(spyClient).build();
final CategorySync categorySync = new CategorySync(categorySyncOptions);
// Test
final CategorySyncStatistics statistics = categorySync.sync(Collections.singletonList(categoryDraft)).toCompletableFuture().join();
// Assertion
assertThat(statistics).hasValues(1, 0, 1, 0);
// Assert CTP state.
final PagedQueryResult<Category> queryResult = CTP_TARGET_CLIENT.execute(CategoryQuery.of().plusPredicates(categoryQueryModel -> categoryQueryModel.key().is(categoryDraft.getKey()))).toCompletableFuture().join();
assertThat(queryResult.head()).hasValueSatisfying(category -> assertThat(category.getName()).isEqualTo(newCategoryName));
}
use of com.commercetools.sync.categories.CategorySync in project commercetools-sync-java by commercetools.
the class CategorySyncIT method syncDrafts_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate.
@Test
void syncDrafts_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate() {
// Preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndFailedFetchOnRetry();
final CategoryDraft categoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "Modern Furniture"), LocalizedString.of(Locale.ENGLISH, "modern-furniture")).key(oldCategoryKey).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> errors = new ArrayList<>();
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
errors.add(exception.getCause());
}).build();
final CategorySync categorySync = new CategorySync(categorySyncOptions);
final CategorySyncStatistics statistics = categorySync.sync(Collections.singletonList(categoryDraft)).toCompletableFuture().join();
// Test and assertion
assertThat(statistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1);
assertThat(errors).hasSize(1);
assertThat(errors.get(0).getCause()).isExactlyInstanceOf(BadGatewayException.class);
assertThat(errorMessages.get(0)).contains("Reason: Failed to fetch from CTP while retrying after concurrency modification.");
}
use of com.commercetools.sync.categories.CategorySync in project commercetools-sync-java by commercetools.
the class CategorySyncIT method setupTest.
/**
* Deletes Categories and Types from source and target CTP projects, then it populates target CTP
* project with category test data.
*/
@BeforeEach
void setupTest() {
deleteAllCategories(CTP_TARGET_CLIENT);
deleteAllCategories(CTP_SOURCE_CLIENT);
createCategories(CTP_TARGET_CLIENT, getCategoryDrafts(null, 2));
callBackErrorResponses = new ArrayList<>();
callBackExceptions = new ArrayList<>();
callBackWarningResponses = new ArrayList<>();
categorySync = new CategorySync(buildCategorySyncOptions(50));
referenceIdToKeyCache = new CaffeineReferenceIdToKeyCacheImpl();
}
Aggregations