use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionProgressServiceImplTest method shouldReturnFailedFutureWhenJobExecutionDoesNotExist.
@Test
public void shouldReturnFailedFutureWhenJobExecutionDoesNotExist(TestContext context) {
Async async = context.async();
int totalRecords = 62;
String jobExecId = UUID.randomUUID().toString();
Future<JobExecutionProgress> future = jobExecutionProgressService.initializeJobExecutionProgress(jobExecId, totalRecords, TENANT_ID);
future.onComplete(ar -> {
context.assertTrue(ar.failed());
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionProgressDaoImpl method updateByJobExecutionId.
@Override
public Future<JobExecutionProgress> updateByJobExecutionId(String jobExecutionId, UnaryOperator<JobExecutionProgress> progressMutator, String tenantId) {
String rollbackMessage = String.format(ROLLBACK_MESSAGE, jobExecutionId);
Promise<JobExecutionProgress> promise = Promise.promise();
Promise<SQLConnection> tx = Promise.promise();
PostgresClient pgClient = pgClientFactory.createInstance(tenantId);
getSelectResult(tx, pgClient, jobExecutionId, tenantId).map(progressResults -> {
Optional<JobExecutionProgress> optionalJobExecutionProgress = mapResultSetToOptionalJobExecutionProgress(progressResults);
if (optionalJobExecutionProgress.isEmpty()) {
throw new NotFoundException(rollbackMessage);
}
return progressMutator.apply(optionalJobExecutionProgress.get());
}).compose(mutatedProgress -> updateProgressByJobExecutionId(tx.future(), mutatedProgress, tenantId)).onComplete(updateAr -> {
if (updateAr.succeeded()) {
pgClient.endTx(tx.future(), endTx -> promise.complete(updateAr.result()));
} else {
LOGGER.error(rollbackMessage, updateAr.cause());
pgClient.rollbackTx(tx.future(), r -> promise.fail(updateAr.cause()));
}
});
return promise.future();
}
use of org.folio.rest.jaxrs.model.JobExecutionProgress 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.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionProgressServiceImplTest method shouldInitProgress.
@Test
public void shouldInitProgress(TestContext context) {
Async async = context.async();
int expectedTotalRecords = 62;
Future<JobExecutionProgress> future = jobExecutionService.initializeJobExecutions(initJobExecutionsRqDto, params).compose(initJobExecutionsRsDto -> jobExecutionProgressService.initializeJobExecutionProgress(initJobExecutionsRsDto.getParentJobExecutionId(), expectedTotalRecords, TENANT_ID)).compose(progress -> jobExecutionProgressService.getByJobExecutionId(progress.getJobExecutionId(), TENANT_ID));
future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
JobExecutionProgress progress = ar.result();
context.assertEquals(expectedTotalRecords, progress.getTotal());
jobMonitoringService.getByJobExecutionId(progress.getJobExecutionId(), params.getTenantId()).onSuccess(optionalJobMonitoring -> {
context.assertTrue(optionalJobMonitoring.isPresent());
JobMonitoring jobMonitoring = optionalJobMonitoring.get();
context.assertNotNull(jobMonitoring.getId());
context.assertEquals(progress.getJobExecutionId(), jobMonitoring.getJobExecutionId());
context.assertNotNull(jobMonitoring.getLastEventTimestamp());
context.assertFalse(jobMonitoring.getNotificationSent());
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.JobExecutionProgress in project mod-source-record-manager by folio-org.
the class JobExecutionProgressServiceImplTest method shouldReturnFailedFutureOnUpdateWhenProgressDoesNotExist.
@Test
public void shouldReturnFailedFutureOnUpdateWhenProgressDoesNotExist(TestContext context) {
Async async = context.async();
int succeededRecords = 7;
String jobExecutionId = UUID.randomUUID().toString();
Future<JobExecutionProgress> future = jobExecutionProgressService.updateJobExecutionProgress(jobExecutionId, progressToUpdate -> progressToUpdate.withCurrentlySucceeded(succeededRecords), TENANT_ID);
future.onComplete(ar -> {
context.assertTrue(ar.failed());
async.complete();
});
}
Aggregations