use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.
the class ProductSyncIT method syncDrafts_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.
@Test
void syncDrafts_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndNotFoundFetchOnRetry();
final ProductSyncOptions spyOptions = ProductSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> collectErrors(exception.getMessage(), exception.getCause())).warningCallback((exception, oldResource, newResource) -> warningCallBackMessages.add(exception.getMessage())).build();
final ProductSync spyProductSync = new ProductSync(spyOptions);
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH, ProductType.referenceOfId(productType.getKey()), ResourceIdentifier.ofKey(targetTaxCategory.getKey()), ResourceIdentifier.ofKey(targetProductState.getKey()), categoryResourceIdentifiersWithKeys, categoryOrderHintsWithKeys);
final ProductSyncStatistics syncStatistics = executeBlocking(spyProductSync.sync(singletonList(productDraft)));
// Test and assertion
assertThat(syncStatistics).hasValues(1, 0, 0, 1, 0);
assertThat(errorCallBackMessages).hasSize(1);
assertThat(errorCallBackExceptions).hasSize(1);
assertThat(errorCallBackMessages.get(0)).contains(format("Failed to update Product with key: '%s'. Reason: Not found when attempting to fetch while" + " retrying after concurrency modification.", productDraft.getKey()));
}
use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.
the class ProductSyncIT method sync_withChangedProductButConcurrentModificationException_shouldRetryAndUpdateProduct.
@Test
void sync_withChangedProductButConcurrentModificationException_shouldRetryAndUpdateProduct() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
final ProductSyncOptions spyOptions = ProductSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> collectErrors(exception.getMessage(), exception.getCause())).warningCallback((exception, oldResource, newResource) -> warningCallBackMessages.add(exception.getMessage())).build();
final ProductSync spyProductSync = new ProductSync(spyOptions);
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH, ResourceIdentifier.ofKey(productType.getKey()), ResourceIdentifier.ofKey(targetTaxCategory.getKey()), ResourceIdentifier.ofKey(targetProductState.getKey()), categoryResourceIdentifiersWithKeys, categoryOrderHintsWithKeys);
final ProductSyncStatistics syncStatistics = executeBlocking(spyProductSync.sync(singletonList(productDraft)));
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.
the class ProductSyncIT method sync_withSameDraftsWithChangesInBatch_ShouldRetryUpdateBecauseOfConcurrentModificationExceptions.
@Test
void sync_withSameDraftsWithChangesInBatch_ShouldRetryUpdateBecauseOfConcurrentModificationExceptions() {
// Prepare batches from external source
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH, ProductType.reference(productType.getKey()), null, null, categoryResourceIdentifiersWithKeys, categoryOrderHintsWithKeys);
// Draft with same key
final ProductDraft draftWithSameKey = createProductDraftBuilder(PRODUCT_KEY_2_RESOURCE_PATH, ProductType.reference(productType.getKey())).taxCategory(null).state(null).categories(new ArrayList<>()).categoryOrderHints(CategoryOrderHints.of(new HashMap<>())).key(productDraft.getKey()).masterVariant(ProductVariantDraftBuilder.of(product.getMasterData().getStaged().getMasterVariant()).build()).build();
final List<ProductDraft> batch = new ArrayList<>();
batch.add(productDraft);
batch.add(draftWithSameKey);
final ProductSync productSync = new ProductSync(syncOptions);
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(batch));
assertThat(syncStatistics).hasValues(2, 0, 2, 0, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.
the class ProductSyncIT method sync_withChangedProduct_shouldUpdateProduct.
@Test
void sync_withChangedProduct_shouldUpdateProduct() {
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH, ProductType.referenceOfId(productType.getKey()), ResourceIdentifier.ofKey(targetTaxCategory.getKey()), ResourceIdentifier.ofKey(targetProductState.getKey()), categoryResourceIdentifiersWithKeys, categoryOrderHintsWithKeys);
final ProductSync productSync = new ProductSync(syncOptions);
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(productDraft)));
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.
the class ProductSyncWithAssetsIT method setupTest.
/**
* Deletes Products and Types from the target CTP project, then it populates target CTP project
* with product test data.
*/
@BeforeEach
void setupTest() {
clearSyncTestCollections();
deleteAllProducts(CTP_TARGET_CLIENT);
productSync = new ProductSync(buildSyncOptions());
assetDraftsToCreateOnExistingProduct = asList(createAssetDraft("1", ofEnglish("1"), assetsCustomType.getId()), createAssetDraft("2", ofEnglish("2"), assetsCustomType.getId()), createAssetDraft("3", ofEnglish("3"), assetsCustomType.getId()));
final ProductDraft productDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("draftName"), ofEnglish("existingSlug"), createVariantDraft("v1", assetDraftsToCreateOnExistingProduct, null)).key("existingProduct").build();
product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft)));
}
Aggregations