Search in sources :

Example 1 with IngestJob

use of org.folio.inventory.resources.ingest.IngestJob in project mod-inventory by folio-org.

the class InMemoryIngestJobCollectionExamples method jobStateCanBeUpdated.

@Test
public void jobStateCanBeUpdated() throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<IngestJob> addFuture = new CompletableFuture<>();
    collection.add(new IngestJob(IngestJobState.REQUESTED), succeed(addFuture), fail(addFuture));
    IngestJob added = getOnCompletion(addFuture);
    IngestJob completed = added.complete();
    CompletableFuture<Void> updateFuture = new CompletableFuture<>();
    collection.update(completed, succeed(updateFuture), fail(updateFuture));
    waitForCompletion(updateFuture);
    CompletableFuture<IngestJob> findFuture = new CompletableFuture<>();
    collection.findById(added.id, succeed(findFuture), fail(findFuture));
    IngestJob found = getOnCompletion(findFuture);
    assertThat(found.state, is(IngestJobState.COMPLETED));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IngestJob(org.folio.inventory.resources.ingest.IngestJob) Test(org.junit.Test)

Example 2 with IngestJob

use of org.folio.inventory.resources.ingest.IngestJob in project mod-inventory by folio-org.

the class InMemoryIngestJobCollectionExamples method jobsCanBeFoundById.

@Test
public void jobsCanBeFoundById() throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<IngestJob> addFuture = new CompletableFuture<>();
    collection.add(new IngestJob(IngestJobState.REQUESTED), succeed(addFuture), fail(addFuture));
    IngestJob added = getOnCompletion(addFuture);
    CompletableFuture<IngestJob> findFuture = new CompletableFuture<>();
    collection.findById(added.id, succeed(findFuture), fail(findFuture));
    IngestJob found = getOnCompletion(findFuture);
    assertThat(found.id, is(added.id));
    assertThat(found.state, is(IngestJobState.REQUESTED));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IngestJob(org.folio.inventory.resources.ingest.IngestJob) Test(org.junit.Test)

Example 3 with IngestJob

use of org.folio.inventory.resources.ingest.IngestJob in project mod-inventory by folio-org.

the class IngestMessageProcessor method markIngestCompleted.

private void markIngestCompleted(Message<JsonObject> message) {
    final MessagingContext context = new MessagingContext(message.headers());
    storage.getIngestJobCollection(context).update(new IngestJob(context.getJobId(), IngestJobState.COMPLETED), v -> log.info(String.format("Ingest job %s completed", context.getJobId())), failure -> log.error(String.format("Updating ingest job failed: %s", failure.getReason())));
}
Also used : IngestJob(org.folio.inventory.resources.ingest.IngestJob) MessagingContext(org.folio.inventory.common.MessagingContext)

Example 4 with IngestJob

use of org.folio.inventory.resources.ingest.IngestJob in project mod-inventory by folio-org.

the class InMemoryIngestJobCollectionExamples method jobsCanBeAdded.

@Test
public void jobsCanBeAdded() throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<IngestJob> addFuture = new CompletableFuture<>();
    collection.add(new IngestJob(IngestJobState.REQUESTED), succeed(addFuture), fail(addFuture));
    waitForCompletion(addFuture);
    CompletableFuture<MultipleRecords<IngestJob>> findFuture = new CompletableFuture<>();
    collection.findAll(PagingParameters.defaults(), succeed(findFuture), fail(findFuture));
    MultipleRecords<IngestJob> allJobsWrapped = getOnCompletion(findFuture);
    List<IngestJob> allJobs = allJobsWrapped.records;
    assertThat(allJobs.size(), is(1));
    allJobs.stream().forEach(job -> assertThat(job.id, is(notNullValue())));
    allJobs.stream().forEach(job -> assertThat(job.state, is(IngestJobState.REQUESTED)));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IngestJob(org.folio.inventory.resources.ingest.IngestJob) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 5 with IngestJob

use of org.folio.inventory.resources.ingest.IngestJob in project mod-inventory by folio-org.

the class InMemoryIngestJobCollectionExamples method singleJobWithSameIdFollowingUpdate.

@Test
public void singleJobWithSameIdFollowingUpdate() throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<IngestJob> addFuture = new CompletableFuture<>();
    collection.add(new IngestJob(IngestJobState.REQUESTED), succeed(addFuture), fail(addFuture));
    IngestJob added = getOnCompletion(addFuture);
    IngestJob completed = added.complete();
    CompletableFuture<Void> updateFuture = new CompletableFuture<>();
    collection.update(completed, succeed(updateFuture), fail(updateFuture));
    waitForCompletion(updateFuture);
    CompletableFuture<MultipleRecords<IngestJob>> findAllFuture = new CompletableFuture<>();
    collection.findAll(PagingParameters.defaults(), succeed(findAllFuture), fail(findAllFuture));
    MultipleRecords<IngestJob> allJobsWrapped = getOnCompletion(findAllFuture);
    List<IngestJob> allJobs = allJobsWrapped.records;
    assertThat(allJobs.size(), is(1));
    assertThat(allJobs.stream().findFirst().get().id, is(added.id));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IngestJob(org.folio.inventory.resources.ingest.IngestJob) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Aggregations

IngestJob (org.folio.inventory.resources.ingest.IngestJob)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 Test (org.junit.Test)4 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)2 MessagingContext (org.folio.inventory.common.MessagingContext)1