Search in sources :

Example 1 with PRODUCT_SYNC

use of com.commercetools.sync.benchmark.BenchmarkUtils.PRODUCT_SYNC in project commercetools-sync-java by commercetools.

the class ProductSyncBenchmark method sync_ExistingProducts_ShouldUpdateProducts.

@Test
void sync_ExistingProducts_ShouldUpdateProducts() throws IOException {
    final List<ProductDraft> productDrafts = buildProductDrafts(NUMBER_OF_RESOURCE_UNDER_TEST);
    // Create drafts to target project with different descriptions
    CompletableFuture.allOf(productDrafts.stream().map(ProductDraftBuilder::of).map(builder -> builder.description(ofEnglish("oldDescription"))).map(builder -> builder.productType(productType.toReference())).map(ProductDraftBuilder::build).map(draft -> CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(draft))).map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new)).join();
    // Sync new drafts
    final ProductSync productSync = new ProductSync(syncOptions);
    final long beforeSyncTime = System.currentTimeMillis();
    final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(productDrafts));
    final long totalTime = System.currentTimeMillis() - beforeSyncTime;
    // assert on threshold (based on history of benchmarks; highest was ~19 seconds)
    // double of the highest benchmark
    final int threshold = 38000;
    assertThat(totalTime).withFailMessage(format(THRESHOLD_EXCEEDED_ERROR, totalTime, threshold)).isLessThan(threshold);
    // Assert actual state of CTP project (number of updated products)
    final CompletableFuture<Integer> totalNumberOfUpdatedProducts = CTP_TARGET_CLIENT.execute(ProductQuery.of().withPredicates(p -> p.masterData().staged().description().locale(ENGLISH).is("newDescription"))).thenApply(PagedQueryResult::getTotal).thenApply(Long::intValue).toCompletableFuture();
    executeBlocking(totalNumberOfUpdatedProducts);
    assertThat(totalNumberOfUpdatedProducts).isCompletedWithValue(NUMBER_OF_RESOURCE_UNDER_TEST);
    // Assert actual state of CTP project (total number of existing products)
    final CompletableFuture<Integer> totalNumberOfProducts = CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged()).thenApply(PagedQueryResult::getTotal).thenApply(Long::intValue).toCompletableFuture();
    executeBlocking(totalNumberOfProducts);
    assertThat(totalNumberOfProducts).isCompletedWithValue(NUMBER_OF_RESOURCE_UNDER_TEST);
    // Assert statistics
    assertThat(syncStatistics).hasValues(NUMBER_OF_RESOURCE_UNDER_TEST, 0, NUMBER_OF_RESOURCE_UNDER_TEST, 0);
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    saveNewResult(PRODUCT_SYNC, UPDATES_ONLY, totalTime);
}
Also used : ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) PRODUCT_TYPE_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_RESOURCE_PATH) SyncException(com.commercetools.sync.commons.exceptions.SyncException) THRESHOLD_EXCEEDED_ERROR(com.commercetools.sync.benchmark.BenchmarkUtils.THRESHOLD_EXCEEDED_ERROR) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) ProductITUtils.deleteProductSyncTestData(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) CREATES_ONLY(com.commercetools.sync.benchmark.BenchmarkUtils.CREATES_ONLY) OLD_CATEGORY_CUSTOM_TYPE_NAME(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) ENGLISH(java.util.Locale.ENGLISH) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Product(io.sphere.sdk.products.Product) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CompletionStage(java.util.concurrent.CompletionStage) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) Optional(java.util.Optional) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ProductType(io.sphere.sdk.producttypes.ProductType) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) ProductITUtils.deleteAllProducts(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts) ProductQuery(io.sphere.sdk.products.queries.ProductQuery) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) NUMBER_OF_RESOURCE_UNDER_TEST(com.commercetools.sync.benchmark.BenchmarkUtils.NUMBER_OF_RESOURCE_UNDER_TEST) CREATES_AND_UPDATES(com.commercetools.sync.benchmark.BenchmarkUtils.CREATES_AND_UPDATES) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) Nonnull(javax.annotation.Nonnull) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) IOException(java.io.IOException) PRODUCT_SYNC(com.commercetools.sync.benchmark.BenchmarkUtils.PRODUCT_SYNC) UPDATES_ONLY(com.commercetools.sync.benchmark.BenchmarkUtils.UPDATES_ONLY) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) BenchmarkUtils.saveNewResult(com.commercetools.sync.benchmark.BenchmarkUtils.saveNewResult) ProductVariantDraftBuilder(io.sphere.sdk.products.ProductVariantDraftBuilder) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with PRODUCT_SYNC

use of com.commercetools.sync.benchmark.BenchmarkUtils.PRODUCT_SYNC in project commercetools-sync-java by commercetools.

the class ProductSyncBenchmark method sync_WithSomeExistingProducts_ShouldSyncProducts.

