Search in sources :

Example 6 with JobExecution

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));
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) RowSet(io.vertx.sqlclient.RowSet) JobExecutionSourceChunk(org.folio.rest.jaxrs.model.JobExecutionSourceChunk) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) Date(java.util.Date) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord)

Example 7 with 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));
        });
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) Async(io.vertx.ext.unit.Async) Instant(java.time.Instant) JobExecutionDetail(org.folio.rest.jaxrs.model.JobExecutionDetail) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 8 with JobExecution

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)));
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) Arrays(java.util.Arrays) Date(java.util.Date) PostgresClient.convertToPsqlStandard(org.folio.rest.persist.PostgresClient.convertToPsqlStandard) Random(java.util.Random) CHILD(org.folio.rest.jaxrs.model.JobExecution.SubordinationType.CHILD) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) ZoneOffset(java.time.ZoneOffset) JobExecutionDto(org.folio.rest.jaxrs.model.JobExecutionDto) JobMonitoring(org.folio.rest.jaxrs.model.JobMonitoring) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) JobExecutionSourceChunk(org.folio.rest.jaxrs.model.JobExecutionSourceChunk) UUID(java.util.UUID) Instant(java.time.Instant) Future(io.vertx.core.Future) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) String.format(java.lang.String.format) JobExecutionService(org.folio.services.JobExecutionService) List(java.util.List) JobExecutionDtoCollection(org.folio.rest.jaxrs.model.JobExecutionDtoCollection) Strings(org.apache.logging.log4j.util.Strings) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Async(io.vertx.ext.unit.Async) OKAPI_TENANT_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) CompositeFuture(io.vertx.core.CompositeFuture) RowSet(io.vertx.sqlclient.RowSet) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) JobExecutionServiceImpl(org.folio.services.JobExecutionServiceImpl) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) JobExecutionProgress(org.folio.rest.jaxrs.model.JobExecutionProgress) Rule(org.junit.Rule) ChronoUnit(java.time.temporal.ChronoUnit) File(org.folio.rest.jaxrs.model.File) Row(io.vertx.sqlclient.Row) Log4j2(lombok.extern.log4j.Log4j2) JobExecutionDetail(org.folio.rest.jaxrs.model.JobExecutionDetail) OKAPI_TOKEN_HEADER(org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Assert.assertEquals(org.junit.Assert.assertEquals) Async(io.vertx.ext.unit.Async) Instant(java.time.Instant) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 9 with JobExecution

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();
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Date(java.util.Date) RunWith(org.junit.runner.RunWith) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) DELETE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.DELETE) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) Future(io.vertx.core.Future) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Async(io.vertx.ext.unit.Async) List(java.util.List) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Example 10 with JobExecution

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();
    });
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Date(java.util.Date) RunWith(org.junit.runner.RunWith) PostgresClientFactory(org.folio.dao.util.PostgresClientFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) JobExecution(org.folio.rest.jaxrs.model.JobExecution) Spy(org.mockito.Spy) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ERROR(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR) MODIFY(org.folio.rest.jaxrs.model.JournalRecord.ActionType.MODIFY) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) DELETE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.DELETE) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) Future(io.vertx.core.Future) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Assert(org.junit.Assert) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) Async(io.vertx.ext.unit.Async) List(java.util.List) InitJobExecutionsRsDto(org.folio.rest.jaxrs.model.InitJobExecutionsRsDto) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date) Test(org.junit.Test) AbstractRestTest(org.folio.rest.impl.AbstractRestTest)

Aggregations

JobExecution (org.folio.rest.jaxrs.model.JobExecution)128 Test (org.junit.Test)111 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)99 InitJobExecutionsRsDto (org.folio.rest.jaxrs.model.InitJobExecutionsRsDto)73 Async (io.vertx.ext.unit.Async)68 Future (io.vertx.core.Future)55 JobProfileInfo (org.folio.rest.jaxrs.model.JobProfileInfo)55 List (java.util.List)54 Date (java.util.Date)53 UUID (java.util.UUID)52 Before (org.junit.Before)48 PostgresClientFactory (org.folio.dao.util.PostgresClientFactory)47 RunWith (org.junit.runner.RunWith)47 InjectMocks (org.mockito.InjectMocks)47 TestContext (io.vertx.ext.unit.TestContext)46 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)46 MockitoAnnotations (org.mockito.MockitoAnnotations)46 Spy (org.mockito.Spy)46 JournalRecordDaoImpl (org.folio.dao.JournalRecordDaoImpl)41 JournalRecord (org.folio.rest.jaxrs.model.JournalRecord)38