Skip to content

Commit 267e332

Browse files
committed
Fix benchmarks.
1 parent c3deb1e commit 267e332

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

src/benchmark/java/com/commercetools/sync/benchmark/ProductSyncBenchmark.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import io.sphere.sdk.products.ProductVariantDraftBuilder;
1414
import io.sphere.sdk.products.commands.ProductCreateCommand;
1515
import io.sphere.sdk.products.queries.ProductProjectionQuery;
16+
import io.sphere.sdk.products.queries.ProductQuery;
1617
import io.sphere.sdk.producttypes.ProductType;
1718
import io.sphere.sdk.queries.PagedQueryResult;
18-
import io.sphere.sdk.queries.QueryPredicate;
1919
import org.junit.AfterClass;
2020
import org.junit.Before;
2121
import org.junit.BeforeClass;
@@ -137,11 +137,11 @@ public void sync_NewProducts_ShouldCreateProducts() throws IOException {
137137
@Test
138138
public void sync_ExistingProducts_ShouldUpdateProducts() throws IOException {
139139
final List<ProductDraft> productDrafts = buildProductDrafts(NUMBER_OF_RESOURCE_UNDER_TEST);
140-
// Create drafts to target project with different slugs
140+
// Create drafts to target project with different descriptions
141141
CompletableFuture.allOf(productDrafts.stream()
142142
.map(ProductDraftBuilder::of)
143-
.map(builder -> builder.slug(
144-
ofEnglish(builder.getSlug().get(ENGLISH) + "_old")))
143+
.map(builder -> builder.description(
144+
ofEnglish("oldDescription")))
145145
.map(builder -> builder.productType(productType.toReference()))
146146
.map(ProductDraftBuilder::build)
147147
.map(draft -> CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(draft)))
@@ -166,8 +166,10 @@ public void sync_ExistingProducts_ShouldUpdateProducts() throws IOException {
166166

167167
// Assert actual state of CTP project (number of updated products)
168168
final CompletableFuture<Integer> totalNumberOfUpdatedProducts =
169-
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged()
170-
.withPredicates(QueryPredicate.of("version = \"2\"")))
169+
CTP_TARGET_CLIENT.execute(ProductQuery.of()
170+
.withPredicates(p -> p.masterData().staged()
171+
.description().locale(ENGLISH)
172+
.is("newDescription")))
171173
.thenApply(PagedQueryResult::getTotal)
172174
.thenApply(Long::intValue)
173175
.toCompletableFuture();
@@ -199,11 +201,11 @@ public void sync_WithSomeExistingProducts_ShouldSyncProducts() throws IOExceptio
199201
final int halfNumberOfDrafts = productDrafts.size() / 2;
200202
final List<ProductDraft> firstHalf = productDrafts.subList(0, halfNumberOfDrafts);
201203

202-
// Create first half of drafts to target project with different slugs
204+
// Create first half of drafts to target project with different description
203205
CompletableFuture.allOf(firstHalf.stream()
204206
.map(ProductDraftBuilder::of)
205-
.map(builder -> builder.slug(
206-
ofEnglish(builder.getSlug().get(ENGLISH) + "_old")))
207+
.map(builder -> builder.description(
208+
ofEnglish("oldDescription")))
207209
.map(builder -> builder.productType(productType.toReference()))
208210
.map(ProductDraftBuilder::build)
209211
.map(draft -> CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(draft)))
@@ -228,18 +230,20 @@ public void sync_WithSomeExistingProducts_ShouldSyncProducts() throws IOExceptio
228230

229231
// Assert actual state of CTP project (number of updated products)
230232
final CompletableFuture<Integer> totalNumberOfUpdatedProducts =
231-
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged()
232-
.withPredicates(QueryPredicate.of("version = \"2\"")))
233+
CTP_TARGET_CLIENT.execute(ProductQuery.of()
234+
.withPredicates(p -> p.masterData().staged()
235+
.description().locale(ENGLISH)
236+
.is("oldDescription")))
233237
.thenApply(PagedQueryResult::getTotal)
234238
.thenApply(Long::intValue)
235239
.toCompletableFuture();
236240

237241
executeBlocking(totalNumberOfUpdatedProducts);
238-
assertThat(totalNumberOfUpdatedProducts).isCompletedWithValue(halfNumberOfDrafts);
242+
assertThat(totalNumberOfUpdatedProducts).isCompletedWithValue(0);
239243

240244
// Assert actual state of CTP project (total number of existing products)
241245
final CompletableFuture<Integer> totalNumberOfProducts =
242-
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged())
246+
CTP_TARGET_CLIENT.execute(ProductQuery.of())
243247
.thenApply(PagedQueryResult::getTotal)
244248
.thenApply(Long::intValue)
245249
.toCompletableFuture();
@@ -267,6 +271,7 @@ private List<ProductDraft> buildProductDrafts(final int numberOfProducts) {
267271
.build();
268272
final ProductDraft productDraft = ProductDraftBuilder
269273
.of(draftsProductType, ofEnglish("name_" + i), ofEnglish("slug_" + i), masterVariantDraft)
274+
.description(ofEnglish("newDescription"))
270275
.key("productKey_" + i)
271276
.build();
272277
productDrafts.add(productDraft);

0 commit comments

Comments
 (0)