use of org.folio.inventory.common.domain.Failure in project mod-inventory by folio-org.
the class ExternalItemCollectionFailureExamples method serverErrorWhenDeletingAnItemByIdTriggersFailureCallback.
@Test
public void serverErrorWhenDeletingAnItemByIdTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException {
ItemCollection collection = createCollection();
CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
collection.delete(UUID.randomUUID().toString(), success -> fail("Completion callback should not be called"), failureCalled::complete);
Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
check(failure);
}
use of org.folio.inventory.common.domain.Failure in project mod-inventory by folio-org.
the class ExternalItemCollectionFailureExamples method serverErrorWhenCreatingAnItemTriggersFailureCallback.
@Test
public void serverErrorWhenCreatingAnItemTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException {
ItemCollection collection = createCollection();
CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
collection.add(createItem(), success -> fail("Completion callback should not be called"), failureCalled::complete);
Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
check(failure);
}
use of org.folio.inventory.common.domain.Failure in project mod-inventory by folio-org.
the class ExternalItemCollectionFailureExamples method serverErrorWhenFindingItemsTriggersFailureCallback.
@Test
public void serverErrorWhenFindingItemsTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
ItemCollection collection = createCollection();
CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
collection.findByCql("title=\"*Small Angry*\"", new PagingParameters(10, 0), success -> fail("Completion callback should not be called"), failureCalled::complete);
Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
check(failure);
}
use of org.folio.inventory.common.domain.Failure in project mod-inventory by folio-org.
the class ExternalItemCollectionFailureExamples method serverErrorWhenGettingAllItemsTriggersFailureCallback.
@Test
public void serverErrorWhenGettingAllItemsTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException {
ItemCollection collection = createCollection();
CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
collection.findAll(PagingParameters.defaults(), success -> fail("Completion callback should not be called"), failureCalled::complete);
Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
check(failure);
}
use of org.folio.inventory.common.domain.Failure in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method shouldSendErrorEventWhenFailedToFetchRecordFromStorage.
@Test
public void shouldSendErrorEventWhenFailedToFetchRecordFromStorage(TestContext context) throws InterruptedException {
// given
Async async = context.async();
Map<String, String> payload = new HashMap<>();
payload.put("RECORD_TYPE", "MARC_AUTHORITY");
payload.put("MARC_AUTHORITY", Json.encode(authorityRecord));
payload.put("MAPPING_RULES", authorityMappingRules.encode());
payload.put("MAPPING_PARAMS", new JsonObject().encode());
payload.put("PARSED_RECORD_DTO", Json.encode(new ParsedRecordDto().withRecordType(ParsedRecordDto.RecordType.MARC_AUTHORITY).withRelatedRecordVersion("1")));
Event event = new Event().withId("01").withEventPayload(Json.encode(payload));
String expectedKafkaRecordKey = "test_key";
when(kafkaRecord.key()).thenReturn(expectedKafkaRecordKey);
when(kafkaRecord.value()).thenReturn(Json.encode(event));
doAnswer(invocationOnMock -> {
Consumer<Failure> failureHandler = invocationOnMock.getArgument(2);
failureHandler.accept(new Failure("Unexpected failure", 500));
return null;
}).when(mockedAuthorityRecordCollection).findById(anyString(), any(), any());
// when
Future<String> future = handler.handle(kafkaRecord);
// then
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_ERROR.name());
cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(expectedKafkaRecordKey, ar.result());
async.complete();
});
}
Aggregations