Search in sources :

Example 1 with CollectingUnitOfWorkFactory

use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory 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 2 with CollectingUnitOfWorkFactory

use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory 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)

Example 3 with CollectingUnitOfWorkFactory

use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.

the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstanceAndCance.

@Test
public void testScheduleJobsForProcessInstanceAndCance() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    lenient().when(processes.processById("processId_1")).then(i -> {
        return process;
    });
    lenient().when(processes.processIds()).then(i -> {
        return Collections.singletonList("processId_1");
    });
    lenient().when(process.instances()).then(i -> {
        latch.countDown();
        return Mockito.mock(ProcessInstances.class);
    });
    FileSystemBasedJobService jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
    ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(123, DurationExpirationTime.after(500), "processInstanceId", "processId", "1");
    jobs.scheduleProcessInstanceJob(processInstanceJobDescription);
    jobs.cancelJob(processInstanceJobDescription.id());
    boolean achieved = latch.await(1, TimeUnit.SECONDS);
    assertThat(achieved).isFalse();
    verify(processes, times(0)).processById(eq("processId"));
}
Also used : CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) ProcessInstanceJobDescription(io.automatiko.engine.api.jobs.ProcessInstanceJobDescription) FileSystemBasedJobService(io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) Test(org.junit.jupiter.api.Test)

Example 4 with CollectingUnitOfWorkFactory

use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.

the class BaseProcessInstanceManagementResourceTest method setUp.

@BeforeEach
void setUp() {
    Map<String, Process<?>> processes = Mockito.mock(Map.class);
    lenient().when(processes.get(anyString())).thenReturn(process);
    lenient().when(process.instances()).thenReturn(instances);
    lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance));
    lenient().when(instances.findById(anyString(), anyInt(), any())).thenReturn(Optional.of(processInstance));
    lenient().when(processInstance.errors()).thenReturn(Optional.of(errors));
    lenient().when(processInstance.variables()).thenReturn(variables);
    lenient().when(processInstance.id()).thenReturn(PROCESS_INSTANCE_ID);
    lenient().when(processInstance.status()).thenReturn(ProcessInstance.STATE_ERROR);
    lenient().when(errors.failedNodeIds()).thenReturn(NODE_ID_ERROR);
    lenient().when(errors.errorMessages()).thenReturn("Test error message");
    lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    tested = spy(new BaseProcessInstanceManagementResource(processes, application) {

        @Override
        protected Object buildOkResponse(Object body) {
            return body;
        }

        @Override
        protected Object badRequestResponse(String message) {
            return message;
        }

        @Override
        protected Object notFoundResponse(String message) {
            return message;
        }

        @Override
        public Object getInstanceInError(String processId, String processInstanceId, String user, List groups) {
            return null;
        }

        @Override
        public Object getWorkItemsInProcessInstance(String processId, String processInstanceId, String user, List groups) {
            return null;
        }

        @Override
        public Object retriggerInstanceInError(String processId, String processInstanceId, String user, List groups) {
            return null;
        }

        @Override
        public Object skipInstanceInError(String processId, String processInstanceId, String user, List groups) {
            return null;
        }

        @Override
        public Object triggerNodeInstanceId(String processId, String processInstanceId, String nodeId, String user, List groups) {
            return null;
        }

        @Override
        public Object retriggerNodeInstanceId(String processId, String processInstanceId, String nodeInstanceId, String user, List groups) {
            return null;
        }

        @Override
        public Object cancelNodeInstanceId(String processId, String processInstanceId, String nodeInstanceId, String user, List groups) {
            return null;
        }

        @Override
        public Object cancelProcessInstanceId(String processId, String processInstanceId, String status, String user, List groups) {
            return null;
        }

        @Override
        public Object retriggerInstanceInErrorByErrorId(String processId, String processInstanceId, String errord, String user, List groups) {
            return null;
        }

        @Override
        public Object skipInstanceInErrorByErrorId(String processId, String processInstanceId, String errorId, String user, List groups) {
            return null;
        }
    });
}
Also used : CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) Process(io.automatiko.engine.api.workflow.Process) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with CollectingUnitOfWorkFactory

use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.

the class ServerlessProcess method processConfig.

public static ProcessConfig processConfig() {
    DefaultWorkItemHandlerConfig workItemHandlerConfig = new DefaultWorkItemHandlerConfig();
    DefaultProcessEventListenerConfig processEventListenerConfig = new DefaultProcessEventListenerConfig();
    return new StaticProcessConfig(workItemHandlerConfig, processEventListenerConfig, new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
}
Also used : StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) DefaultVariableInitializer(io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer) DefaultWorkItemHandlerConfig(io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig)

Aggregations

CollectingUnitOfWorkFactory (io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory)10 DefaultUnitOfWorkManager (io.automatiko.engine.services.uow.DefaultUnitOfWorkManager)10 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)5 StaticProcessConfig (io.automatiko.engine.workflow.StaticProcessConfig)5 DefaultVariableInitializer (io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Test (org.junit.jupiter.api.Test)4 FileSystemBasedJobService (io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService)3 ProcessInstanceJobDescription (io.automatiko.engine.api.jobs.ProcessInstanceJobDescription)3 DefaultWorkItemHandlerConfig (io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Process (io.automatiko.engine.api.workflow.Process)2 ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)2 CachedWorkItemHandlerConfig (io.automatiko.engine.workflow.CachedWorkItemHandlerConfig)2 HumanTaskWorkItemHandler (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemHandler)2 List (java.util.List)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 PredictionAwareHumanTaskLifeCycle (io.automatiko.engine.addons.predictions.api.PredictionAwareHumanTaskLifeCycle)1 Application (io.automatiko.engine.api.Application)1 IdentitySupplier (io.automatiko.engine.api.auth.IdentitySupplier)1