Skip to content

Commit 09cef24

Browse files
Merge pull request #272 from commercetools/fix-benchmarks
Fix benchmarks
2 parents 176af63 + 267e332 commit 09cef24

2 files changed

Lines changed: 18 additions & 35 deletions

File tree

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import io.sphere.sdk.inventory.InventoryEntryDraftBuilder;
1010
import io.sphere.sdk.inventory.queries.InventoryEntryQuery;
1111
import io.sphere.sdk.queries.PagedQueryResult;
12-
import io.sphere.sdk.queries.QueryPredicate;
1312
import org.junit.AfterClass;
1413
import org.junit.Before;
1514
import org.junit.Ignore;
@@ -78,16 +77,6 @@ public void sync_NewInventories_ShouldCreateInventories() throws IOException {
7877
+ " threshold of '%d'.", diff, THRESHOLD))
7978
.isLessThanOrEqualTo(THRESHOLD);
8079

81-
// Assert actual state of CTP project (number of updated inventories)
82-
final CompletableFuture<Integer> totalUpdatedInventoriesFuture =
83-
CTP_TARGET_CLIENT.execute(InventoryEntryQuery.of().withPredicates(QueryPredicate.of("version = \"2\"")))
84-
.thenApply(PagedQueryResult::getTotal)
85-
.thenApply(Long::intValue)
86-
.toCompletableFuture();
87-
88-
executeBlocking(totalUpdatedInventoriesFuture);
89-
assertThat(totalUpdatedInventoriesFuture).isCompletedWithValue(0);
90-
9180
// Assert actual state of CTP project (total number of existing inventories)
9281
final CompletableFuture<Integer> totalNumberOfInventories =
9382
CTP_TARGET_CLIENT.execute(InventoryEntryQuery.of())

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

Lines changed: 18 additions & 24 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;
@@ -116,17 +116,6 @@ public void sync_NewProducts_ShouldCreateProducts() throws IOException {
116116
diff, THRESHOLD))
117117
.isLessThanOrEqualTo(THRESHOLD);
118118

119-
// Assert actual state of CTP project (number of updated products)
120-
final CompletableFuture<Integer> totalNumberOfUpdatedProducts =
121-
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged()
122-
.withPredicates(QueryPredicate.of("version = \"2\"")))
123-
.thenApply(PagedQueryResult::getTotal)
124-
.thenApply(Long::intValue)
125-
.toCompletableFuture();
126-
127-
executeBlocking(totalNumberOfUpdatedProducts);
128-
assertThat(totalNumberOfUpdatedProducts).isCompletedWithValue(0);
129-
130119
// Assert actual state of CTP project (total number of existing products)
131120
final CompletableFuture<Integer> totalNumberOfProducts =
132121
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged())
@@ -148,11 +137,11 @@ public void sync_NewProducts_ShouldCreateProducts() throws IOException {
148137
@Test
149138
public void sync_ExistingProducts_ShouldUpdateProducts() throws IOException {
150139
final List<ProductDraft> productDrafts = buildProductDrafts(NUMBER_OF_RESOURCE_UNDER_TEST);
151-
// Create drafts to target project with different slugs
140+
// Create drafts to target project with different descriptions
152141
CompletableFuture.allOf(productDrafts.stream()
153142
.map(ProductDraftBuilder::of)
154-
.map(builder -> builder.slug(
155-
ofEnglish(builder.getSlug().get(ENGLISH) + "_old")))
143+
.map(builder -> builder.description(
144+
ofEnglish("oldDescription")))
156145
.map(builder -> builder.productType(productType.toReference()))
157146
.map(ProductDraftBuilder::build)
158147
.map(draft -> CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(draft)))
@@ -177,8 +166,10 @@ public void sync_ExistingProducts_ShouldUpdateProducts() throws IOException {
177166

178167
// Assert actual state of CTP project (number of updated products)
179168
final CompletableFuture<Integer> totalNumberOfUpdatedProducts =
180-
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged()
181-
.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")))
182173
.thenApply(PagedQueryResult::getTotal)
183174
.thenApply(Long::intValue)
184175
.toCompletableFuture();
@@ -210,11 +201,11 @@ public void sync_WithSomeExistingProducts_ShouldSyncProducts() throws IOExceptio
210201
final int halfNumberOfDrafts = productDrafts.size() / 2;
211202
final List<ProductDraft> firstHalf = productDrafts.subList(0, halfNumberOfDrafts);
212203

213-
// Create first half of drafts to target project with different slugs
204+
// Create first half of drafts to target project with different description
214205
CompletableFuture.allOf(firstHalf.stream()
215206
.map(ProductDraftBuilder::of)
216-
.map(builder -> builder.slug(
217-
ofEnglish(builder.getSlug().get(ENGLISH) + "_old")))
207+
.map(builder -> builder.description(
208+
ofEnglish("oldDescription")))
218209
.map(builder -> builder.productType(productType.toReference()))
219210
.map(ProductDraftBuilder::build)
220211
.map(draft -> CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(draft)))
@@ -239,18 +230,20 @@ public void sync_WithSomeExistingProducts_ShouldSyncProducts() throws IOExceptio
239230

240231
// Assert actual state of CTP project (number of updated products)
241232
final CompletableFuture<Integer> totalNumberOfUpdatedProducts =
242-
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged()
243-
.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")))
244237
.thenApply(PagedQueryResult::getTotal)
245238
.thenApply(Long::intValue)
246239
.toCompletableFuture();
247240

248241
executeBlocking(totalNumberOfUpdatedProducts);
249-
assertThat(totalNumberOfUpdatedProducts).isCompletedWithValue(halfNumberOfDrafts);
242+
assertThat(totalNumberOfUpdatedProducts).isCompletedWithValue(0);
250243

251244
// Assert actual state of CTP project (total number of existing products)
252245
final CompletableFuture<Integer> totalNumberOfProducts =
253-
CTP_TARGET_CLIENT.execute(ProductProjectionQuery.ofStaged())
246+
CTP_TARGET_CLIENT.execute(ProductQuery.of())
254247
.thenApply(PagedQueryResult::getTotal)
255248
.thenApply(Long::intValue)
256249
.toCompletableFuture();
@@ -278,6 +271,7 @@ private List<ProductDraft> buildProductDrafts(final int numberOfProducts) {
278271
.build();
279272
final ProductDraft productDraft = ProductDraftBuilder
280273
.of(draftsProductType, ofEnglish("name_" + i), ofEnglish("slug_" + i), masterVariantDraft)
274+
.description(ofEnglish("newDescription"))
281275
.key("productKey_" + i)
282276
.build();
283277
productDrafts.add(productDraft);

0 commit comments

Comments
 (0)