Search in sources :

Example 1 with QUANTITY_ON_STOCK_1

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SUPPLY_CHANNEL_KEY_2(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SUPPLY_CHANNEL_KEY_2) SUPPLY_CHANNEL_KEY_1(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SUPPLY_CHANNEL_KEY_1) Reference(io.sphere.sdk.models.Reference) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) SyncException(com.commercetools.sync.commons.exceptions.SyncException) InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) ITUtils.deleteTypesFromTargetAndSource(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypesFromTargetAndSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) InventorySyncOptionsBuilder(com.commercetools.sync.inventories.InventorySyncOptionsBuilder) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) Disabled(org.junit.jupiter.api.Disabled) Channel(io.sphere.sdk.channels.Channel) Collections.singletonList(java.util.Collections.singletonList) ExpansionPath(io.sphere.sdk.expansion.ExpansionPath) AfterAll(org.junit.jupiter.api.AfterAll) SKU_2(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SKU_2) SKU_1(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SKU_1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChannelQuery(io.sphere.sdk.channels.queries.ChannelQuery) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) RESTOCKABLE_IN_DAYS_1(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.RESTOCKABLE_IN_DAYS_1) RESTOCKABLE_IN_DAYS_2(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.RESTOCKABLE_IN_DAYS_2) InventoryITUtils.populateSourceProject(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.populateSourceProject) Test(org.junit.jupiter.api.Test) InventoryITUtils.populateTargetProject(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.populateTargetProject) InventoryEntryDraftBuilder(io.sphere.sdk.inventory.InventoryEntryDraftBuilder) List(java.util.List) InventorySyncOptions(com.commercetools.sync.inventories.InventorySyncOptions) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) IntStream(java.util.stream.IntStream) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CompletableFuture(java.util.concurrent.CompletableFuture) InventoryEntryQuery(io.sphere.sdk.inventory.queries.InventoryEntryQuery) Nonnull(javax.annotation.Nonnull) InventoryITUtils.getChannelByKey(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.getChannelByKey) Nullable(javax.annotation.Nullable) InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel) ChannelRole(io.sphere.sdk.channels.ChannelRole) LongStream(java.util.stream.LongStream) EXPECTED_DELIVERY_1(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.EXPECTED_DELIVERY_1) EXPECTED_DELIVERY_2(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.EXPECTED_DELIVERY_2) ChannelITUtils.deleteChannelsFromTargetAndSource(com.commercetools.sync.integration.commons.utils.ChannelITUtils.deleteChannelsFromTargetAndSource) REFERENCE_ID_TO_KEY_CACHE(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.REFERENCE_ID_TO_KEY_CACHE) InventoryITUtils.deleteInventoryEntriesFromTargetAndSource(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.deleteInventoryEntriesFromTargetAndSource) InventorySync(com.commercetools.sync.inventories.InventorySync) QUANTITY_ON_STOCK_1(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.QUANTITY_ON_STOCK_1) Collectors.toList(java.util.stream.Collectors.toList) InventoryEntryExpansionModel(io.sphere.sdk.inventory.expansion.InventoryEntryExpansionModel) InventoryTransformUtils(com.commercetools.sync.inventories.utils.InventoryTransformUtils) QUANTITY_ON_STOCK_2(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.QUANTITY_ON_STOCK_2) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) InventorySync(com.commercetools.sync.inventories.InventorySync) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventorySyncOptions(com.commercetools.sync.inventories.InventorySyncOptions) Test(org.junit.jupiter.api.Test)

Aggregations

AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)1 SyncException (com.commercetools.sync.commons.exceptions.SyncException)1 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)1 ChannelITUtils.deleteChannelsFromTargetAndSource (com.commercetools.sync.integration.commons.utils.ChannelITUtils.deleteChannelsFromTargetAndSource)1 ITUtils.deleteTypesFromTargetAndSource (com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypesFromTargetAndSource)1 CTP_SOURCE_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT)1 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)1 EXPECTED_DELIVERY_1 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.EXPECTED_DELIVERY_1)1 EXPECTED_DELIVERY_2 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.EXPECTED_DELIVERY_2)1 QUANTITY_ON_STOCK_1 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.QUANTITY_ON_STOCK_1)1 QUANTITY_ON_STOCK_2 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.QUANTITY_ON_STOCK_2)1 REFERENCE_ID_TO_KEY_CACHE (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.REFERENCE_ID_TO_KEY_CACHE)1 RESTOCKABLE_IN_DAYS_1 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.RESTOCKABLE_IN_DAYS_1)1 RESTOCKABLE_IN_DAYS_2 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.RESTOCKABLE_IN_DAYS_2)1 SKU_1 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SKU_1)1 SKU_2 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SKU_2)1 SUPPLY_CHANNEL_KEY_1 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SUPPLY_CHANNEL_KEY_1)1 SUPPLY_CHANNEL_KEY_2 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SUPPLY_CHANNEL_KEY_2)1 InventoryITUtils.deleteInventoryEntriesFromTargetAndSource (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.deleteInventoryEntriesFromTargetAndSource)1 InventoryITUtils.getChannelByKey (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.getChannelByKey)1