Search in sources :

Example 1 with DefaultProcessEventListenerConfig

use of io.automatiko.engine.workflow.DefaultProcessEventListenerConfig in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testSingleInjectWithExecTimeoutWorkflow.

@ParameterizedTest
@ValueSource(strings = { "serverless/single-inject-state-timeout.sw.json" })
public void testSingleInjectWithExecTimeoutWorkflow(String processLocation) throws Exception {
    Application app = generateCodeProcessesOnly(processLocation);
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Execution timeout :: end", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("singleinject_1_0");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("name");
    JsonNode dataOut = (JsonNode) result.toMap().get("name");
    assertThat(dataOut.textValue()).isEqualTo("john");
    boolean completed = listener.waitTillCompleted(3000000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("name");
    dataOut = (JsonNode) result.toMap().get("name");
    assertThat(dataOut.textValue()).isEqualTo("anothernotset");
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DefaultProcessEventListenerConfig

use of io.automatiko.engine.workflow.DefaultProcessEventListenerConfig in project automatiko-engine by automatiko-io.

the class TimerEventTest method testBoundaryDurationTimerEventOnTask.

@Test
public void testBoundaryDurationTimerEventOnTask() throws Exception {
    Application app = generateCodeProcessesOnly("timer/TimerBoundaryEventDurationISOOnTask.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("TimerBoundaryEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultProcessEventListenerConfig

use of io.automatiko.engine.workflow.DefaultProcessEventListenerConfig in project automatiko-engine by automatiko-io.

the class TimerEventTest method testStartTimerEvent.

@Test
public void testStartTimerEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerDuration.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(1, 10);
    if (instances.size() == 0) {
        Thread.sleep(1000);
        instances = p.instances().values(1, 10);
    }
    assertThat(instances).hasSize(1);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(0);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultProcessEventListenerConfig

use of io.automatiko.engine.workflow.DefaultProcessEventListenerConfig in project automatiko-engine by automatiko-io.

the class TimerEventTest method testBoundaryCycleTimerEventOnTask.

@Test
public void testBoundaryCycleTimerEventOnTask() throws Exception {
    Application app = generateCodeProcessesOnly("timer/TimerBoundaryEventCycleISOOnTask.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("TimerBoundaryEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultProcessEventListenerConfig

use of io.automatiko.engine.workflow.DefaultProcessEventListenerConfig in project automatiko-engine by automatiko-io.

the class TimerEventTest method testStartTimerEventTimeCycleCron.

@Test
public void testStartTimerEventTimeCycleCron() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerCycleCron.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 2);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(2);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // deactivate to cancel timer, so there should be no more timers fired
    p.deactivate();
    // reset the listener to make sure nothing more is triggered
    listener.reset(1);
    completed = listener.waitTillCompleted(3000);
    // same amount of instances should be active as before deactivation
    instances = p.instances().values(1, 10);
    // clean up by aborting all instances
    instances.forEach(i -> ((ProcessInstance<?>) i).abort());
    instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(0);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)31 Application (io.automatiko.engine.api.Application)26 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)26 Test (org.junit.jupiter.api.Test)26 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)25 Model (io.automatiko.engine.api.Model)23 HashMap (java.util.HashMap)23 Timeout (org.junit.jupiter.api.Timeout)7 CollectingUnitOfWorkFactory (io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory)5 DefaultUnitOfWorkManager (io.automatiko.engine.services.uow.DefaultUnitOfWorkManager)5 StaticProcessConfig (io.automatiko.engine.workflow.StaticProcessConfig)5 DefaultVariableInitializer (io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer)5 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)4 DefaultWorkItemHandlerConfig (io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig)3 ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)2 WorkItem (io.automatiko.engine.api.workflow.WorkItem)2 CachedWorkItemHandlerConfig (io.automatiko.engine.workflow.CachedWorkItemHandlerConfig)2 HumanTaskWorkItemHandler (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemHandler)2 OffsetDateTime (java.time.OffsetDateTime)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2