Search in sources :

Example 11 with Execution

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

the class FlowCaseTest method run.

@SuppressWarnings({ "ResultOfMethodCallIgnored", "unchecked" })
void run(String input, State.Type fromState, State.Type triggerState, int count, String outputs) throws Exception {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    AtomicReference<Execution> triggered = new AtomicReference<>();
    executionQueue.receive(execution -> {
        if (execution.getFlowId().equals("switch") && execution.getState().getCurrent().isTerninated()) {
            countDownLatch.countDown();
            triggered.set(execution);
        }
    });
    Execution execution = runnerUtils.runOne("io.kestra.tests", "task-flow", null, (f, e) -> ImmutableMap.of("string", input), Duration.ofMinutes(1));
    countDownLatch.await(1, TimeUnit.MINUTES);
    assertThat(execution.getTaskRunList(), hasSize(1));
    assertThat(execution.getState().getCurrent(), is(fromState));
    if (outputs != null) {
        assertThat(((Map<String, String>) execution.getTaskRunList().get(0).getOutputs().get("outputs")).get("extracted"), containsString(outputs));
    }
    assertThat(execution.getTaskRunList().get(0).getOutputs().get("executionId"), is(triggered.get().getId()));
    if (outputs != null) {
        assertThat(execution.getTaskRunList().get(0).getOutputs().get("state"), is(triggered.get().getState().getCurrent().name()));
    }
    assertThat(triggered.get().getTrigger().getType(), is(Flow.class.getName()));
    assertThat(triggered.get().getTrigger().getVariables().get("executionId"), is(execution.getId()));
    assertThat(triggered.get().getTrigger().getVariables().get("flowId"), is(execution.getFlowId()));
    assertThat(triggered.get().getTrigger().getVariables().get("namespace"), is(execution.getNamespace()));
    assertThat(triggered.get().getTaskRunList(), hasSize(count));
    assertThat(triggered.get().getState().getCurrent(), is(triggerState));
}
Also used : Execution(io.kestra.core.models.executions.Execution) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with Execution

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

the class ParallelTest method parallelNested.

@Test
void parallelNested() throws TimeoutException, QueueException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "parallel-nested");
    assertThat(execution.getTaskRunList(), hasSize(11));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 13 with Execution

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

the class PauseTest method run.

@Test
void run() throws Exception {
    Flow flow = flowRepository.findById("io.kestra.tests", "pause").orElseThrow();
    Execution execution = runnerUtils.runOne("io.kestra.tests", "pause", Duration.ofSeconds(120));
    assertThat(execution.getState().getCurrent(), is(State.Type.PAUSED));
    assertThat(execution.getTaskRunList().get(0).getState().getCurrent(), is(State.Type.PAUSED));
    assertThat(execution.getTaskRunList(), hasSize(1));
    Execution restarted = executionService.markAs(execution, execution.findTaskRunByTaskIdAndValue("pause", List.of()).getId(), State.Type.RUNNING);
    execution = runnerUtils.awaitExecution(e -> e.getState().getCurrent() == State.Type.SUCCESS, () -> executionQueue.emit(restarted), Duration.ofSeconds(120));
    assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) QueueFactoryInterface(io.kestra.core.queues.QueueFactoryInterface) QueueInterface(io.kestra.core.queues.QueueInterface) TimeoutException(java.util.concurrent.TimeoutException) ExecutionService(io.kestra.core.services.ExecutionService) Execution(io.kestra.core.models.executions.Execution) InternalException(io.kestra.core.exceptions.InternalException) State(io.kestra.core.models.flows.State) Test(org.junit.jupiter.api.Test) List(java.util.List) Duration(java.time.Duration) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.is(org.hamcrest.Matchers.is) Flow(io.kestra.core.models.flows.Flow) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Inject(jakarta.inject.Inject) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest) FlowRepositoryInterface(io.kestra.core.repositories.FlowRepositoryInterface) Named(jakarta.inject.Named) Execution(io.kestra.core.models.executions.Execution) Flow(io.kestra.core.models.flows.Flow) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 14 with Execution

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

the class SequentialTest method sequentialWithLocalErrors.

@Test
void sequentialWithLocalErrors() throws TimeoutException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "sequential-with-local-errors");
    assertThat(execution.getTaskRunList(), hasSize(6));
    assertThat(execution.getState().getCurrent(), is(State.Type.FAILED));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 15 with Execution

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

the class SequentialTest method sequential.

@Test
void sequential() throws TimeoutException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "sequential");
    assertThat(execution.getTaskRunList(), hasSize(11));
    assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

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