Search in sources :

Example 6 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class DependencyResolverTest method independentAllErrorNoRetriesLeft.

@Test
public void independentAllErrorNoRetriesLeft() {
    ProcessBuilder builder = createProcessBuilder();
    Process process = builder.execute("STAGE1").withSyncTestExecutor(StageExecutorState.ERROR, NO_RETRIES_EXECUTOR_PARAMS).execute("STAGE2").withSyncTestExecutor(StageExecutorState.ERROR, NO_RETRIES_EXECUTOR_PARAMS).execute("STAGE3").withSyncTestExecutor(StageExecutorState.ERROR, NO_RETRIES_EXECUTOR_PARAMS).execute("STAGE4").withSyncTestExecutor(StageExecutorState.ERROR, NO_RETRIES_EXECUTOR_PARAMS).build();
    Set<Stage> stages = process.getStages();
    for (Stage stage : stages) {
        simulateStageExecution(stage, StageState.ERROR);
    }
    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, Arrays.asList("STAGE1", "STAGE2", "STAGE3", "STAGE4"));
    assertGetImmediatelyExecutableStages(process, Collections.emptyList());
    assertGetEventuallyExecutableStages(process, Collections.emptyList());
}
Also used : ProcessBuilder(pipelite.process.builder.ProcessBuilder) Stage(pipelite.stage.Stage) Process(pipelite.process.Process) Test(org.junit.jupiter.api.Test)

Example 7 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class DependencyResolverTest method othersActivePendingIndependentOnePermanentError.

@Test
public void othersActivePendingIndependentOnePermanentError() {
    for (StageState stageState : EnumSet.of(ACTIVE, PENDING)) {
        ProcessBuilder builder = createProcessBuilder();
        Process process = builder.execute("STAGE1").withSyncTestExecutor(StageExecutorState.ERROR).execute("STAGE2").withSyncTestExecutor().execute("STAGE3").withSyncTestExecutor().execute("STAGE4").withSyncTestExecutor().build();
        Set<Stage> stages = process.getStages();
        int stageNumber = 0;
        for (Stage stage : stages) {
            if (stageNumber == 0) {
                simulateStageExecution(stage, ErrorType.PERMANENT_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, Arrays.asList("STAGE1"));
        assertGetImmediatelyExecutableStages(process, Arrays.asList("STAGE2", "STAGE3", "STAGE4"));
        assertGetEventuallyExecutableStages(process, Arrays.asList("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)

Example 8 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class DependencyResolverTest method simulatedStageExecution.

private SingleStageProcess simulatedStageExecution(StageState stageState, int executionCount, int immediateExecutionCount, int maximumRetries, int immediateRetries) {
    StageEntity stageEntity = new StageEntity();
    stageEntity.setExecutionCount(executionCount);
    stageEntity.setStageState(stageState);
    SyncTestExecutor executor = StageExecutor.createSyncTestExecutor(StageExecutorState.SUCCESS, null);
    executor.setExecutorParams(ExecutorParameters.builder().immediateRetries(immediateRetries).maximumRetries(maximumRetries).build());
    Stage stage = Stage.builder().stageName("STAGE").executor(executor).build();
    stage.setStageEntity(stageEntity);
    for (int i = 0; i < immediateExecutionCount; ++i) {
        stage.incrementImmediateExecutionCount();
    }
    return new SingleStageProcess(new Process("TEST", ProcessBuilderHelper.stageGraph(Arrays.asList(new ProcessBuilderHelper.AddedStage(stage)))), stage);
}
Also used : Stage(pipelite.stage.Stage) Process(pipelite.process.Process) StageEntity(pipelite.entity.StageEntity) SyncTestExecutor(pipelite.executor.SyncTestExecutor)

Example 9 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class ProcessRunnerPoolTest method createProcess.

private Process createProcess(Function<StageExecutorRequest, StageExecutorResult> callback) {
    String processId = PipeliteIdCreator.processId();
    ExecutorParameters executorParams = new ExecutorParameters();
    executorParams.setMaximumRetries(0);
    Process process = new ProcessBuilder(processId).execute("STAGE1").withAsyncTestExecutor(callback, executorParams).build();
    ProcessEntity processEntity = ProcessEntity.createExecution(PIPELINE_NAME, processId, ProcessEntity.DEFAULT_PRIORITY);
    process.setProcessEntity(processEntity);
    return process;
}
Also used : ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) ProcessBuilder(pipelite.process.builder.ProcessBuilder) ProcessEntity(pipelite.entity.ProcessEntity) Process(pipelite.process.Process)

Example 10 with Process

use of pipelite.process.Process in project pipelite by enasequence.

the class ProcessRunnerPoolTest method testSuccess.

@Test
public void testSuccess() {
    AtomicLong lockProcessCnt = new AtomicLong();
    AtomicLong unlockProcessCnt = new AtomicLong();
    ProcessRunnerPool pool = createProcessRunnerPool(lockProcessCnt, unlockProcessCnt);
    AtomicInteger runProcessCnt = new AtomicInteger();
    for (int i = 0; i < PROCESS_CNT; i++) {
        Process process = createProcess((request) -> StageExecutorResult.success());
        pool.runProcess(PIPELINE_NAME, process, (p) -> runProcessCnt.incrementAndGet());
    }
    while (!pool.isIdle()) {
        Time.wait(Duration.ofSeconds(1));
        pool.runOneIteration();
    }
    PipelineMetrics pipelineMetrics = metrics.pipeline(PIPELINE_NAME);
    assertThat(runProcessCnt.get()).isEqualTo(PROCESS_CNT);
    assertThat(pipelineMetrics.process().getCompletedCount()).isEqualTo(PROCESS_CNT);
    assertThat(pipelineMetrics.process().getFailedCount()).isZero();
    assertThat(pipelineMetrics.process().getInternalErrorCount()).isZero();
    assertThat(metrics.getProcessRunnerPoolOneIterationTimer().mean(TimeUnit.SECONDS)).isLessThan(5);
    assertThat(metrics.getProcessRunnerOneIterationTimer().mean(TimeUnit.SECONDS)).isLessThan(5);
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getCompletedTimeSeries())).isEqualTo(PROCESS_CNT);
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getCompletedTimeSeries(), ZonedDateTime.now().minusHours(1))).isEqualTo(PROCESS_CNT);
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getCompletedTimeSeries(), ZonedDateTime.now().plusHours(1))).isZero();
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getFailedTimeSeries())).isZero();
    assertThat(TimeSeriesMetrics.getCount(pipelineMetrics.process().getInternalErrorTimeSeries())).isZero();
    assertThat(lockProcessCnt.get()).isEqualTo(PROCESS_CNT);
    assertThat(unlockProcessCnt.get()).isEqualTo(PROCESS_CNT);
    assertThat(pool.getActiveProcessCount()).isZero();
    assertThat(pool.getActiveProcessRunners().size()).isZero();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Process(pipelite.process.Process) PipelineMetrics(pipelite.metrics.PipelineMetrics) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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