Search in sources :

Example 46 with Failure

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ItemCollection(org.folio.inventory.domain.items.ItemCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 47 with 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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ItemCollection(org.folio.inventory.domain.items.ItemCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 48 with 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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) ItemCollection(org.folio.inventory.domain.items.ItemCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 49 with 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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ItemCollection(org.folio.inventory.domain.items.ItemCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 50 with 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();
    });
}
Also used : HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) JsonObject(io.vertx.core.json.JsonObject) Event(org.folio.rest.jaxrs.model.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Aggregations

Failure (org.folio.inventory.common.domain.Failure)50 Test (org.junit.Test)44 CompletableFuture (java.util.concurrent.CompletableFuture)26 HashMap (java.util.HashMap)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 DataImportEventPayload (org.folio.DataImportEventPayload)17 JsonObject (io.vertx.core.json.JsonObject)16 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)10 Record (org.folio.rest.jaxrs.model.Record)10 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)9 Async (io.vertx.ext.unit.Async)8 Consumer (java.util.function.Consumer)7 HoldingsRecord (org.folio.HoldingsRecord)7 AuthorityRecordCollection (org.folio.inventory.domain.AuthorityRecordCollection)7 InstanceCollection (org.folio.inventory.domain.instances.InstanceCollection)7 ItemCollection (org.folio.inventory.domain.items.ItemCollection)6 EventHandler (org.folio.processing.events.services.handler.EventHandler)6 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)4 Instance (org.folio.inventory.domain.instances.Instance)4 Reader (org.folio.processing.mapping.mapper.reader.Reader)4