use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionDaoImplTest method prepareDataForDeletion.
private Future<JobExecution> prepareDataForDeletion(Instant completedDate) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), Matchers.is(1));
JobExecution jobExec = createdJobExecutions.get(0);
jobExec.withCompletedDate(Date.from(completedDate));
JobExecutionProgress jobExecutionProgress = new JobExecutionProgress().withJobExecutionId(jobExec.getId()).withTotal(1).withCurrentlySucceeded(1).withCurrentlyFailed(0);
JobMonitoring jobMonitoring = new JobMonitoring().withId(UUID.randomUUID().toString()).withJobExecutionId(jobExec.getId()).withNotificationSent(true).withLastEventTimestamp(new Date());
JournalRecord journalRecord = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(COMPLETED);
JobExecutionSourceChunk jobExecutionSourceChunk = new JobExecutionSourceChunk().withId("67dfac11-1caf-4470-9ad1-d533f6360bdd").withJobExecutionId(jobExec.getId()).withLast(false).withState(JobExecutionSourceChunk.State.COMPLETED).withChunkSize(10).withProcessedAmount(42);
return jobExecutionDao.updateJobExecution(jobExec, TENANT_ID).compose(jobExecution -> {
Future<RowSet<Row>> saveProgressFuture = jobExecutionProgressDao.save(jobExecutionProgress, TENANT_ID);
Future<String> saveMonitoringFuture = jobMonitoringDao.save(jobMonitoring, TENANT_ID);
Future<String> saveJournalFuture = journalRecordDao.save(journalRecord, TENANT_ID);
Future<String> saveSourceChunkFuture = jobExecutionSourceChunkDao.save(jobExecutionSourceChunk, TENANT_ID);
return CompositeFuture.all(saveProgressFuture, saveMonitoringFuture, saveJournalFuture, saveSourceChunkFuture).compose(ar -> Future.succeededFuture(jobExecution));
});
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionDaoImplTest method shouldNotDeleteIfCompletedDateNotExceeds.
@Test
public void shouldNotDeleteIfCompletedDateNotExceeds(TestContext context) {
/*
In this test we setup job execution that finishes 1 day ago, after this job execution has been soft deleted.
Periodic job should not hard delete it, because 1 day does not meet condition: older than 2 days.
*/
Async async = context.async();
Instant minusOneDay = LocalDateTime.now().minus(1, ChronoUnit.DAYS).atOffset(ZoneOffset.UTC).toInstant();
Future<JobExecution> preparationFuture = prepareDataForDeletion(minusOneDay);
preparationFuture.onComplete(ar -> {
JobExecution jobExecution = ar.result();
List<String> jobExecutionIds = List.of(jobExecution.getId());
jobExecutionDao.softDeleteJobExecutionsByIds(jobExecutionIds, TENANT_ID).onSuccess(reply -> {
JobExecutionDetail jobExecutionDetail = reply.getJobExecutionDetails().get(0);
assertEquals(jobExecutionDetail.getJobExecutionId(), jobExecution.getId());
assertTrue(jobExecutionDetail.getIsDeleted());
jobExecutionDao.hardDeleteJobExecutions(2, TENANT_ID).onSuccess(resp -> checkDataExistenceAfterHardDeleting(1, jobExecutionIds, async));
});
});
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JobExecutionDaoImplTest method shouldNotDeleteIfJobExecutionIdsNotMatch.
@Test
public void shouldNotDeleteIfJobExecutionIdsNotMatch(TestContext context) {
/*
In this test we setup job execution that finishes 3 days ago, after this ANOTHER job execution has been soft deleted.
Periodic job should not hard delete our initial job execution, because it remains not soft deleted.
*/
Async async = context.async();
Instant minusThreeDays = LocalDateTime.now().minus(3, ChronoUnit.DAYS).atOffset(ZoneOffset.UTC).toInstant();
Future<JobExecution> preparationFuture = prepareDataForDeletion(minusThreeDays);
preparationFuture.onComplete(ar -> {
JobExecution jobExecution = ar.result();
List<String> differentJobExecutionIds = List.of(UUID.randomUUID().toString());
jobExecutionDao.softDeleteJobExecutionsByIds(differentJobExecutionIds, TENANT_ID).onSuccess(reply -> jobExecutionDao.hardDeleteJobExecutions(2, TENANT_ID).onSuccess(resp -> checkDataExistenceAfterHardDeleting(1, List.of(jobExecution.getId()), async)));
});
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JournalRecordDaoTest method shouldReturnSortedJournalRecordListByActionType.
@Test
public void shouldReturnSortedJournalRecordListByActionType(TestContext testContext) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
Assert.assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
JournalRecord journalRecord1 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(COMPLETED);
JournalRecord journalRecord2 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(MODIFY).withActionDate(new Date()).withActionStatus(COMPLETED);
JournalRecord journalRecord3 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(DELETE).withActionDate(new Date()).withActionStatus(COMPLETED);
Async async = testContext.async();
Future<List<JournalRecord>> getFuture = journalRecordDao.save(journalRecord1, TENANT_ID).compose(ar -> journalRecordDao.save(journalRecord2, TENANT_ID)).compose(ar -> journalRecordDao.save(journalRecord3, TENANT_ID)).compose(ar -> journalRecordDao.getByJobExecutionId(jobExec.getId(), "action_type", "asc", TENANT_ID));
getFuture.onComplete(ar -> {
testContext.verify(v -> {
Assert.assertTrue(ar.succeeded());
List<JournalRecord> journalRecords = ar.result();
Assert.assertEquals(3, journalRecords.size());
Assert.assertThat(journalRecords.get(0).getActionType(), lessThan(journalRecords.get(1).getActionType()));
Assert.assertThat(journalRecords.get(1).getActionType(), lessThan(journalRecords.get(2).getActionType()));
});
async.complete();
});
}
use of org.folio.rest.jaxrs.model.JobExecution in project mod-source-record-manager by folio-org.
the class JournalRecordDaoTest method shouldReturnSortedJournalRecordListByErrorMessage.
@Test
public void shouldReturnSortedJournalRecordListByErrorMessage(TestContext testContext) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
Assert.assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
JournalRecord journalRecord1 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.MARC_BIBLIOGRAPHIC).withEntityId(UUID.randomUUID().toString()).withActionType(CREATE).withActionDate(new Date()).withActionStatus(ERROR).withError("Record creation error");
JournalRecord journalRecord2 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(MODIFY).withActionDate(new Date()).withActionStatus(ERROR).withError("Instance was not updated");
JournalRecord journalRecord3 = new JournalRecord().withJobExecutionId(jobExec.getId()).withSourceRecordOrder(0).withSourceId(UUID.randomUUID().toString()).withEntityType(JournalRecord.EntityType.INSTANCE).withEntityId(UUID.randomUUID().toString()).withActionType(DELETE).withActionDate(new Date()).withActionStatus(ERROR).withError("No action taken");
Async async = testContext.async();
Future<List<JournalRecord>> getFuture = journalRecordDao.save(journalRecord1, TENANT_ID).compose(ar -> journalRecordDao.save(journalRecord2, TENANT_ID)).compose(ar -> journalRecordDao.save(journalRecord3, TENANT_ID)).compose(ar -> journalRecordDao.getByJobExecutionId(jobExec.getId(), "error", "desc", TENANT_ID));
getFuture.onComplete(ar -> {
testContext.verify(v -> {
Assert.assertTrue(ar.succeeded());
List<JournalRecord> journalRecords = ar.result();
Assert.assertEquals(3, journalRecords.size());
Assert.assertThat(journalRecords.get(0).getError(), greaterThan(journalRecords.get(1).getError()));
Assert.assertThat(journalRecords.get(1).getError(), greaterThan(journalRecords.get(2).getError()));
});
async.complete();
});
}
Aggregations