use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.
the class LambdaSubProcessNodeInstance method internalTrigger.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void internalTrigger(KogitoNodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getStringId()) == null) {
return;
}
if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A SubProcess node only accepts default incoming connections!");
}
KogitoProcessContextImpl context = ContextFactory.fromNode(this);
SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
Object o = subProcessFactory.bind(context);
org.kie.kogito.process.ProcessInstance<?> processInstance = subProcessFactory.createInstance(o);
org.kie.api.runtime.process.ProcessInstance pi = ((AbstractProcessInstance<?>) processInstance).internalGetProcessInstance();
((ProcessInstanceImpl) pi).setMetaData("ParentProcessInstanceId", getProcessInstance().getStringId());
((ProcessInstanceImpl) pi).setMetaData("ParentNodeInstanceId", getUniqueId());
((ProcessInstanceImpl) pi).setMetaData("ParentNodeId", getSubProcessNode().getUniqueId());
((ProcessInstanceImpl) pi).setParentProcessInstanceId(getProcessInstance().getStringId());
((ProcessInstanceImpl) pi).setRootProcessInstanceId(StringUtils.isEmpty(getProcessInstance().getRootProcessInstanceId()) ? getProcessInstance().getStringId() : getProcessInstance().getRootProcessInstanceId());
((ProcessInstanceImpl) pi).setRootProcessId(StringUtils.isEmpty(getProcessInstance().getRootProcessId()) ? getProcessInstance().getProcessId() : getProcessInstance().getRootProcessId());
((ProcessInstanceImpl) pi).setSignalCompletion(getSubProcessNode().isWaitForCompletion());
processInstance.start();
this.processInstanceId = processInstance.id();
this.asyncWaitingNodeInstance = hasAsyncNodeInstance(pi);
subProcessFactory.unbind(context, processInstance.variables());
if (!getSubProcessNode().isWaitForCompletion()) {
triggerCompleted();
} else if (processInstance.status() == ProcessInstance.STATE_COMPLETED || processInstance.status() == ProcessInstance.STATE_ABORTED) {
processInstanceCompleted((ProcessInstanceImpl) pi);
} else {
addProcessListener();
}
}
use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.
the class KafkaProcessInstancesTest method testProcessInstancesCreateNotActive.
@Test
public void testProcessInstancesCreateNotActive() {
AbstractProcessInstance instance = mock(AbstractProcessInstance.class);
when(instance.status()).thenReturn(ProcessInstance.STATE_COMPLETED);
instances.create(id, instance);
verify(producer, never()).send(any(), any());
}
use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.
the class KafkaProcessInstancesTest method testProcessInstancesUpdate.
@Test
public void testProcessInstancesUpdate() {
doReturn(mock(Future.class)).when(producer).send(any());
AbstractProcessInstance instance = mock(AbstractProcessInstance.class);
doReturn(new byte[] {}).when(marshaller).marshallProcessInstance(instance);
when(instance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
instances.update(id, instance);
ArgumentCaptor<ProducerRecord> captor = ArgumentCaptor.forClass(ProducerRecord.class);
verify(producer).send(captor.capture());
assertThat(captor.getValue().value()).isEqualTo(new byte[] {});
assertThat(captor.getValue().key()).isEqualTo(id);
assertThat(captor.getValue().topic()).isEqualTo(topicName(process.id()));
verify(instance).internalRemoveProcessInstance(any());
verify(marshaller).createdReloadFunction(any());
}
use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.
the class KafkaProcessInstancesTest method testProcessInstancesCreateDuplicate.
@Test
public void testProcessInstancesCreateDuplicate() {
when(store.get(id)).thenReturn(new byte[] {});
AbstractProcessInstance instance = mock(AbstractProcessInstance.class);
when(instance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
assertThatExceptionOfType(ProcessInstanceDuplicatedException.class).isThrownBy(() -> instances.create(id, instance));
}
use of org.kie.kogito.process.impl.AbstractProcessInstance in project kogito-runtimes by kiegroup.
the class CacheProcessInstancesWithLockIT method testBasic.
@Test
public void testBasic() {
BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
CacheProcessInstances pi = new CacheProcessInstances(process, cacheManager, null, true);
assertNotNull(pi);
WorkflowProcessInstance createPi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
createPi.setId(TEST_ID);
createPi.setStartDate(new Date());
AbstractProcessInstance<?> mockCreatePi = mock(AbstractProcessInstance.class);
mockCreatePi.setVersion(1L);
when(mockCreatePi.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
when(mockCreatePi.internalGetProcessInstance()).thenReturn(createPi);
when(mockCreatePi.id()).thenReturn(TEST_ID);
pi.create(TEST_ID, mockCreatePi);
assertThat(pi.size()).isOne();
assertTrue(pi.exists(TEST_ID));
WorkflowProcessInstance updatePi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
updatePi.setId(TEST_ID);
updatePi.setStartDate(new Date());
AbstractProcessInstance<?> mockUpdatePi = mock(AbstractProcessInstance.class);
when(mockUpdatePi.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
when(mockUpdatePi.internalGetProcessInstance()).thenReturn(updatePi);
when(mockUpdatePi.id()).thenReturn(TEST_ID);
try {
pi.update(TEST_ID, mockUpdatePi);
} catch (RuntimeException e) {
assertThat(e.getMessage()).isEqualTo("The document with ID: " + TEST_ID + " was updated or deleted by other request.");
}
pi.remove(TEST_ID);
assertFalse(pi.exists(TEST_ID));
}
Aggregations