use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.
the class RetryServiceTest method assertSetupSchedule.
private void assertSetupSchedule(String serviceName, String pipelineName, String processId, String cron, ZonedDateTime nextTime) {
// Failed
ScheduleEntity s = scheduleService.getSavedSchedule(pipelineName).get();
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(CronUtils.describe(cron));
assertThat(s.getExecutionCount()).isEqualTo(1);
assertThat(s.getNextTime()).isEqualTo(nextTime.truncatedTo(ChronoUnit.SECONDS));
assertThat(s.getStartTime()).isNotNull();
assertThat(s.getEndTime()).isNotNull();
assertThat(s.getLastCompleted()).isNull();
assertThat(s.getLastFailed()).isNotNull();
assertThat(s.getStreakCompleted()).isEqualTo(0);
assertThat(s.getStreakFailed()).isEqualTo(1);
assertThat(s.getProcessId()).isEqualTo(processId);
assertThat(s.isFailed()).isEqualTo(true);
assertThat(s.isActive()).isEqualTo(false);
}
use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.
the class RetryServiceTest method retryFailedSchedule.
@Test
public void retryFailedSchedule() {
String serviceName = PipeliteIdCreator.serviceName();
String processId = PipeliteIdCreator.processId();
RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(SCHEDULE_NAME);
Process process = ProcessFactory.create(processId, registeredPipeline);
// Failed process
process.setProcessEntity(processService.createExecution(SCHEDULE_NAME, processId, 1));
processService.startExecution(process.getProcessEntity());
ProcessEntity processEntity = processService.endExecution(process, ProcessState.FAILED);
// Failed stage
Stage stage = process.getStage(STAGE_NAME).get();
stageService.createExecution(SCHEDULE_NAME, processId, stage);
stageService.startExecution(stage);
stageService.endExecution(stage, StageExecutorResult.error());
StageEntity stageEntity = stage.getStageEntity();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.FAILED);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.ERROR);
// Failed schedule
scheduleService.createSchedule(serviceName, SCHEDULE_NAME, CRON);
ScheduleEntity scheduleEntity = scheduleService.startExecution(SCHEDULE_NAME, processId);
ZonedDateTime nextTime = CronUtils.launchTime(CRON, ZonedDateTime.now().plusHours(1));
scheduleEntity = scheduleService.endExecution(processEntity, nextTime);
assertThat(scheduleEntity.isFailed()).isTrue();
// Create schedule runner
processRunnerPoolManager._createScheduleRunner();
ScheduleRunner scheduleRunner = runnerService.getScheduleRunner();
scheduleRunner.setMaximumExecutions(SCHEDULE_NAME, 1);
assertThat(scheduleRunner.getScheduleCrons().size()).isOne();
assertThat(scheduleRunner.getScheduleCrons().get(0).getPipelineName()).isEqualTo(SCHEDULE_NAME);
// Check schedule state
assertSetupSchedule(serviceName, SCHEDULE_NAME, processId, CRON, nextTime);
ZonedDateTime retryTime = ZonedDateTime.now();
Time.wait(Duration.ofMillis(1000));
scheduleRunner.startUp();
// Retry
retryService.retry(SCHEDULE_NAME, processId);
while (!scheduleRunner.isIdle()) {
scheduleRunner.runOneIteration();
Time.wait(Duration.ofMillis(100));
}
// Check schedule state
assertRetriedSchedule(serviceName, SCHEDULE_NAME, processId, CRON, retryTime);
// Check process state
processEntity = processService.getSavedProcess(SCHEDULE_NAME, processId).get();
assertThat(processEntity.getPipelineName()).isEqualTo(SCHEDULE_NAME);
assertThat(processEntity.getProcessId()).isEqualTo(processId);
assertThat(processEntity.getStartTime()).isNotNull();
assertThat(processEntity.getEndTime()).isNotNull();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.COMPLETED);
// Check stage state
stageEntity = stageService.getSavedStage(SCHEDULE_NAME, processId, STAGE_NAME).get();
assertThat(stageEntity.getPipelineName()).isEqualTo(SCHEDULE_NAME);
assertThat(stageEntity.getProcessId()).isEqualTo(processId);
assertThat(stageEntity.getStageName()).isEqualTo(STAGE_NAME);
assertThat(stageEntity.getStageState()).isEqualTo(StageState.SUCCESS);
assertThat(stageEntity.getStartTime()).isNotNull();
assertThat(stageEntity.getEndTime()).isNotNull();
}
use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.
the class RetryServiceTest method assertRetriedSchedule.
private void assertRetriedSchedule(String serviceName, String pipelineName, String processId, String cron, ZonedDateTime nextTime) {
// Success
ScheduleEntity s = scheduleService.getSavedSchedule(pipelineName).get();
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(CronUtils.describe(cron));
assertThat(s.getExecutionCount()).isEqualTo(2);
assertThat(s.getNextTime()).isAfterOrEqualTo(nextTime.truncatedTo(ChronoUnit.SECONDS));
assertThat(s.getStartTime()).isNotNull();
assertThat(s.getEndTime()).isNotNull();
assertThat(s.getLastCompleted()).isNotNull();
assertThat(s.getLastFailed()).isNotNull();
assertThat(s.getStreakCompleted()).isEqualTo(1);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.getProcessId()).isEqualTo(processId);
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(false);
}
use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.
the class ScheduleServiceTest method lifecycle.
@Test
public void lifecycle() {
String serviceName = PipeliteIdCreator.serviceName();
String pipelineName = PipeliteIdCreator.pipelineName();
String cron = PipeliteTestConstants.CRON_EVERY_TWO_SECONDS;
String description = CronUtils.describe(cron);
ScheduleEntity s = scheduleService.createSchedule(serviceName, pipelineName, cron);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isZero();
assertThat(s.getProcessId()).isNull();
assertThat(s.getStartTime()).isNull();
assertThat(s.getEndTime()).isNull();
assertThat(s.getNextTime()).isNull();
assertThat(s.getLastCompleted()).isNull();
assertThat(s.getLastFailed()).isNull();
assertThat(s.getStreakCompleted()).isEqualTo(0);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(false);
// Get all schedules.
List<ScheduleEntity> schedules = scheduleService.getSchedules(serviceName);
assertThat(schedules.size()).isEqualTo(1);
assertThat(schedules.get(0)).isEqualTo(s);
// Get active schedules.
List<ScheduleEntity> activeSchedules = scheduleService.getSchedules(serviceName);
assertThat(activeSchedules.size()).isEqualTo(1);
assertThat(activeSchedules.get(0)).isEqualTo(s);
// Schedule first execution.
ZonedDateTime nextTime1 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
s = scheduleService.scheduleExecution(s, nextTime1);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isEqualTo(0);
assertThat(s.getNextTime()).isEqualTo(nextTime1);
assertThat(s.getStartTime()).isNull();
assertThat(s.getEndTime()).isNull();
assertThat(s.getLastCompleted()).isNull();
assertThat(s.getLastFailed()).isNull();
assertThat(s.getStreakCompleted()).isEqualTo(0);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.getProcessId()).isNull();
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(false);
// Start first execution.
String processId1 = "test1";
s = scheduleService.startExecution(pipelineName, processId1);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isEqualTo(0);
assertThat(s.getNextTime()).isNull();
assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime1);
assertThat(s.getEndTime()).isNull();
assertThat(s.getLastCompleted()).isNull();
assertThat(s.getLastFailed()).isNull();
assertThat(s.getStreakCompleted()).isEqualTo(0);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.getProcessId()).isEqualTo(processId1);
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(true);
// End first execution.
ZonedDateTime endTime1 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
ProcessEntity processEntity1 = new ProcessEntity();
processEntity1.setPipelineName(pipelineName);
processEntity1.setProcessId(processId1);
processEntity1.setProcessState(ProcessState.COMPLETED);
ZonedDateTime nextTime2 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
s = scheduleService.endExecution(processEntity1, nextTime2);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isEqualTo(1);
assertThat(s.getNextTime()).isEqualTo(nextTime2);
assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime1);
assertThat(s.getEndTime()).isAfterOrEqualTo(endTime1);
assertThat(s.getLastCompleted()).isEqualTo(endTime1);
assertThat(s.getLastFailed()).isNull();
assertThat(s.getStreakCompleted()).isEqualTo(1);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.getProcessId()).isEqualTo(processId1);
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(false);
// Start second execution.
String processId2 = "test2";
s = scheduleService.startExecution(pipelineName, processId2);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isEqualTo(1);
assertThat(s.getNextTime()).isNull();
assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime2);
assertThat(s.getEndTime()).isNull();
assertThat(s.getLastCompleted()).isEqualTo(endTime1);
assertThat(s.getLastFailed()).isNull();
assertThat(s.getStreakCompleted()).isEqualTo(1);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.getProcessId()).isEqualTo(processId2);
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(true);
// End second execution.
ZonedDateTime endTime2 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
ProcessEntity processEntity2 = new ProcessEntity();
processEntity2.setPipelineName(pipelineName);
processEntity2.setProcessId(processId2);
processEntity2.setProcessState(ProcessState.COMPLETED);
ZonedDateTime nextTime3 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
s = scheduleService.endExecution(processEntity2, nextTime3);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isEqualTo(2);
assertThat(s.getNextTime()).isEqualTo(nextTime3);
assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime2);
assertThat(s.getEndTime()).isAfterOrEqualTo(endTime2);
assertThat(s.getLastCompleted()).isEqualTo(s.getEndTime());
assertThat(s.getLastFailed()).isNull();
assertThat(s.getStreakCompleted()).isEqualTo(2);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.getProcessId()).isEqualTo(processId2);
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(false);
// Start third execution.
String processId3 = "test3";
s = scheduleService.startExecution(pipelineName, processId3);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isEqualTo(2);
assertThat(s.getNextTime()).isNull();
assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime3);
assertThat(s.getEndTime()).isNull();
assertThat(s.getLastCompleted()).isAfterOrEqualTo(endTime2);
assertThat(s.getLastFailed()).isNull();
assertThat(s.getStreakCompleted()).isEqualTo(2);
assertThat(s.getStreakFailed()).isEqualTo(0);
assertThat(s.getProcessId()).isEqualTo(processId3);
assertThat(s.isFailed()).isEqualTo(false);
assertThat(s.isActive()).isEqualTo(true);
// End third execution (FAILED).
ZonedDateTime endTime3 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
ProcessEntity processEntity3 = new ProcessEntity();
processEntity3.setPipelineName(pipelineName);
processEntity3.setProcessId(processId3);
processEntity3.setProcessState(ProcessState.FAILED);
ZonedDateTime nextTime4 = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
s = scheduleService.endExecution(processEntity3, nextTime4);
assertThat(s.getServiceName()).isEqualTo(serviceName);
assertThat(s.getPipelineName()).isEqualTo(pipelineName);
assertThat(s.getCron()).isEqualTo(cron);
assertThat(s.getDescription()).isEqualTo(description);
assertThat(s.getExecutionCount()).isEqualTo(3);
assertThat(s.getNextTime()).isEqualTo(nextTime4);
assertThat(s.getStartTime()).isAfterOrEqualTo(nextTime3);
assertThat(s.getEndTime()).isAfterOrEqualTo(endTime3);
assertThat(s.getLastCompleted()).isAfterOrEqualTo(endTime2);
assertThat(s.getLastFailed()).isEqualTo(s.getEndTime());
assertThat(s.getStreakCompleted()).isEqualTo(0);
assertThat(s.getStreakFailed()).isEqualTo(1);
assertThat(s.getProcessId()).isEqualTo(processId3);
assertThat(s.isFailed()).isEqualTo(true);
assertThat(s.isActive()).isEqualTo(false);
}
use of pipelite.entity.ScheduleEntity in project pipelite by enasequence.
the class ScheduleServiceTest method isRetryScheduleWithNotFailedSchedule.
@Test
public void isRetryScheduleWithNotFailedSchedule() {
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();
PipeliteProcessRetryException ex = assertThrows(PipeliteProcessRetryException.class, () -> scheduleService.isRetrySchedule(pipelineName, processId));
assertThat(ex.getMessage()).contains("the process for the schedule is not failed");
}
Aggregations