@Test
void sync_WithSomeExistingProducts_ShouldSyncProducts() throws IOException {
    final List<ProductDraft> productDrafts = buildProductDrafts(NUMBER_OF_RESOURCE_UNDER_TEST);
    final int halfNumberOfDrafts = productDrafts.size() / 2;
    final List<ProductDraft> firstHalf = productDrafts.subList(0, halfNumberOfDrafts);
    // Create first half of drafts to target project with different description
    CompletableFuture.allOf(firstHalf.stream().map(ProductDraftBuilder::of).map(builder -> builder.description(ofEnglish("oldDescription"))).map(builder -> builder.productType(productType.toReference())).map(ProductDraftBuilder::build).map(draft -> CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(draft))).map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new)).join();
    // Sync new drafts
    final ProductSync productSync = new ProductSync(syncOptions);
    final long beforeSyncTime = System.currentTimeMillis();
    final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(productDrafts));
    final long totalTime = System.currentTimeMillis() - beforeSyncTime;
    // assert on threshold (based on history of benchmarks; highest was ~19 seconds)
    // double of the highest benchmark
    final int threshold = 38000;
    assertThat(totalTime).withFailMessage(format(THRESHOLD_EXCEEDED_ERROR, totalTime, threshold)).isLessThan(threshold);
    // Assert actual state of CTP project (number of updated products)
    final CompletableFuture<Integer> totalNumberOfUpdatedProducts = CTP_TARGET_CLIENT.execute(ProductQuery.of().withPredicates(p -> p.masterData().staged().description().locale(ENGLISH).is("oldDescription"))).thenApply(PagedQueryResult::getTotal).thenApply(Long::intValue).toCompletableFuture();
    executeBlocking(totalNumberOfUpdatedProducts);
    assertThat(totalNumberOfUpdatedProducts).isCompletedWithValue(0);
    // Assert actual state of CTP project (total number of existing products)
    final CompletableFuture<Integer> totalNumberOfProducts = CTP_TARGET_CLIENT.execute(ProductQuery.of()).thenApply(PagedQueryResult::getTotal).thenApply(Long::intValue).toCompletableFuture();
    executeBlocking(totalNumberOfProducts);
    assertThat(totalNumberOfProducts).isCompletedWithValue(NUMBER_OF_RESOURCE_UNDER_TEST);
    // Assert statistics
    assertThat(syncStatistics).hasValues(NUMBER_OF_RESOURCE_UNDER_TEST, halfNumberOfDrafts, halfNumberOfDrafts, 0);
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    saveNewResult(PRODUCT_SYNC, CREATES_AND_UPDATES, totalTime);
}
Also used : ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) PRODUCT_TYPE_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_RESOURCE_PATH) SyncException(com.commercetools.sync.commons.exceptions.SyncException) THRESHOLD_EXCEEDED_ERROR(com.commercetools.sync.benchmark.BenchmarkUtils.THRESHOLD_EXCEEDED_ERROR) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) ProductITUtils.deleteProductSyncTestData(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) CREATES_ONLY(com.commercetools.sync.benchmark.BenchmarkUtils.CREATES_ONLY) OLD_CATEGORY_CUSTOM_TYPE_NAME(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) ENGLISH(java.util.Locale.ENGLISH) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Product(io.sphere.sdk.products.Product) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CompletionStage(java.util.concurrent.CompletionStage) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) Optional(java.util.Optional) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ProductType(io.sphere.sdk.producttypes.ProductType) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) ProductITUtils.deleteAllProducts(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts) ProductQuery(io.sphere.sdk.products.queries.ProductQuery) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) NUMBER_OF_RESOURCE_UNDER_TEST(com.commercetools.sync.benchmark.BenchmarkUtils.NUMBER_OF_RESOURCE_UNDER_TEST) CREATES_AND_UPDATES(com.commercetools.sync.benchmark.BenchmarkUtils.CREATES_AND_UPDATES) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) Nonnull(javax.annotation.Nonnull) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) IOException(java.io.IOException) PRODUCT_SYNC(com.commercetools.sync.benchmark.BenchmarkUtils.PRODUCT_SYNC) UPDATES_ONLY(com.commercetools.sync.benchmark.BenchmarkUtils.UPDATES_ONLY) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) BenchmarkUtils.saveNewResult(com.commercetools.sync.benchmark.BenchmarkUtils.saveNewResult) ProductVariantDraftBuilder(io.sphere.sdk.products.ProductVariantDraftBuilder) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

CREATES_AND_UPDATES (com.commercetools.sync.benchmark.BenchmarkUtils.CREATES_AND_UPDATES)2 CREATES_ONLY (com.commercetools.sync.benchmark.BenchmarkUtils.CREATES_ONLY)2 NUMBER_OF_RESOURCE_UNDER_TEST (com.commercetools.sync.benchmark.BenchmarkUtils.NUMBER_OF_RESOURCE_UNDER_TEST)2 PRODUCT_SYNC (com.commercetools.sync.benchmark.BenchmarkUtils.PRODUCT_SYNC)2 THRESHOLD_EXCEEDED_ERROR (com.commercetools.sync.benchmark.BenchmarkUtils.THRESHOLD_EXCEEDED_ERROR)2 UPDATES_ONLY (com.commercetools.sync.benchmark.BenchmarkUtils.UPDATES_ONLY)2 BenchmarkUtils.saveNewResult (com.commercetools.sync.benchmark.BenchmarkUtils.saveNewResult)2 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)2 SyncException (com.commercetools.sync.commons.exceptions.SyncException)2 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)2 TriConsumer (com.commercetools.sync.commons.utils.TriConsumer)2 OLD_CATEGORY_CUSTOM_TYPE_KEY (com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY)2 OLD_CATEGORY_CUSTOM_TYPE_NAME (com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME)2 CategoryITUtils.createCategoriesCustomType (com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType)2 ProductITUtils.deleteAllProducts (com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts)2 ProductITUtils.deleteProductSyncTestData (com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData)2 ProductTypeITUtils.createProductType (com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType)2 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)2 ProductSync (com.commercetools.sync.products.ProductSync)2 PRODUCT_TYPE_RESOURCE_PATH (com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_RESOURCE_PATH)2