Search in sources :

Example 1 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class TestTypeScheduleRunner method deleteSchedule.

private <T extends SingleStageTestProcessConfiguration> void deleteSchedule(ConfigurableTestSchedule<T> schedule) {
    ScheduleEntity scheduleEntity = new ScheduleEntity();
    scheduleEntity.setPipelineName(schedule.pipelineName());
    scheduleService.delete(scheduleEntity);
    System.out.println("deleted schedule for pipeline: " + schedule.pipelineName());
}
Also used : ScheduleEntity(pipelite.entity.ScheduleEntity)

Example 2 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleRunnerTest method assertScheduleEntity.

private void assertScheduleEntity(List<ScheduleEntity> scheduleEntities, TestSchedule f) {
    String pipelineName = f.pipelineName();
    assertThat(scheduleEntities.stream().filter(e -> e.getPipelineName().equals(f.pipelineName())).count()).isEqualTo(1);
    ScheduleEntity scheduleEntity = scheduleEntities.stream().filter(e -> e.getPipelineName().equals(f.pipelineName())).findFirst().get();
    assertThat(scheduleEntity.getServiceName()).isEqualTo(serviceConfiguration.getName());
    assertThat(scheduleEntity.getPipelineName()).isEqualTo(pipelineName);
    assertThat(scheduleEntity.getProcessId()).isNotNull();
    assertThat(scheduleEntity.getExecutionCount()).isEqualTo(f.processCnt);
    assertThat(scheduleEntity.getStartTime()).isNotNull();
    assertThat(scheduleEntity.getEndTime()).isNotNull();
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Getter(lombok.Getter) ScheduleEntity(pipelite.entity.ScheduleEntity) PipeliteTestConfigWithManager(pipelite.PipeliteTestConfigWithManager) StageEntity(pipelite.entity.StageEntity) ProcessService(pipelite.service.ProcessService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ProcessEntity(pipelite.entity.ProcessEntity) RunnerService(pipelite.service.RunnerService) ScheduleService(pipelite.service.ScheduleService) ProcessState(pipelite.process.ProcessState) TestConfiguration(org.springframework.boot.test.context.TestConfiguration) PipelineMetrics(pipelite.metrics.PipelineMetrics) StageService(pipelite.service.StageService) ProcessBuilder(pipelite.process.builder.ProcessBuilder) Duration(java.time.Duration) ServiceConfiguration(pipelite.configuration.ServiceConfiguration) StageLogEntity(pipelite.entity.StageLogEntity) StageState(pipelite.stage.StageState) ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) PipeliteMetrics(pipelite.metrics.PipeliteMetrics) StageExecutorResult(pipelite.stage.executor.StageExecutorResult) Profile(org.springframework.context.annotation.Profile) Test(org.junit.jupiter.api.Test) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessRunnerPoolManager(pipelite.manager.ProcessRunnerPoolManager) TimeSeriesMetrics(pipelite.metrics.TimeSeriesMetrics) ConfigurableTestSchedule(pipelite.tester.pipeline.ConfigurableTestSchedule) Bean(org.springframework.context.annotation.Bean) ScheduleEntity(pipelite.entity.ScheduleEntity)

Example 3 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleRunnerResumeTest method testResumeSchedules.

@Test
public // @Timeout(value = 10, unit = TimeUnit.SECONDS)
void testResumeSchedules() {
    int maxExecution1 = 1;
    int maxExecution2 = 1;
    // Create two schedules with start time and process id to allow processes to resume.
    ZonedDateTime startTime1 = ZonedDateTime.now().minusHours(2).truncatedTo(ChronoUnit.SECONDS);
    ZonedDateTime startTime2 = ZonedDateTime.now().minusHours(2).truncatedTo(ChronoUnit.SECONDS);
    ZonedDateTime nextTime1 = ZonedDateTime.now().minusMinutes(1).truncatedTo(ChronoUnit.SECONDS);
    ZonedDateTime nextTime2 = ZonedDateTime.now().minusHours(1).truncatedTo(ChronoUnit.SECONDS);
    ScheduleEntity scheduleEntity1 = pipeliteServices.schedule().getSavedSchedule(resume1.pipelineName()).get();
    ScheduleEntity scheduleEntity2 = pipeliteServices.schedule().getSavedSchedule(resume2.pipelineName()).get();
    scheduleEntity1.setStartTime(startTime1);
    scheduleEntity2.setStartTime(startTime2);
    scheduleEntity1.setNextTime(nextTime1);
    scheduleEntity2.setNextTime(nextTime2);
    String processId1 = "1";
    String processId2 = "2";
    scheduleEntity1.setProcessId(processId1);
    scheduleEntity2.setProcessId(processId2);
    pipeliteServices.schedule().saveSchedule(scheduleEntity1);
    pipeliteServices.schedule().saveSchedule(scheduleEntity2);
    ProcessEntity processEntity1 = ProcessEntity.createExecution(resume1.pipelineName(), processId1, 5);
    ProcessEntity processEntity2 = ProcessEntity.createExecution(resume2.pipelineName(), processId2, 5);
    pipeliteServices.process().saveProcess(processEntity1);
    pipeliteServices.process().saveProcess(processEntity2);
    ScheduleRunner scheduleRunner = spy(ScheduleRunnerFactory.create(pipeliteConfiguration, pipeliteServices, pipeliteMetrics, pipeliteServices.registeredPipeline().getRegisteredPipelines(Schedule.class)));
    scheduleRunner.setMaximumExecutions(resume1.pipelineName(), maxExecution1);
    scheduleRunner.setMaximumExecutions(resume2.pipelineName(), maxExecution2);
    // Resume the two processes, check that they are immediately executed
    // and that they are scheduled for a later execution.
    scheduleRunner.startUp();
    while (!scheduleRunner.isIdle()) {
        scheduleRunner.runOneIteration();
        Time.wait(Duration.ofMillis(100));
    }
    scheduleEntity1 = pipeliteServices.schedule().getSavedSchedule(resume1.pipelineName()).get();
    scheduleEntity2 = pipeliteServices.schedule().getSavedSchedule(resume2.pipelineName()).get();
    assertThat(scheduleEntity1.getStartTime()).isEqualTo(startTime1);
    assertThat(scheduleEntity2.getStartTime()).isEqualTo(startTime2);
    assertThat(scheduleEntity1.getEndTime()).isAfter(startTime1);
    assertThat(scheduleEntity2.getEndTime()).isAfter(startTime2);
    assertThat(scheduleEntity1.getExecutionCount()).isOne();
    assertThat(scheduleEntity2.getExecutionCount()).isOne();
    assertThat(scheduleEntity1.getProcessId()).isEqualTo(processId1);
    assertThat(scheduleEntity2.getProcessId()).isEqualTo(processId2);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class RetryServiceTest method clean.

@AfterEach
public void clean() {
    ScheduleEntity scheduleEntity = new ScheduleEntity();
    scheduleEntity.setPipelineName(SCHEDULE_NAME);
    scheduleService.delete(scheduleEntity);
}
Also used : ScheduleEntity(pipelite.entity.ScheduleEntity) AfterEach(org.junit.jupiter.api.AfterEach)

Example 5 with ScheduleEntity

use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.

the class ScheduleServiceTest method isRetryScheduleWithNewExecutionWithinRetryMargin.

@Test
public void isRetryScheduleWithNewExecutionWithinRetryMargin() {
    String serviceName = PipeliteIdCreator.serviceName();
    String pipelineName = PipeliteIdCreator.pipelineName();
    String processId = PipeliteIdCreator.processId();
    String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
    ScheduleEntity scheduleEntity = scheduleService.createSchedule(serviceName, pipelineName, cron);
    assertThat(scheduleEntity.isFailed()).isFalse();
    scheduleEntity = scheduleService.startExecution(pipelineName, processId);
    assertThat(scheduleEntity.isFailed()).isFalse();
    ProcessEntity processEntity = ProcessEntity.createExecution(pipelineName, processId, 1);
    processEntity.endExecution(ProcessState.FAILED);
    scheduleEntity = scheduleService.endExecution(processEntity, ZonedDateTime.now());
    assertThat(scheduleEntity.isFailed()).isTrue();
    PipeliteProcessRetryException ex = assertThrows(PipeliteProcessRetryException.class, () -> scheduleService.isRetrySchedule(pipelineName, processId));
    assertThat(ex.getMessage()).contains("the next process for the schedule will be executed in less than");
}
Also used : PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) ProcessEntity(pipelite.entity.ProcessEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ScheduleEntity (pipelite.entity.ScheduleEntity)22 ProcessEntity (pipelite.entity.ProcessEntity)9 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 ZonedDateTime (java.time.ZonedDateTime)5 Timed (io.micrometer.core.annotation.Timed)4 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)4 Schedule (pipelite.Schedule)2 StageEntity (pipelite.entity.StageEntity)2 PipeliteException (pipelite.exception.PipeliteException)2 Process (pipelite.process.Process)2 Duration (java.time.Duration)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PostConstruct (javax.annotation.PostConstruct)1 Getter (lombok.Getter)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 TestConfiguration (org.springframework.boot.test.context.TestConfiguration)1