Java Code Examples for org.flowable.engine.RuntimeService#startProcessInstanceById()

The following examples show how to use org.flowable.engine.RuntimeService#startProcessInstanceById() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessDefinitionCacheTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {

        // Setup both process engines
        StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
        standaloneProcessEngineConfiguration.setEngineName("reboot-test-schema");
        standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
        standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false);
        standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true);
        ProcessEngine processEngine1 = standaloneProcessEngineConfiguration.buildProcessEngine();
        RepositoryService repositoryService1 = processEngine1.getRepositoryService();

        StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration2 = new StandaloneProcessEngineConfiguration();
        standaloneProcessEngineConfiguration2.setEngineName("reboot-test");
        standaloneProcessEngineConfiguration2.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
        standaloneProcessEngineConfiguration2.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
        standaloneProcessEngineConfiguration2.setAsyncExecutorActivate(false);
        standaloneProcessEngineConfiguration2.setFlowable5CompatibilityEnabled(true);
        ProcessEngine processEngine2 = standaloneProcessEngineConfiguration2.buildProcessEngine();
        RepositoryService repositoryService2 = processEngine2.getRepositoryService();
        RuntimeService runtimeService2 = processEngine2.getRuntimeService();
        TaskService taskService2 = processEngine2.getTaskService();

        // Deploy first version of process: start->originalTask->end on first process engine
        String deploymentId = repositoryService1.createDeployment()
                .addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
                .deploy()
                .getId();

        // Start process instance on second engine
        String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
        runtimeService2.startProcessInstanceById(processDefinitionId);
        org.flowable.task.api.Task task = taskService2.createTaskQuery().singleResult();
        assertEquals("original task", task.getName());

        // Delete the deployment on second process engine
        repositoryService2.deleteDeployment(deploymentId, true);
        assertEquals(0, repositoryService2.createDeploymentQuery().count());
        assertEquals(0, runtimeService2.createProcessInstanceQuery().count());

        // deploy a revised version of the process: start->revisedTask->end on first process engine
        //
        // Before the bugfix, this would set the cache on the first process engine,
        // but the second process engine still has the original process definition in his cache.
        // Since there is a deployment delete in between, the new generated process definition id is the same
        // as in the original deployment, making the second process engine using the old cached process definition.
        deploymentId = repositoryService1.createDeployment()
                .addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
                .deploy()
                .getId();

        // Start process instance on second process engine -> must use revised process definition
        repositoryService2.createProcessDefinitionQuery().singleResult().getId();
        runtimeService2.startProcessInstanceByKey("oneTaskProcess");
        task = taskService2.createTaskQuery().singleResult();
        assertEquals("revised task", task.getName());

        // cleanup
        repositoryService1.deleteDeployment(deploymentId, true);
        processEngine1.close();
        processEngine2.close();
    }
 
Example 2
Source File: ProcessDefinitionCacheTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {

    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test-schema")
            .setDatabaseSchemaUpdate(org.flowable.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
            .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();

    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test")
            .setDatabaseSchemaUpdate(org.flowable.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
            .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService2 = processEngine2.getRepositoryService();
    RuntimeService runtimeService2 = processEngine2.getRuntimeService();
    TaskService taskService2 = processEngine2.getTaskService();

    // Deploy first version of process: start->originalTask->end on first
    // process engine
    String deploymentId = repositoryService1.createDeployment().addClasspathResource("org/flowable/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    org.flowable.task.api.Task task = taskService2.createTaskQuery().singleResult();
    assertEquals("original task", task.getName());

    // Delete the deployment on second process engine
    repositoryService2.deleteDeployment(deploymentId, true);
    assertEquals(0, repositoryService2.createDeploymentQuery().count());
    assertEquals(0, runtimeService2.createProcessInstanceQuery().count());

    // deploy a revised version of the process: start->revisedTask->end on first process engine
    //
    // Before the bugfix, this would set the cache on the first process
    // engine, but the second process engine still has the original process
    // definition in his cache. Since there is a deployment delete in between, the new generated
    // process definition id is the same as in the original deployment, making the second process engine using
    // the old cached process definition.
    deploymentId = repositoryService1.createDeployment().addClasspathResource("org/flowable/engine/test/cache/revisedProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second process engine -> must use revised process definition
    repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceByKey("oneTaskProcess");
    task = taskService2.createTaskQuery().singleResult();
    assertEquals("revised task", task.getName());

    // cleanup
    repositoryService1.deleteDeployment(deploymentId, true);
    processEngine1.close();
    processEngine2.close();
}