use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate.
@Test
void sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate() {
// preparation
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingList.getKey()).thenReturn("shoppingListKey");
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(anySet())).thenReturn(completedFuture(singleton(mockShoppingList)));
when(mockShoppingListService.updateShoppingList(any(), anyList())).thenReturn(exceptionallyCompletedFuture(new SphereException(new ConcurrentModificationException()))).thenReturn(completedFuture(mockShoppingList));
when(mockShoppingListService.fetchShoppingList("shoppingListKey")).thenReturn(exceptionallyCompletedFuture(new SphereException()));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), mock(TypeService.class));
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shoppingListName")).key("shoppingListKey").build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to fetch from CTP while retrying after concurrency modification.");
assertThat(exceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasRootCauseExactlyInstanceOf(SphereException.class);
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithExceptionOnReferenceResolution_ShouldFailToUpdateAndIncreaseFailedCounter.
@Test
void sync_WithExceptionOnReferenceResolution_ShouldFailToUpdateAndIncreaseFailedCounter() {
// preparation
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingList.getKey()).thenReturn("shoppingListKey");
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(anySet())).thenReturn(completedFuture(singleton(mockShoppingList)));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final TypeService typeService = mock(TypeService.class);
when(typeService.fetchCachedTypeId(anyString())).thenReturn(CompletableFutureUtils.failed(new SphereException("CTP error on fetch")));
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), typeService);
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shoppingListName")).key("shoppingListKey").build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to process the ShoppingListDraft with key:'shoppingListKey'");
assertThat(exceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class);
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.
@Test
void sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
// preparation
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingList.getKey()).thenReturn("shoppingListKey");
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(anySet())).thenReturn(completedFuture(singleton(mockShoppingList)));
when(mockShoppingListService.updateShoppingList(any(), anyList())).thenReturn(exceptionallyCompletedFuture(new SphereException(new ConcurrentModificationException()))).thenReturn(completedFuture(mockShoppingList));
when(mockShoppingListService.fetchShoppingList("shoppingListKey")).thenReturn(completedFuture(Optional.empty()));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), mock(TypeService.class));
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shoppingListName")).key("shoppingListKey").build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Not found when attempting to fetch while retrying after concurrency modification.");
assertThat(exceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasNoCause();
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithOnlyDraftsToUpdate_ShouldOnlyCallBeforeUpdateCallback.
@Test
void sync_WithOnlyDraftsToUpdate_ShouldOnlyCallBeforeUpdateCallback() {
// preparation
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingList.getKey()).thenReturn("shoppingListKey");
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(anySet())).thenReturn(completedFuture(singleton(mockShoppingList)));
when(mockShoppingListService.updateShoppingList(any(), anyList())).thenReturn(completedFuture(mockShoppingList));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), mock(TypeService.class));
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("NAME")).key("shoppingListKey").build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 0, 1, 0);
verify(spySyncOptions).applyBeforeUpdateCallback(any(), any(), any());
verify(spySyncOptions, never()).applyBeforeCreateCallback(shoppingListDraft);
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncIT method sync_WithModifiedShoppingList_ShouldUpdateShoppingList.
@Test
void sync_WithModifiedShoppingList_ShouldUpdateShoppingList() {
final ShoppingListDraft modifiedShoppingListDraft = prepareUpdatedDraft();
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(modifiedShoppingListDraft)).toCompletableFuture().join();
assertThat(errorMessages).isEmpty();
assertThat(warningMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertUpdateActions();
assertThat(shoppingListSyncStatistics).hasValues(1, 0, 1, 0);
assertThat(shoppingListSyncStatistics.getReportMessage()).isEqualTo("Summary: 1 shopping lists were processed in total " + "(0 created, 1 updated and 0 failed to sync).");
assertShoppingListUpdatedCorrectly(modifiedShoppingListDraft);
}
Aggregations