use of com.commercetools.sync.integration.inventories.utils.InventoryITUtils.QUANTITY_ON_STOCK_1 in project commercetools-sync-java by commercetools.
the class InventorySyncIT method sync_WithSyncDifferentBatchesConcurrently_ShouldReturnProperStatistics.
@Test
void sync_WithSyncDifferentBatchesConcurrently_ShouldReturnProperStatistics() {
// Prepare new inventories.
final List<InventoryEntryDraft> newDrafts = IntStream.range(100, 160).mapToObj(i -> InventoryEntryDraftBuilder.of(String.valueOf(i), QUANTITY_ON_STOCK_1).build()).collect(toList());
// Split them to batches.
final List<InventoryEntryDraft> firstBatch = newDrafts.subList(0, 20);
final List<InventoryEntryDraft> secondBatch = newDrafts.subList(20, 40);
final List<InventoryEntryDraft> thirdBatch = newDrafts.subList(40, 60);
// Initialize sync.
final InventorySyncOptions inventorySyncOptions = InventorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final InventorySync inventorySync = new InventorySync(inventorySyncOptions);
// Run batch syncing concurrently.
final CompletableFuture<InventorySyncStatistics> firstResult = inventorySync.sync(firstBatch).toCompletableFuture();
final CompletableFuture<InventorySyncStatistics> secondResult = inventorySync.sync(secondBatch).toCompletableFuture();
final CompletableFuture<InventorySyncStatistics> thirdResult = inventorySync.sync(thirdBatch).toCompletableFuture();
CompletableFuture.allOf(firstResult, secondResult, thirdResult).join();
// Ensure instance's statistics.
assertThat(inventorySync.getStatistics()).hasValues(60, 60, 0, 0);
}
Aggregations