Search in sources :

Example 26 with Process

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);
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) ProcessBuilder(pipelite.process.builder.ProcessBuilder) Process(pipelite.process.Process) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 27 with Process

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");
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 28 with Process

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();
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) ZonedDateTime(java.time.ZonedDateTime) ProcessEntity(pipelite.entity.ProcessEntity) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity) ScheduleEntity(pipelite.entity.ScheduleEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 29 with Process

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");
}
Also used : ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process) PipeliteProcessRetryException(pipelite.exception.PipeliteProcessRetryException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with Process

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"));
    }
}
Also used : StageState(pipelite.stage.StageState) ProcessBuilder(pipelite.process.builder.ProcessBuilder) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) Test(org.junit.jupiter.api.Test)

Aggregations

Process (pipelite.process.Process)40 Test (org.junit.jupiter.api.Test)29 Stage (pipelite.stage.Stage)27 ProcessBuilder (pipelite.process.builder.ProcessBuilder)24 ProcessEntity (pipelite.entity.ProcessEntity)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 StageState (pipelite.stage.StageState)14 StageEntity (pipelite.entity.StageEntity)8 StageLogEntity (pipelite.entity.StageLogEntity)4 ArrayList (java.util.ArrayList)3 PipeliteProcessRetryException (pipelite.exception.PipeliteProcessRetryException)3 ZonedDateTime (java.time.ZonedDateTime)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 RegisteredPipeline (pipelite.RegisteredPipeline)2 ScheduleEntity (pipelite.entity.ScheduleEntity)2 SyncTestExecutor (pipelite.executor.SyncTestExecutor)2 PipelineMetrics (pipelite.metrics.PipelineMetrics)2 ProcessState (pipelite.process.ProcessState)2 ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)2