use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class SchedulerConditionTest method schedule.
@Test
void schedule() throws Exception {
// mock flow listeners
MemoryFlowListeners flowListenersServiceSpy = spy(this.flowListenersService);
SchedulerExecutionStateInterface executionRepositorySpy = spy(this.executionState);
CountDownLatch queueCount = new CountDownLatch(4);
Flow flow = createScheduleFlow();
triggerState.save(Trigger.builder().namespace(flow.getNamespace()).flowId(flow.getId()).flowRevision(flow.getRevision()).triggerId("hourly").date(ZonedDateTime.parse("2021-09-06T02:00:00+01:00[Europe/Paris]")).build());
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(executionRepositorySpy).findById(any());
// scheduler
try (AbstractScheduler scheduler = new DefaultScheduler(applicationContext, flowListenersServiceSpy, executionRepositorySpy, triggerState)) {
// wait for execution
executionQueue.receive(SchedulerConditionTest.class, execution -> {
if (execution.getState().getCurrent() == State.Type.CREATED) {
executionQueue.emit(execution.withState(State.Type.SUCCESS));
queueCount.countDown();
if (queueCount.getCount() == 0) {
assertThat((ZonedDateTime) execution.getTrigger().getVariables().get("date"), is(ZonedDateTime.parse("2022-01-03T00:00:00+01:00")));
}
}
assertThat(execution.getFlowId(), is(flow.getId()));
});
scheduler.run();
queueCount.await(1, TimeUnit.MINUTES);
assertThat(queueCount.getCount(), is(0L));
}
}
use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class SchedulerScheduleTest method schedule.
@Test
void schedule() throws Exception {
// mock flow listeners
MemoryFlowListeners flowListenersServiceSpy = spy(this.flowListenersService);
SchedulerExecutionStateInterface executionRepositorySpy = spy(this.executionState);
CountDownLatch queueCount = new CountDownLatch(5);
Flow flow = createScheduleFlow();
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(executionRepositorySpy).findById(any());
// scheduler
try (AbstractScheduler scheduler = new DefaultScheduler(applicationContext, flowListenersServiceSpy, executionRepositorySpy, triggerState)) {
// wait for execution
executionQueue.receive(SchedulerScheduleTest.class, execution -> {
assertThat(execution.getInputs().get("testInputs"), is("test-inputs"));
queueCount.countDown();
if (execution.getState().getCurrent() == State.Type.CREATED) {
executionQueue.emit(execution.withState(State.Type.SUCCESS));
}
assertThat(execution.getFlowId(), is(flow.getId()));
});
scheduler.run();
queueCount.await(1, TimeUnit.MINUTES);
assertThat(queueCount.getCount(), is(0L));
}
}
use of io.kestra.core.models.flows.State 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;
}
}
use of io.kestra.core.models.flows.State 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)));
}
use of io.kestra.core.models.flows.State in project kestra by kestra-io.
the class ExecutionTest method hasTaskRunJoinableFailedExecutionFromExecutor.
@Test
void hasTaskRunJoinableFailedExecutionFromExecutor() {
Execution execution = Execution.builder().taskRunList(Collections.singletonList(TASK_RUN.state(new State(State.Type.FAILED, new State().withState(State.Type.RUNNING))).build())).build();
assertThat(execution.hasTaskRunJoinable(TASK_RUN.state(new State(State.Type.RUNNING, new State())).build()), is(false));
}
Aggregations