use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class RecordProcessedEventHandlingServiceImplTest method shouldIncrementCurrentlyFailedAndUpdateProgressOnHandleEvent.
@Test
public void shouldIncrementCurrentlyFailedAndUpdateProgressOnHandleEvent(TestContext context) {
// given
Async async = context.async();
HashMap<String, String> payloadContext = new HashMap<>();
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DataImportEventTypes.DI_ERROR.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<JobExecutionProgress> jobFuture = future.compose(ar -> recordProcessedEventHandlingService.handle(Json.encode(dataImportEventPayload), params)).compose(ar -> jobExecutionProgressService.getByJobExecutionId(dataImportEventPayload.getJobExecutionId(), TENANT_ID));
// then
jobFuture.onComplete(ar -> {
context.assertTrue(ar.succeeded());
JobExecutionProgress updatedProgress = ar.result();
context.assertEquals(1, updatedProgress.getCurrentlyFailed());
context.assertEquals(0, updatedProgress.getCurrentlySucceeded());
context.assertEquals(rawRecordsDto.getRecordsMetadata().getTotal(), updatedProgress.getTotal());
Async async2 = context.async();
jobFuture.compose(jobAr -> jobExecutionService.getJobExecutionById(dataImportEventPayload.getJobExecutionId(), TENANT_ID)).onComplete(jobAr -> {
context.assertTrue(jobAr.succeeded());
context.assertTrue(jobAr.result().isPresent());
JobExecution jobExecution = jobAr.result().get();
context.assertEquals(PARSING_IN_PROGRESS, jobExecution.getStatus());
async2.complete();
});
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JobExecution 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();
});
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class DataImportInitConsumerVerticleTest method assertProgressAndMonitoringAndJobExecutionStatus.
private void assertProgressAndMonitoringAndJobExecutionStatus(JobExecution.Status statusToCheck, Async async) {
jobExecutionProgressService.getByJobExecutionId(jobExecutionId, TENANT_ID).onSuccess(progress -> {
assertEquals(jobExecutionId, progress.getJobExecutionId());
assertEquals(TOTAL_RECORDS, progress.getTotal());
jobExecutionService.getJobExecutionById(jobExecutionId, TENANT_ID).onSuccess(jobExecutionOptional -> {
JobExecution jobExecution = jobExecutionOptional.get();
assertEquals(statusToCheck, jobExecution.getStatus());
jobMonitoringService.getByJobExecutionId(jobExecution.getId(), TENANT_ID).onSuccess(jobMonitoringOptional -> {
JobMonitoring jobMonitoring = jobMonitoringOptional.get();
assertEquals(jobExecutionId, jobMonitoring.getJobExecutionId());
async.complete();
});
});
});
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldProcessChunkIfRequestForMappingParametersFails.
@Test
public void shouldProcessChunkIfRequestForMappingParametersFails(TestContext testContext) {
// given
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
// Do mock services to return failed response
WireMock.stubFor(get(IDENTIFIER_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(INSTANCE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(CLASSIFICATION_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(ELECTRONIC_ACCESS_URL).willReturn(serverError()));
WireMock.stubFor(get(INSTANCE_FORMATS_URL).willReturn(serverError()));
WireMock.stubFor(get(CONTRIBUTOR_NAME_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(CONTRIBUTOR_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(INSTANCE_NOTE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(INSTANCE_ALTERNATIVE_TITLE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(MODE_OF_ISSUANCE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(INSTANCE_STATUSES_URL).willReturn(serverError()));
WireMock.stubFor(get(NATURE_OF_CONTENT_TERMS_URL).willReturn(serverError()));
WireMock.stubFor(get(INSTANCE_RELATIONSHIP_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(HOLDINGS_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(HOLDINGS_NOTE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(ILL_POLICIES_URL).willReturn(serverError()));
WireMock.stubFor(get(CALL_NUMBER_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(STATISTICAL_CODES_URL).willReturn(serverError()));
WireMock.stubFor(get(STATISTICAL_CODE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(LOCATIONS_URL).willReturn(serverError()));
WireMock.stubFor(get(MATERIAL_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(ITEM_DAMAGED_STATUSES_URL).willReturn(serverError()));
WireMock.stubFor(get(LOAN_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(ITEM_NOTE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(AUTHORITY_NOTE_TYPES_URL).willReturn(serverError()));
WireMock.stubFor(get(FIELD_PROTECTION_SETTINGS_URL).willReturn(serverError()));
WireMock.stubFor(get(TENANT_CONFIGURATIONS_SETTINGS_URL).willReturn(serverError()));
Async async = testContext.async();
RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
async.complete();
// when
async = testContext.async();
RestAssured.given().spec(spec).body(rawRecordsDto.withId(UUID.randomUUID().toString())).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
// then
async = testContext.async();
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(JobExecution.Status.PARSING_IN_PROGRESS.name())).body("runBy.firstName", is("DIKU")).body("progress.total", is(100)).body("startedDate", notNullValue(Date.class)).log().all();
async.complete();
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldUpdateSingleParentOnPut.
@Test
public void shouldUpdateSingleParentOnPut() {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution singleParent = createdJobExecutions.get(0);
assertThat(singleParent.getSubordinationType(), is(JobExecution.SubordinationType.PARENT_SINGLE));
singleParent.setJobProfileInfo(new JobProfileInfo().withId(DEFAULT_JOB_PROFILE_ID).withName("Marc jobs profile"));
RestAssured.given().spec(spec).body(JsonObject.mapFrom(singleParent).toString()).when().put(JOB_EXECUTION_PATH + singleParent.getId()).then().statusCode(HttpStatus.SC_OK).body("id", is(singleParent.getId())).body("jobProfileInfo.name", is(singleParent.getJobProfileInfo().getName()));
}
Aggregations