Search in sources :

Example 16 with Execution

use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.

the class SwitchTest method switchThird.

@Test
void switchThird() throws TimeoutException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "switch", null, (f, e) -> ImmutableMap.of("string", "THIRD"));
    assertThat(execution.getTaskRunList().get(1).getTaskId(), is("t3"));
    assertThat(execution.findTaskRunsByTaskId("parent-seq").get(0).getOutputs().get("value"), is("THIRD"));
    assertThat(execution.findTaskRunsByTaskId("parent-seq").get(0).getOutputs().get("defaults"), is(false));
    assertThat(execution.getTaskRunList().get(2).getTaskId(), is("failed"));
    assertThat(execution.getTaskRunList().get(3).getTaskId(), is("error-t1"));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 17 with Execution

use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.

the class SwitchTest method switchSecond.

@Test
void switchSecond() throws TimeoutException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "switch", null, (f, e) -> ImmutableMap.of("string", "SECOND"));
    assertThat(execution.getTaskRunList().get(1).getTaskId(), is("t2"));
    assertThat(execution.findTaskRunsByTaskId("parent-seq").get(0).getOutputs().get("value"), is("SECOND"));
    assertThat(execution.findTaskRunsByTaskId("parent-seq").get(0).getOutputs().get("defaults"), is(false));
    assertThat(execution.getTaskRunList().get(2).getTaskId(), is("t2_sub"));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 18 with Execution

use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.

the class SwitchTest method switchDefault.

@Test
void switchDefault() throws TimeoutException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "switch", null, (f, e) -> ImmutableMap.of("string", "DEFAULT"));
    assertThat(execution.getTaskRunList().get(1).getTaskId(), is("default"));
    assertThat(execution.findTaskRunsByTaskId("parent-seq").get(0).getOutputs().get("value"), is("DEFAULT"));
    assertThat(execution.findTaskRunsByTaskId("parent-seq").get(0).getOutputs().get("defaults"), is(true));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 19 with Execution

use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.

the class VariablesTest method invalidVars.

@Test
void invalidVars() throws TimeoutException {
    List<LogEntry> logs = new ArrayList<>();
    workerTaskLogQueue.receive(logs::add);
    Execution execution = runnerUtils.runOne("io.kestra.tests", "variables-invalid");
    List<LogEntry> filters = TestsUtils.filterLogs(logs, execution.getTaskRunList().get(1));
    assertThat(execution.getTaskRunList(), hasSize(2));
    assertThat(execution.getTaskRunList().get(1).getState().getCurrent(), is(State.Type.FAILED));
    assertThat(filters.stream().filter(logEntry -> logEntry.getMessage().contains("Missing variable: 'inputs' on '{{inputs.invalid}}'")).count(), greaterThan(0L));
    assertThat(execution.getState().getCurrent(), is(State.Type.FAILED));
}
Also used : Execution(io.kestra.core.models.executions.Execution) ArrayList(java.util.ArrayList) LogEntry(io.kestra.core.models.executions.LogEntry) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 20 with Execution

use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.

the class SchedulerThreadTest method thread.

@Test
void thread() throws Exception {
    // mock flow listeners
    MemoryFlowListeners flowListenersServiceSpy = spy(this.flowListenersService);
    SchedulerExecutionStateInterface schedulerExecutionStateSpy = spy(this.executionState);
    CountDownLatch queueCount = new CountDownLatch(2);
    Flow flow = createThreadFlow();
    doReturn(Collections.singletonList(flow)).when(flowListenersServiceSpy).flows();
    // mock the backfill execution is ended
    doAnswer(invocation -> Optional.of(Execution.builder().state(new State().withState(State.Type.SUCCESS)).build())).when(schedulerExecutionStateSpy).findById(any());
    // scheduler
    try (AbstractScheduler scheduler = new DefaultScheduler(applicationContext, flowListenersServiceSpy, schedulerExecutionStateSpy, triggerState)) {
        AtomicReference<Execution> last = new AtomicReference<>();
        // wait for execution
        executionQueue.receive(SchedulerThreadTest.class, execution -> {
            last.set(execution);
            assertThat(execution.getFlowId(), is(flow.getId()));
            if (execution.getState().getCurrent() != State.Type.SUCCESS) {
                executionQueue.emit(execution.withState(State.Type.SUCCESS));
                queueCount.countDown();
            }
        });
        scheduler.run();
        queueCount.await(1, TimeUnit.MINUTES);
        assertThat(last.get().getVariables().get("defaultInjected"), is("done"));
        assertThat(last.get().getVariables().get("counter"), is(3));
        AbstractSchedulerTest.COUNTER = 0;
    }
}
Also used : Execution(io.kestra.core.models.executions.Execution) State(io.kestra.core.models.flows.State) MemoryFlowListeners(io.kestra.runner.memory.MemoryFlowListeners) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Flow(io.kestra.core.models.flows.Flow) Test(org.junit.jupiter.api.Test)

Aggregations

Execution (io.kestra.core.models.executions.Execution)159 Test (org.junit.jupiter.api.Test)114 Flow (io.kestra.core.models.flows.Flow)59 AbstractMemoryRunnerTest (io.kestra.core.runners.AbstractMemoryRunnerTest)39 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 State (io.kestra.core.models.flows.State)14 TaskRun (io.kestra.core.models.executions.TaskRun)13 EachSequentialTest (io.kestra.core.tasks.flows.EachSequentialTest)13 FlowCaseTest (io.kestra.core.tasks.flows.FlowCaseTest)13 TemplateTest (io.kestra.core.tasks.flows.TemplateTest)13 LogEntry (io.kestra.core.models.executions.LogEntry)11 Map (java.util.Map)11 InputsTest (io.kestra.core.runners.InputsTest)10 Inject (jakarta.inject.Inject)7 FlowRepositoryInterface (io.kestra.core.repositories.FlowRepositoryInterface)6 ZonedDateTime (java.time.ZonedDateTime)6 InternalException (io.kestra.core.exceptions.InternalException)5 QueueFactoryInterface (io.kestra.core.queues.QueueFactoryInterface)5 QueueInterface (io.kestra.core.queues.QueueInterface)5