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();
}
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"));
}
}
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"));
}
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;
}
});
}
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);
}
Aggregations