Search in sources :

Example 6 with DefaultUnitOfWorkManager

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

the class JbpmBpmn2TestCase method config.

protected ProcessConfig config(List<WorkItemHandler> handlers, List<ProcessEventListener> listeners) {
    DefaultWorkItemHandlerConfig handlerConfig = new DefaultWorkItemHandlerConfig();
    handlers.forEach(h -> handlerConfig.register(h.getName(), h));
    DefaultProcessEventListenerConfig listenerConfig = new DefaultProcessEventListenerConfig();
    listeners.forEach(h -> listenerConfig.register(h));
    ProcessConfig config = new StaticProcessConfig(handlerConfig, listenerConfig, new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
    return config;
}
Also used : StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) 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)

Example 7 with DefaultUnitOfWorkManager

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

the class PredictionAwareHumanTaskLifeCycleTest method configure.

@BeforeEach
public void configure() {
    predictNow = new AtomicBoolean(false);
    trainedTasks = new ArrayList<>();
    predictionService = new PredictionService() {

        @Override
        public void train(io.automatiko.engine.api.runtime.process.WorkItem task, Map<String, Object> inputData, Map<String, Object> outputData) {
            trainedTasks.add(task.getId());
        }

        @Override
        public PredictionOutcome predict(io.automatiko.engine.api.runtime.process.WorkItem task, Map<String, Object> inputData) {
            if (predictNow.get()) {
                return new PredictionOutcome(95, 75, Collections.singletonMap("output", "predicted value"));
            }
            return new PredictionOutcome();
        }

        @Override
        public String getIdentifier() {
            return "test";
        }
    };
    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);
}
Also used : HumanTaskWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemHandler) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) DefaultVariableInitializer(io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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 8 with DefaultUnitOfWorkManager

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

the class ProcessInstanceManagementResourceTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@BeforeEach
public void setup() {
    responseBuilder = mock(ResponseBuilder.class);
    Response response = mock(Response.class);
    when((runtimeDelegate).createResponseBuilder()).thenReturn(responseBuilder);
    lenient().when((responseBuilder).status(any(StatusType.class))).thenReturn(responseBuilder);
    lenient().when((responseBuilder).entity(any())).thenReturn(responseBuilder);
    lenient().when((responseBuilder).build()).thenReturn(response);
    application = mock(Application.class);
    Map<String, Process<?>> processes = Mockito.mock(Map.class);
    Process process = mock(Process.class);
    ProcessInstances instances = mock(ProcessInstances.class);
    processInstance = mock(ProcessInstance.class);
    errors = mock(ProcessErrors.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(), eq(5), any())).thenReturn(Optional.of(processInstance));
    lenient().when(processInstance.errors()).thenReturn(Optional.of(errors));
    lenient().when(processInstance.id()).thenReturn("abc-def");
    lenient().when(processInstance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    lenient().when(errors.failedNodeIds()).thenReturn("xxxxx");
    lenient().when(errors.errorMessages()).thenReturn("Test error message");
    lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    IdentitySupplier identitySupplier = new IdentitySupplier() {

        @Override
        public IdentityProvider buildIdentityProvider(String user, List<String> roles) {
            return new StaticIdentityProvider("test");
        }
    };
    resource = spy(new ProcessInstanceManagementResource(processes, application, identitySupplier));
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) Process(io.automatiko.engine.api.workflow.Process) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Response(javax.ws.rs.core.Response) ProcessInstances(io.automatiko.engine.api.workflow.ProcessInstances) ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) StatusType(javax.ws.rs.core.Response.StatusType) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) IdentitySupplier(io.automatiko.engine.api.auth.IdentitySupplier) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) List(java.util.List) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Application(io.automatiko.engine.api.Application) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with DefaultUnitOfWorkManager

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

the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstanceReload.

@Test
public void testScheduleJobsForProcessInstanceReload() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    when(processes.processById("processId_1")).then(i -> {
        return process;
    });
    when(processes.processIds()).then(i -> {
        return Collections.singletonList("processId_1");
    });
    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(100), "processInstanceId", "processId", "1");
    jobs.scheduleProcessInstanceJob(processInstanceJobDescription);
    jobs.shutown(null);
    jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
    jobs.scheduleOnLoad(null);
    boolean achieved = latch.await(2, TimeUnit.SECONDS);
    assertThat(achieved).isTrue();
}
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 10 with DefaultUnitOfWorkManager

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

the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstance.

@Test
public void testScheduleJobsForProcessInstance() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    when(processes.processById("processId_1")).then(i -> {
        return process;
    });
    when(processes.processIds()).then(i -> {
        return Collections.singletonList("processId_1");
    });
    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);
    boolean achieved = latch.await(2, TimeUnit.SECONDS);
    assertThat(achieved).isTrue();
    verify(process, times(1)).instances();
}
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)

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