Search in sources :

Example 21 with Execution

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

the class UriProviderTest method executionUrl.

@Test
void executionUrl() {
    Flow flow = TestsUtils.mockFlow();
    Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
    assertThat(uriProvider.executionUrl(execution).toString(), containsString("mysuperhost.com/subpath/ui"));
    assertThat(uriProvider.executionUrl(execution).toString(), containsString(flow.getNamespace() + "/" + flow.getId() + "/" + execution.getId()));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Flow(io.kestra.core.models.flows.Flow) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 22 with Execution

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

the class UriProviderTest method flowUrl.

@Test
void flowUrl() {
    Flow flow = TestsUtils.mockFlow();
    Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
    assertThat(uriProvider.executionUrl(execution).toString(), containsString("mysuperhost.com/subpath/ui"));
    assertThat(uriProvider.flowUrl(execution).toString(), containsString(flow.getNamespace() + "/" + flow.getId()));
    assertThat(uriProvider.executionUrl(execution).toString(), containsString("mysuperhost.com/subpath/ui"));
    assertThat(uriProvider.flowUrl(flow).toString(), containsString(flow.getNamespace() + "/" + flow.getId()));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Flow(io.kestra.core.models.flows.Flow) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 23 with Execution

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

the class ExecutionControllerTest method webhook.

@SuppressWarnings("unchecked")
@Test
void webhook() {
    Flow webhook = flowRepositoryInterface.findById(TESTS_FLOW_NS, "webhook").orElseThrow();
    String key = ((Webhook) webhook.getTriggers().get(0)).getKey();
    Execution execution = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key + "?name=john&age=12&age=13", ImmutableMap.of("a", 1, "b", true)), Execution.class);
    assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("body")).get("a"), is(1));
    assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("body")).get("b"), is(true));
    assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("parameters")).get("name"), is(List.of("john")));
    assertThat(((Map<String, List<Integer>>) execution.getTrigger().getVariables().get("parameters")).get("age"), containsInAnyOrder("12", "13"));
    execution = client.toBlocking().retrieve(HttpRequest.PUT("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key, Collections.singletonList(ImmutableMap.of("a", 1, "b", true))), Execution.class);
    assertThat(((List<Map<String, Object>>) execution.getTrigger().getVariables().get("body")).get(0).get("a"), is(1));
    assertThat(((List<Map<String, Object>>) execution.getTrigger().getVariables().get("body")).get(0).get("b"), is(true));
    execution = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key, "bla"), Execution.class);
    assertThat(execution.getTrigger().getVariables().get("body"), is("bla"));
    execution = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key), Execution.class);
    assertThat(execution.getTrigger().getVariables().get("body"), is(nullValue()));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Webhook(io.kestra.core.models.triggers.types.Webhook) Flow(io.kestra.core.models.flows.Flow) InputsTest(io.kestra.core.runners.InputsTest) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 24 with Execution

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

the class ExecutionControllerTest method triggerAndFollow.

@Test
void triggerAndFollow() {
    Execution result = triggerInputsFlowExecution();
    RxSseClient sseClient = embeddedServer.getApplicationContext().createBean(RxSseClient.class, embeddedServer.getURL());
    List<Event<Execution>> results = sseClient.eventStream("/api/v1/executions/" + result.getId() + "/follow", Execution.class).toList().blockingGet();
    assertThat(results.size(), is(greaterThan(0)));
    assertThat(results.get(results.size() - 1).getData().getState().getCurrent(), is(State.Type.SUCCESS));
}
Also used : Execution(io.kestra.core.models.executions.Execution) RxSseClient(io.micronaut.rxjava2.http.client.sse.RxSseClient) Event(io.micronaut.http.sse.Event) InputsTest(io.kestra.core.runners.InputsTest) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 25 with Execution

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

the class ExecutionControllerTest method restartFromTaskId.

