use of pipelite.process.Process in project pipelite by enasequence.
the class ProcessServiceTest method lifecycle.
@Test
public void lifecycle() {
String pipelineName = PipeliteIdCreator.pipelineName();
String processId = PipeliteIdCreator.processId();
int priority = 1;
ProcessEntity processEntity = processService.createExecution(pipelineName, processId, priority);
assertThat(processEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(processEntity.getProcessId()).isEqualTo(processId);
assertThat(processEntity.getPriority()).isEqualTo(priority);
assertThat(processEntity.getExecutionCount()).isEqualTo(0);
assertThat(processEntity.getStartTime()).isNull();
assertThat(processEntity.getEndTime()).isNull();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.PENDING);
processService.startExecution(processEntity);
assertThat(processEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(processEntity.getProcessId()).isEqualTo(processId);
assertThat(processEntity.getPriority()).isEqualTo(priority);
assertThat(processEntity.getExecutionCount()).isEqualTo(0);
assertThat(processEntity.getStartTime()).isNotNull();
assertThat(processEntity.getEndTime()).isNull();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.ACTIVE);
assertThat(processService.getSavedProcess(pipelineName, processId).get()).isEqualTo(processEntity);
Process process = new ProcessBuilder(processId).execute("STAGE").withSyncTestExecutor().build();
process.setProcessEntity(processEntity);
processService.endExecution(process, ProcessState.COMPLETED);
assertThat(processEntity.getPipelineName()).isEqualTo(pipelineName);
assertThat(processEntity.getProcessId()).isEqualTo(processId);
assertThat(processEntity.getPriority()).isEqualTo(priority);
assertThat(processEntity.getExecutionCount()).isEqualTo(1);
assertThat(processEntity.getStartTime()).isNotNull();
assertThat(processEntity.getEndTime()).isNotNull();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.COMPLETED);
assertThat(processService.getSavedProcess(pipelineName, processId).get()).isEqualTo(processEntity);
}
use of pipelite.process.Process in project pipelite by enasequence.
the class RetryServiceTest method retryFailedProcessThrowsBecauseNotFailed.
@Test
public void retryFailedProcessThrowsBecauseNotFailed() {
String processId = PipeliteIdCreator.processId();
RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(PIPELINE_NAME);
Process process = ProcessFactory.create(processId, registeredPipeline);
// Save completed process
process.setProcessEntity(processService.createExecution(PIPELINE_NAME, processId, 1));
processService.startExecution(process.getProcessEntity());
processService.endExecution(process, ProcessState.COMPLETED);
// Check completed process
ProcessEntity processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.COMPLETED);
// Retry
Exception exception = assertThrows(PipeliteProcessRetryException.class, () -> retryService.retry(PIPELINE_NAME, processId));
assertThat(exception.getMessage()).contains("process is not failed");
}
use of pipelite.process.Process 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.process.Process in project pipelite by enasequence.
the class RetryServiceTest method retryFailedProcessThrowsUnknownStage.
@Test
public void retryFailedProcessThrowsUnknownStage() {
String processId = PipeliteIdCreator.processId();
RegisteredPipeline registeredPipeline = registeredPipelineService.getRegisteredPipeline(PIPELINE_NAME);
Process process = ProcessFactory.create(processId, registeredPipeline);
// Save completed process
process.setProcessEntity(processService.createExecution(PIPELINE_NAME, processId, 1));
processService.startExecution(process.getProcessEntity());
processService.endExecution(process, ProcessState.FAILED);
// Check completed process
ProcessEntity processEntity = processService.getSavedProcess(PIPELINE_NAME, processId).get();
assertThat(processEntity.getProcessState()).isEqualTo(ProcessState.FAILED);
// Retry
Exception exception = assertThrows(PipeliteProcessRetryException.class, () -> retryService.retry(PIPELINE_NAME, processId));
assertThat(exception.getMessage()).contains("unknown stage");
}
use of pipelite.process.Process in project pipelite by enasequence.
the class DependencyResolverTest method othersActivePendingIndependentOneErrorMaxRetriesLeft.
@Test
public void othersActivePendingIndependentOneErrorMaxRetriesLeft() {
for (StageState stageState : EnumSet.of(ACTIVE, PENDING)) {
ProcessBuilder builder = createProcessBuilder();
Process process = builder.execute("STAGE1").withSyncTestExecutor(StageExecutorState.ERROR, ExecutorParameters.builder().maximumRetries(1).immediateRetries(0).build()).execute("STAGE2").withSyncTestExecutor().execute("STAGE3").withSyncTestExecutor().execute("STAGE4").withSyncTestExecutor().build();
Set<Stage> stages = process.getStages();
int stageNumber = 0;
for (Stage stage : process.getStages()) {
if (stageNumber == 0) {
simulateStageExecution(stage, StageState.ERROR);
} else {
simulateStageExecution(stage, stageState);
}
stageNumber++;
}
assertGetDependsOnStages(process, "STAGE1", Collections.emptyList());
assertGetDependsOnStages(process, "STAGE2", Collections.emptyList());
assertGetDependsOnStages(process, "STAGE3", Collections.emptyList());
assertGetDependsOnStages(process, "STAGE4", Collections.emptyList());
assertGetDependsOnStagesDirectly(process, "STAGE1", Collections.emptyList());
assertGetDependsOnStagesDirectly(process, "STAGE2", Collections.emptyList());
assertGetDependsOnStagesDirectly(process, "STAGE3", Collections.emptyList());
assertGetDependsOnStagesDirectly(process, "STAGE4", Collections.emptyList());
assertGetDependentStages(process, "STAGE1", Collections.emptyList());
assertGetDependentStages(process, "STAGE2", Collections.emptyList());
assertGetDependentStages(process, "STAGE3", Collections.emptyList());
assertGetDependentStages(process, "STAGE4", Collections.emptyList());
assertGetPermanentFailedStages(stages, Collections.emptyList());
assertGetImmediatelyExecutableStages(process, Arrays.asList("STAGE2", "STAGE3", "STAGE4"));
assertGetEventuallyExecutableStages(process, Arrays.asList("STAGE1", "STAGE2", "STAGE3", "STAGE4"));
}
}
Aggregations