use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowTest method testParallelExecWorkflow.
@Test
public void testParallelExecWorkflow() throws Exception {
Application app = generateCodeProcessesOnly("serverless/parallel-state.sw.json", "serverless/parallel-state-branch1.sw.json", "serverless/parallel-state-branch2.sw.json");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("parallelworkflow_1_0");
Model m = p.createModel();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).containsKeys("branch1data", "branch2data");
Map<String, Object> dataOut = result.toMap();
assertThat(((JsonNode) dataOut.get("branch1data")).textValue()).isEqualTo("testBranch1Data");
assertThat(((JsonNode) dataOut.get("branch2data")).textValue()).isEqualTo("testBranch2Data");
}
use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowTest method testCompensationWorkflow.
@Disabled
@ParameterizedTest
@ValueSource(strings = { "serverless/compensation.sw.json" })
public void testCompensationWorkflow(String processLocation) throws Exception {
Application app = generateCodeProcessesOnly(processLocation);
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("compensationworkflow");
Model m = p.createModel();
String jsonParamStr = "{\"x\": \"0\"}";
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonParamObj = mapper.readTree(jsonParamStr);
m.fromMap(toMap(jsonParamObj));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).containsKeys("x");
JsonNode dataOut = (JsonNode) result.toMap().get("x");
assertThat(dataOut.textValue()).isEqualTo("2");
}
use of io.automatiko.engine.api.Model 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");
}
use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowTest method testParallelExecWorkflowNumCompleted.
@Disabled
@Test
public void testParallelExecWorkflowNumCompleted() throws Exception {
Application app = generateCodeProcessesOnly("serverless/parallel-state-num-completed.sw.json", "serverless/parallel-state-branch1.sw.json", "serverless/parallel-state-branch2.sw.json");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("parallelworkflow_1_0");
Model m = p.createModel();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).containsKeys("branch2data");
Map<String, Object> dataOut = result.toMap();
assertThat(((JsonNode) dataOut.get("branch2data")).textValue()).isEqualTo("testBranch2Data");
}
use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowTest method testLogVarWorkflow.
@ParameterizedTest
@ValueSource(strings = { "serverless/logvar.sw.json" })
public void testLogVarWorkflow(String processLocation) throws Exception {
Application app = generateCodeProcessesOnly(processLocation);
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("logvar_1_0");
Model m = p.createModel();
String jsonParamStr = "{\"name\": \"john\"}";
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonParamObj = mapper.readTree(jsonParamStr);
m.fromMap(toMap(jsonParamObj));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).containsKeys("name");
JsonNode dataOut = (JsonNode) result.toMap().get("name");
assertThat(dataOut.textValue()).isEqualTo("john");
}
Aggregations