Search in sources :

Example 11 with DefaultProcessEventListenerConfig

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

the class EmbeddedSubProcessTest method testEmbeddedSubprocessServiceProcessTaskWithRetry.

@Test
@Timeout(unit = TimeUnit.SECONDS, value = 10)
public void testEmbeddedSubprocessServiceProcessTaskWithRetry() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/EmbeddedSubprocessWihErrorRetry.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Error happened", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("subprocessRetry");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    listener.waitTillCompleted();
    assertThat(processInstance.startDate()).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("name", "ErrorData");
    assertThat(result.toMap().get("name")).isNotNull().isEqualTo("john");
    assertThat(result.toMap().get("ErrorData")).isNotNull().isInstanceOf(WorkItemExecutionError.class);
    assertThat(((WorkItemExecutionError) result.toMap().get("ErrorData")).getErrorCode()).isEqualTo("500");
}
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) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 12 with DefaultProcessEventListenerConfig

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

the class EventSubProcessTest method testEventErrorSubProcessDefaultHander.

@Test
public void testEventErrorSubProcessDefaultHander() throws Exception {
    Application app = generateCodeProcessesOnly("event-subprocess/EventSubprocessErrorDefault.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("end-sub", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("EventSubprocessError_1");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    listener.waitTillCompleted(5000);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
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 13 with DefaultProcessEventListenerConfig

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

the class EventSubProcessTest method testEventTimerCycleISOSubProcess.

@Test
public void testEventTimerCycleISOSubProcess() throws Exception {
    Application app = generateCodeProcessesOnly("event-subprocess/EventSubprocessTimerCycle.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("start-sub", 2);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("EventSubprocessTimer_1");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
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 14 with DefaultProcessEventListenerConfig

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

the class FileSystemProcessInstancesTest method testBasicFlowControlledByUnitOfWork.

@Test
void testBasicFlowControlledByUnitOfWork() {
    UnitOfWorkManager uowManager = new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory());
    ProcessConfig config = new StaticProcessConfig(new DefaultWorkItemHandlerConfig(), new DefaultProcessEventListenerConfig(), uowManager, null, new DefaultVariableInitializer(), new FileSystemProcessInstancesFactory());
    BpmnProcess process = createProcess(config, "BPMN2-UserTask.bpmn2");
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    UnitOfWork uow = uowManager.newUnitOfWork();
    uow.start();
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    assertThat(process.instances().values(1, 10)).hasSize(1);
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(2)).create(any(), any());
    verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
    verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    assertThat(processInstance.description()).isEqualTo("User Task");
    WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
    uow = uowManager.newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    uow.end();
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
    fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(1)).remove(any(), any());
    assertThat(fileSystemBasedStorage.size()).isZero();
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) DefaultVariableInitializer(io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer) WorkItem(io.automatiko.engine.api.workflow.WorkItem) DefaultWorkItemHandlerConfig(io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) UnitOfWorkManager(io.automatiko.engine.api.uow.UnitOfWorkManager) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 15 with DefaultProcessEventListenerConfig

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

the class SmileRandomForestPredictionTest method configure.

@BeforeEach
public void configure() {
    final RandomForestConfiguration configuration = new RandomForestConfiguration();
    final Map<String, AttributeType> inputFeatures = new HashMap<>();
    inputFeatures.put("ActorId", AttributeType.NOMINAL);
    configuration.setInputFeatures(inputFeatures);
    configuration.setOutcomeName("output");
    configuration.setOutcomeType(AttributeType.NOMINAL);
    configuration.setConfidenceThreshold(0.7);
    configuration.setNumTrees(1);
    predictionService = new SmileRandomForest(configuration);
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    wiConfig.register("Human Task", new HumanTaskWorkItemHandler(new PredictionAwareHumanTaskLifeCycle(predictionService)));
    config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
    for (int i = 0; i < 10; i++) {
        predictionService.train(null, Collections.singletonMap("ActorId", "john"), Collections.singletonMap("output", "predicted value"));
    }
    for (int i = 0; i < 8; i++) {
        predictionService.train(null, Collections.singletonMap("ActorId", "mary"), Collections.singletonMap("output", "value"));
    }
}
Also used : HumanTaskWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemHandler) PredictionAwareHumanTaskLifeCycle(io.automatiko.engine.addons.predictions.api.PredictionAwareHumanTaskLifeCycle) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) HashMap(java.util.HashMap) DefaultVariableInitializer(io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer) CachedWorkItemHandlerConfig(io.automatiko.engine.workflow.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

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