Search in sources :

Example 1 with BpmnProcessInstance

use of org.kie.kogito.process.bpmn2.BpmnProcessInstance in project kogito-runtimes by kiegroup.

the class AbstractProcessInstancesIT method testRemove.

@Test
public void testRemove() {
    var factory = new TestProcessInstancesFactory(getDataSource(), true);
    BpmnProcess process = createProcess(factory, "BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
    assertEquals(1L, instanceOne.version());
    assertEquals(1L, instanceTwo.version());
    processInstances.remove(instanceOne.id());
    try {
        String id = instanceTwo.id();
        processInstances.remove(id);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was deleted by other request.");
    }
}
Also used : JDBCProcessInstances(org.kie.kogito.persistence.jdbc.JDBCProcessInstances) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 2 with BpmnProcessInstance

use of org.kie.kogito.process.bpmn2.BpmnProcessInstance in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesWithLockIT method testRemove.

@Test
public void testRemove() {
    MongoDBProcessInstancesFactory factory = new MongoDBProcessInstancesFactory(getMongoClient());
    BpmnProcess process = createProcess(factory);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    MongoDBProcessInstances<?> processInstances = new MongoDBProcessInstances<>(getMongoClient(), process, DB_NAME, factory.transactionManager(), true);
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
    assertEquals(1L, instanceOne.version());
    assertEquals(1L, instanceTwo.version());
    processInstances.remove(instanceOne.id());
    try {
        String id = instanceTwo.id();
        processInstances.remove(id);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was deleted by other request.");
    }
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 3 with BpmnProcessInstance

use of org.kie.kogito.process.bpmn2.BpmnProcessInstance in project kogito-runtimes by kiegroup.

the class PostgreProcessInstancesWithLockIT method testUpdate.

@Test
public void testUpdate() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    PostgreProcessInstances processInstances = (PostgreProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
    assertEquals(1L, instanceOne.version());
    assertEquals(1L, instanceTwo.version());
    instanceOne.updateVariables(BpmnVariables.create(Collections.singletonMap("s", "test")));
    try {
        BpmnVariables testvar = BpmnVariables.create(Collections.singletonMap("ss", "test"));
        instanceTwo.updateVariables(testvar);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("Error updating process instance " + instanceOne.id());
    }
    foundOne = processInstances.findById(processInstance.id());
    instanceOne = (BpmnProcessInstance) foundOne.get();
    assertEquals(2L, instanceOne.version());
    processInstances.remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) PostgreProcessInstances(org.kie.kogito.persistence.postgresql.PostgreProcessInstances) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 4 with BpmnProcessInstance

use of org.kie.kogito.process.bpmn2.BpmnProcessInstance in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesWithLockIT method testUpdate.

@Test
public void testUpdate() {
    MongoDBProcessInstancesFactory factory = new MongoDBProcessInstancesFactory(getMongoClient());
    BpmnProcess process = createProcess(factory);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    MongoDBProcessInstances<?> processInstances = new MongoDBProcessInstances<>(getMongoClient(), process, DB_NAME, factory.transactionManager(), true);
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
    assertEquals(1L, instanceOne.version());
    assertEquals(1L, instanceTwo.version());
    instanceOne.updateVariables(BpmnVariables.create(Collections.singletonMap("s", "test")));
    try {
        BpmnVariables testvar = BpmnVariables.create(Collections.singletonMap("ss", "test"));
        instanceTwo.updateVariables(testvar);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was updated or deleted by other request.");
    }
    foundOne = processInstances.findById(processInstance.id());
    instanceOne = (BpmnProcessInstance) foundOne.get();
    assertEquals(2L, instanceOne.version());
    processInstances.remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 5 with BpmnProcessInstance

use of org.kie.kogito.process.bpmn2.BpmnProcessInstance in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesIT method testMongoDBPersistence.

@Test
void testMongoDBPersistence() {
    MongoDBProcessInstancesFactory factory = new MongoDBProcessInstancesFactory(getMongoClient());
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(factory);
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    MongoDBProcessInstances<?> mongodbInstance = new MongoDBProcessInstances<>(getMongoClient(), process, DB_NAME, factory.transactionManager(), false);
    assertThat(mongodbInstance.size()).isOne();
    assertThat(mongodbInstance.size()).isEqualTo(process.instances().size());
    Optional<?> findById = mongodbInstance.findById(processInstance.id());
    BpmnProcessInstance found = (BpmnProcessInstance) findById.get();
    assertNotNull(found, "ProcessInstanceDocument cannot be null");
    assertThat(found.id()).isEqualTo(processInstance.id());
    assertThat(found.description()).isEqualTo("User Task");
    assertThat(found.variables().toMap()).containsExactly(entry("test", "test"));
    assertThat(mongodbInstance.exists(processInstance.id())).isTrue();
    assertThat(mongodbInstance.values().size()).isOne();
    ProcessInstance<?> readOnlyPI = mongodbInstance.findById(processInstance.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertNotNull(readOnlyPI, "ProcessInstanceDocument cannot be null");
    assertThat(mongodbInstance.values(ProcessInstanceReadMode.READ_ONLY).size()).isOne();
    mongodbInstance.remove(processInstance.id());
    assertThat(mongodbInstance.exists(processInstance.id())).isFalse();
    assertThat(mongodbInstance.values()).isEmpty();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)8 BpmnProcessInstance (org.kie.kogito.process.bpmn2.BpmnProcessInstance)8 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)8 JDBCProcessInstances (org.kie.kogito.persistence.jdbc.JDBCProcessInstances)3 PostgreProcessInstances (org.kie.kogito.persistence.postgresql.PostgreProcessInstances)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)1