use of org.folio.rest.jaxrs.model.JobExecution.Status.COMMITTED in project mod-source-record-manager by folio-org.
the class RecordProcessedEventHandlingServiceImplTest method shouldMarkJobExecutionAsCommittedOnHandleEventWhenAllRecordsSuccessfullyProcessed.
@Test
public void shouldMarkJobExecutionAsCommittedOnHandleEventWhenAllRecordsSuccessfullyProcessed(TestContext context) {
// given
Async async = context.async();
RawRecordsDto rawRecordsDto = new RawRecordsDto().withInitialRecords(Collections.singletonList(new InitialRecord().withRecord(CORRECT_RAW_RECORD))).withRecordsMetadata(new RecordsMetadata().withLast(false).withCounter(1).withTotal(1).withContentType(RecordsMetadata.ContentType.MARC_RAW));
HashMap<String, String> payloadContext = new HashMap<>();
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_COMPLETED.value()).withContext(payloadContext);
Future<Boolean> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionService.setJobProfileToJobExecution(initJobExecutionsRsDto.getParentJobExecutionId(), jobProfileInfo, params)).compose(jobExecution -> {
dataImportEventPayload.setJobExecutionId(jobExecution.getId());
return chunkProcessingService.processChunk(rawRecordsDto, jobExecution.getId(), params);
});
// when
Future<Optional<JobExecution>> jobFuture = future.compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(dataImportEventPayload), params)).compose(ar -> jobExecutionService.getJobExecutionById(dataImportEventPayload.getJobExecutionId(), TENANT_ID));
// then
jobFuture.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertTrue(ar.result().isPresent());
JobExecution jobExecution = ar.result().get();
context.assertEquals(COMMITTED, jobExecution.getStatus());
context.assertEquals(RUNNING_COMPLETE, jobExecution.getUiStatus());
context.assertEquals(rawRecordsDto.getRecordsMetadata().getTotal(), jobExecution.getProgress().getTotal());
context.assertNotNull(jobExecution.getStartedDate());
context.assertNotNull(jobExecution.getCompletedDate());
async.complete();
});
}
Aggregations