use of io.kestra.runner.memory.MemoryFlowListeners 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.runner.memory.MemoryFlowListeners 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.runner.memory.MemoryFlowListeners 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;
}
}
Aggregations