@Test
void restartFromTaskId() throws Exception {
    final String flowId = "restart_with_inputs";
    final String referenceTaskId = "instant";
    // Run execution until it ends
    Execution parentExecution = runnerUtils.runOne(TESTS_FLOW_NS, flowId, null, (flow, execution1) -> runnerUtils.typedInputs(flow, execution1, inputs));
    Optional<Flow> flow = flowRepositoryInterface.findById(TESTS_FLOW_NS, flowId);
    assertThat(flow.isPresent(), is(true));
    // Run child execution starting from a specific task and wait until it finishes
    Execution finishedChildExecution = runnerUtils.awaitChildExecution(flow.get(), parentExecution, throwRunnable(() -> {
        Thread.sleep(100);
        Execution createdChidExec = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/" + parentExecution.getId() + "/replay?taskRunId=" + parentExecution.findTaskRunByTaskIdAndValue(referenceTaskId, List.of()).getId(), ImmutableMap.of()), Execution.class);
        assertThat(createdChidExec, notNullValue());
        assertThat(createdChidExec.getParentId(), is(parentExecution.getId()));
        assertThat(createdChidExec.getTaskRunList().size(), is(4));
        assertThat(createdChidExec.getState().getCurrent(), is(State.Type.RESTARTED));
        IntStream.range(0, 3).mapToObj(value -> createdChidExec.getTaskRunList().get(value)).forEach(taskRun -> assertThat(taskRun.getState().getCurrent(), is(State.Type.SUCCESS)));
        assertThat(createdChidExec.getTaskRunList().get(3).getState().getCurrent(), is(State.Type.RESTARTED));
        assertThat(createdChidExec.getTaskRunList().get(3).getAttempts().size(), is(1));
    }), Duration.ofSeconds(15));
    assertThat(finishedChildExecution, notNullValue());
    assertThat(finishedChildExecution.getParentId(), is(parentExecution.getId()));
    assertThat(finishedChildExecution.getTaskRunList().size(), is(5));
    finishedChildExecution.getTaskRunList().stream().map(TaskRun::getState).forEach(state -> assertThat(state.getCurrent(), is(State.Type.SUCCESS)));
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) TaskRun(io.kestra.core.models.executions.TaskRun) java.util(java.util) InputsTest(io.kestra.core.runners.InputsTest) QueueInterface(io.kestra.core.queues.QueueInterface) TimeoutException(java.util.concurrent.TimeoutException) Client(io.micronaut.http.client.annotation.Client) RxHttpClient(io.micronaut.rxjava2.http.client.RxHttpClient) State(io.kestra.core.models.flows.State) IdUtils(io.kestra.core.utils.IdUtils) Event(io.micronaut.http.sse.Event) RxSseClient(io.micronaut.rxjava2.http.client.sse.RxSseClient) HttpStatus(io.micronaut.http.HttpStatus) MediaType(io.micronaut.http.MediaType) Duration(java.time.Duration) HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) Argument(io.micronaut.core.type.Argument) HttpRequest(io.micronaut.http.HttpRequest) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Webhook(io.kestra.core.models.triggers.types.Webhook) MultipartBody(io.micronaut.http.client.multipart.MultipartBody) PagedResults(io.kestra.webserver.responses.PagedResults) ImmutableMap(com.google.common.collect.ImmutableMap) QueueFactoryInterface(io.kestra.core.queues.QueueFactoryInterface) Rethrow.throwRunnable(io.kestra.core.utils.Rethrow.throwRunnable) Matchers(org.hamcrest.Matchers) Execution(io.kestra.core.models.executions.Execution) File(java.io.File) Test(org.junit.jupiter.api.Test) EmbeddedServer(io.micronaut.runtime.server.EmbeddedServer) FileMetas(io.kestra.core.models.storage.FileMetas) Flow(io.kestra.core.models.flows.Flow) 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) InputsTest(io.kestra.core.runners.InputsTest) 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