use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.
the class EventImplTest method setup.
@BeforeEach
void setup() {
application = mock(Application.class);
when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
process = mock(Process.class);
processInstances = mock(ProcessInstances.class);
processInstance = mock(ProcessInstance.class);
when(process.instances()).thenReturn(processInstances);
when(processInstances.findById(Mockito.anyString())).thenReturn(Optional.of(processInstance));
when(process.createInstance(Mockito.any(DummyModel.class))).thenReturn(processInstance);
processService = mock(ProcessService.class);
executor = Executors.newSingleThreadExecutor();
}
use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.
the class ProcessInstanceMarshallerService method unmarshallProcessInstance.
public ProcessInstance<?> unmarshallProcessInstance(byte[] data, Process<?> process, boolean readOnly) {
try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) {
MarshallerReaderContext context = processInstanceMarshallerFactory.newReaderContext(bais);
context.set(MarshallerContextName.MARSHALLER_PROCESS, process);
context.set(MarshallerContextName.MARSHALLER_INSTANCE_READ_ONLY, readOnly);
setupEnvironment(context);
org.kie.kogito.serialization.process.ProcessInstanceMarshaller marshaller = processInstanceMarshallerFactory.newKogitoProcessInstanceMarshaller();
return (ProcessInstance<?>) marshaller.readProcessInstance(context);
} catch (Exception e) {
throw new ProcessInstanceMarshallerException("Error while unmarshalling process instance", e);
}
}
use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.
the class PublishEventIT method testProcessWithMilestoneEvents.
@Test
public void testProcessWithMilestoneEvents() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.get(Processes.class).processById("TestCase.SimpleMilestone");
ProcessInstance<?> processInstance = p.createInstance(p.createModel());
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
uow.end();
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
DataEvent<?> event = events.get(0);
assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
assertThat(processDataEvent.getKogitoProcessinstanceId()).isNotNull();
assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("TestCase.SimpleMilestone");
assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/SimpleMilestone");
Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.
the class TimerEventIT method testStartTimerEventTimeCycle.
@Test
void testStartTimerEventTimeCycle() throws Exception {
Application app = generateCodeProcessesOnly("timer/StartTimerCycle.bpmn2");
assertThat(app).isNotNull();
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 2);
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
Process<? extends Model> p = app.get(Processes.class).processById("defaultPackage.TimerProcess");
// activate to schedule timers
p.activate();
boolean completed = listener.waitTillCompleted(5000);
assertThat(completed).isTrue();
Collection<?> instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
assertThat(instances).hasSize(2);
ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
assertThat(processInstance).isNotNull();
assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
// deactivate to cancel timer, so there should be no more timers fired
p.deactivate();
// reset the listener to make sure nothing more is triggered
listener.reset(1);
completed = listener.waitTillCompleted(3000);
assertThat(completed).isFalse();
// same amount of instances should be active as before deactivation
instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
assertThat(instances).hasSize(2);
// clean up by aborting all instances
instances.forEach(i -> ((ProcessInstance<?>) i).abort());
assertThat(p.instances().size()).isZero();
}
use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.
the class TimerEventIT method testStartTimerEvent.
@Test
void testStartTimerEvent() throws Exception {
Application app = generateCodeProcessesOnly("timer/StartTimerDuration.bpmn2");
assertThat(app).isNotNull();
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 1);
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
Process<? extends Model> p = app.get(Processes.class).processById("defaultPackage.TimerProcess");
// activate to schedule timers
p.activate();
boolean completed = listener.waitTillCompleted(5000);
assertThat(completed).isTrue();
Collection<?> instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
assertThat(instances).hasSize(1);
ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
assertThat(processInstance).isNotNull();
assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ABORTED);
assertThat(p.instances().size()).isZero();
}
Aggregations