Search in sources :

Example 96 with Execution

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

the class ListenersTestTask method run.

@SuppressWarnings("unchecked")
@Override
public ListenersTestTask.Output run(RunContext runContext) throws Exception {
    ExecutionRepositoryInterface executionRepository = runContext.getApplicationContext().getBean(ExecutionRepositoryInterface.class);
    RetryUtils.Instance<Execution, NoSuchElementException> retryInstance = runContext.getApplicationContext().getBean(RetryUtils.class).of(Exponential.builder().delayFactor(2.0).interval(Duration.ofSeconds(1)).maxInterval(Duration.ofSeconds(15)).maxAttempt(-1).maxDuration(Duration.ofMinutes(10)).build(), runContext.logger());
    String executionRendererId = runContext.render(runContext.render("{{ execution.id }}"));
    Execution execution = retryInstance.run(NoSuchElementException.class, () -> executionRepository.findById(executionRendererId).filter(e -> e.getState().getCurrent().isTerninated()).orElseThrow(() -> new NoSuchElementException("Unable to find execution '" + executionRendererId + "'")));
    return Output.builder().value(execution.toString()).build();
}
Also used : Execution(io.kestra.core.models.executions.Execution) ExecutionRepositoryInterface(io.kestra.core.repositories.ExecutionRepositoryInterface) RetryUtils(io.kestra.core.utils.RetryUtils) NoSuchElementException(java.util.NoSuchElementException)

Example 97 with Execution

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

the class RunContextTest method variables.

@Test
void variables() throws TimeoutException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "return");
    assertThat(execution.getTaskRunList(), hasSize(3));
    assertThat(ZonedDateTime.from(ZonedDateTime.parse((String) execution.getTaskRunList().get(0).getOutputs().get("value"))), ZonedDateTimeMatchers.within(10, ChronoUnit.SECONDS, ZonedDateTime.now()));
    assertThat(execution.getTaskRunList().get(1).getOutputs().get("value"), is("task-id"));
    assertThat(execution.getTaskRunList().get(2).getOutputs().get("value"), is("return"));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Test(org.junit.jupiter.api.Test)

Example 98 with Execution

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

the class RunContextTest method logs.

@Test
void logs() throws TimeoutException {
    List<LogEntry> logs = new ArrayList<>();
    List<LogEntry> filters;
    workerTaskLogQueue.receive(logs::add);
    Execution execution = runnerUtils.runOne("io.kestra.tests", "logs");
    assertThat(execution.getTaskRunList(), hasSize(3));
    filters = TestsUtils.filterLogs(logs, execution.getTaskRunList().get(0));
    assertThat(filters, hasSize(1));
    assertThat(filters.get(0).getLevel(), is(Level.TRACE));
    assertThat(filters.get(0).getMessage(), is("first t1"));
    filters = TestsUtils.filterLogs(logs, execution.getTaskRunList().get(1));
    assertThat(filters, hasSize(1));
    assertThat(filters.get(0).getLevel(), is(Level.WARN));
    assertThat(filters.get(0).getMessage(), is("second io.kestra.core.tasks.debugs.Echo"));
    filters = TestsUtils.filterLogs(logs, execution.getTaskRunList().get(2));
    assertThat(filters, hasSize(1));
    assertThat(filters.get(0).getLevel(), is(Level.ERROR));
    assertThat(filters.get(0).getMessage(), is("third logs"));
}
Also used : Execution(io.kestra.core.models.executions.Execution) LogEntry(io.kestra.core.models.executions.LogEntry) Test(org.junit.jupiter.api.Test)

Example 99 with Execution

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

the class TaskDefaultsCaseTest method invalidTaskDefaults.

public void invalidTaskDefaults() throws TimeoutException {
    List<LogEntry> logs = new ArrayList<>();
    logQueue.receive(logs::add);
    Execution execution = runnerUtils.runOne("io.kestra.tests", "invalid-task-defaults", Duration.ofSeconds(60));
    assertThat(execution.getTaskRunList(), hasSize(1));
    assertThat(logs.stream().filter(logEntry -> logEntry.getMessage().contains("Unrecognized field \"invalid\"")).count(), greaterThan(0L));
}
Also used : Execution(io.kestra.core.models.executions.Execution) ArrayList(java.util.ArrayList) LogEntry(io.kestra.core.models.executions.LogEntry)

Example 100 with Execution

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

the class WorkerTest method workerTask.

private WorkerTask workerTask(String sleep) {
    Bash bash = Bash.builder().type(Bash.class.getName()).id("unit-test").commands(new String[] { "for i in $(seq 1 " + sleep + "); do echo $i; sleep 1; done" }).build();
    Flow flow = Flow.builder().id(IdUtils.create()).namespace("io.kestra.unit-test").tasks(Collections.singletonList(bash)).build();
    Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
    ResolvedTask resolvedTask = ResolvedTask.of(bash);
    return WorkerTask.builder().runContext(runContextFactory.of(ImmutableMap.of("key", "value"))).task(bash).taskRun(TaskRun.of(execution, resolvedTask)).build();
}
Also used : Execution(io.kestra.core.models.executions.Execution) ResolvedTask(io.kestra.core.models.tasks.ResolvedTask) Bash(io.kestra.core.tasks.scripts.Bash) Flow(io.kestra.core.models.flows.Flow)

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