Java Code Examples for org.flowable.engine.ProcessEngine#close()

The following examples show how to use org.flowable.engine.ProcessEngine#close() . 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: EngineEventsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testEngineEventsTest() {
    ProcessEngineConfiguration processEngineConfiguration = StandaloneProcessEngineConfiguration
            .createProcessEngineConfigurationFromResource("org/flowable/standalone/event/flowable-eventlistener.cfg.xml");
    ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

    // Fetch the listener to check received events
    TestFlowableEventListener listener = (TestFlowableEventListener) processEngineConfiguration.getBeans().get("eventListener");
    assertThat(listener).isNotNull();

    // Check create-event
    assertThat(listener.getEventsReceived().get(0).getType()).isEqualTo(FlowableEngineEventType.ENGINE_CREATED);
    listener.clearEventsReceived();

    // Check close-event
    processEngine.close();
    assertThat(listener.getEventsReceived().get(listener.getEventsReceived().size() - 1).getType()).isEqualTo(FlowableEngineEventType.ENGINE_CLOSED);
}
 
Example 2
Source File: ForceCloseMybatisConnectionPoolTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testForceCloseMybatisConnectionPoolFalse() {

    // given
    // that the process engine is configured with forceCloseMybatisConnectionPool = false
    StandaloneInMemProcessEngineConfiguration standaloneInMemProcessEngineConfiguration =  new StandaloneInMemProcessEngineConfiguration();
    standaloneInMemProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-bpmn-" + this.getClass().getName());
    standaloneInMemProcessEngineConfiguration.setForceCloseMybatisConnectionPool(false);
    ProcessEngine processEngine = standaloneInMemProcessEngineConfiguration.buildProcessEngine();

    PooledDataSource pooledDataSource = (PooledDataSource) standaloneInMemProcessEngineConfiguration.getDataSource();
    PoolState state = pooledDataSource.getPoolState();
    assertThat(state.getIdleConnectionCount()).isGreaterThan(0);

    // then
    // if the process engine is closed
    processEngine.close();

    // the idle connections are not closed
    assertThat(state.getIdleConnectionCount()).isGreaterThan(0);

    pooledDataSource.forceCloseAll();
    assertThat(state.getIdleConnectionCount()).isZero();
}
 
Example 3
Source File: DatabaseTablePrefixTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessEngineReboot() throws Exception {
    
    ProcessEngine processEngine1 = null;
    ProcessEngine processEngine2 = null;
    
    try {
        
        createDataSourceAndSchema(); // Creating the schemas
    
        processEngine1 = createProcessEngine("SCHEMA1");
        processEngine1.getRepositoryService().createDeployment()
            .addClasspathResource("org/flowable/engine/test/db/oneJobProcess.bpmn20.xml").deploy();
        assertThat(processEngine1.getRepositoryService().createDeploymentQuery().count()).isEqualTo(1);
        
        // Boot second engine on other schema. Shouldn't be able to see the data
        processEngine2 = createProcessEngine("SCHEMA2");
        assertThat(processEngine2.getRepositoryService().createDeploymentQuery().count()).isZero();
        
        // Reboot both engines. The results should still be the same as before
        processEngine1.close();
        processEngine2.close();
        
        processEngine1 = createProcessEngine("SCHEMA1");
        processEngine2 = createProcessEngine("SCHEMA2");
        
        assertThat(processEngine1.getRepositoryService().createDeploymentQuery().count()).isEqualTo(1);
        assertThat(processEngine2.getRepositoryService().createDeploymentQuery().count()).isZero();
        
    } finally {
        if (processEngine1 != null) {
            processEngine1.close();
        }
        if (processEngine2 != null) {
            processEngine2.close();
        }
    }
}
 
Example 4
Source File: ResourceFlowableExtension.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public ProcessEngine rebootEngine() {
    String engineName = processEngineName != null ? processEngineName : ProcessEngines.NAME_DEFAULT;
    ProcessEngine processEngine = ProcessEngines.getProcessEngine(engineName);
    ProcessEngines.unregister(processEngine);
    processEngine.close();

    ProcessEngine rebootedProcessEngine = initializeProcessEngine();
    getStore(currentExtensionContext).put(currentExtensionContext.getUniqueId(), rebootedProcessEngine);
    return rebootedProcessEngine;
}
 
Example 5
Source File: ResourceFlowableExtension.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void afterEach(ExtensionContext context) throws Exception {
    super.afterEach(context);
    ProcessEngine processEngine = getProcessEngine(context);
    processEngine.close();
    processEngine = null;
}
 
Example 6
Source File: EventRecorderTestUtils.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static void closeProcessEngine(ProcessEngine processEngine, FlowableEventListener listener) {
    if (listener != null) {
        final ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
        processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
    }
    processEngine.close();
}
 
Example 7
Source File: AsyncExecutorTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void cleanup(ProcessEngine processEngine) {
    for (org.flowable.engine.repository.Deployment deployment : processEngine.getRepositoryService().createDeploymentQuery().list()) {
        processEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
    }
    processEngine.close();
}
 
Example 8
Source File: ProcessDefinitionCacheTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartProcessInstanceByIdAfterReboot() {

    // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the
    // existing process engines to make sure that the db is clean and that there are no existing process engines involved.
    ProcessEngines.destroy();

    // Creating the DB schema (without building a process engine)
    ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
    processEngineConfiguration.setEngineName("reboot-test-schema");
    processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
    ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

    // Create process engine and deploy test process
    ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
            .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    processEngine.getRepositoryService().createDeployment().addClasspathResource("org/flowable/engine/test/cache/originalProcess.bpmn20.xml").deploy();

    // verify existence of process definition
    List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();

    assertEquals(1, processDefinitions.size());

    // Start a new Process instance
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    String processInstanceId = processInstance.getId();
    assertNotNull(processInstance);

    // Close the process engine
    processEngine.close();
    assertNotNull(processEngine.getRuntimeService());

    // Reboot the process engine
    processEngine = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test").setDatabaseSchemaUpdate(org.flowable.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
            .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    // Check if the existing process instance is still alive
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNotNull(processInstance);

    // Complete the task. That will end the process instance
    TaskService taskService = processEngine.getTaskService();
    org.flowable.task.api.Task task = taskService.createTaskQuery().list().get(0);
    taskService.complete(task.getId());

    // Check if the process instance has really ended. This means that the
    // process definition has re-loaded into the process definition cache
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNull(processInstance);

    // Extra check to see if a new process instance can be started as well
    processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    assertNotNull(processInstance);

    // close the process engine
    processEngine.close();

    // Cleanup schema
    schemaProcessEngine.close();
}
 
Example 9
Source File: DatabaseTablePrefixTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testPerformDatabaseSchemaOperationCreate() throws Exception {

    DataSource dataSource = createDataSourceAndSchema();

    // configure & build two different process engines, each having a
    // separate table prefix
    ProcessEngineConfigurationImpl config1 = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
            .setDataSource(dataSource)
            .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
    config1.setDatabaseTablePrefix("SCHEMA1.");
    config1.setValidateFlowable5EntitiesEnabled(false);
    config1.setDisableEventRegistry(true);
    config1.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
    config1.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(false);
    ProcessEngine engine1 = config1.buildProcessEngine();

    ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
            .setDataSource(dataSource)
            .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
    config2.setDatabaseTablePrefix("SCHEMA2.");
    config2.setValidateFlowable5EntitiesEnabled(false);
    config2.setDisableEventRegistry(true);
    config2.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
    config2.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(false);
    ProcessEngine engine2 = config2.buildProcessEngine();

    // create the tables in SCHEMA1
    Connection connection = dataSource.getConnection();
    connection.createStatement().execute("set schema SCHEMA1");
    engine1.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA1");
    connection.close();

    // create the tables in SCHEMA2
    connection = dataSource.getConnection();
    connection.createStatement().execute("set schema SCHEMA2");
    engine2.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA2");
    connection.close();

    // if I deploy a process to one engine, it is not visible to the other
    // engine:
    try {
        engine1.getRepositoryService().createDeployment().addClasspathResource("org/flowable/engine/test/db/oneJobProcess.bpmn20.xml").deploy();

        assertThat(engine1.getRepositoryService().createDeploymentQuery().count()).isEqualTo(1);
        assertThat(engine2.getRepositoryService().createDeploymentQuery().count()).isZero();

    } finally {
        engine1.close();
        engine2.close();
    }
}
 
Example 10
Source File: AsyncExecutorTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void cleanup(ProcessEngine processEngine) {
    for (org.flowable.engine.repository.Deployment deployment : processEngine.getRepositoryService().createDeploymentQuery().list()) {
        processEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
    }
    processEngine.close();
}
 
Example 11
Source File: AsyncExecutorTwoEnginesTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void cleanup(ProcessEngine processEngine) {
    for (org.flowable.engine.repository.Deployment deployment : processEngine.getRepositoryService().createDeploymentQuery().list()) {
        processEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
    }
    processEngine.close();
}
 
Example 12
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 13
Source File: ProcessDefinitionCacheTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testStartProcessInstanceByIdAfterReboot() {

        // In case this test is run in a test suite, previous engines might
        // have been initialized and cached. First we close the
        // existing process engines to make sure that the db is clean
        // and that there are no existing process engines involved.
        ProcessEngines.destroy();

        // Creating the DB schema (without building a process engine)
        ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
        processEngineConfiguration.setEngineName("reboot-test-schema");
        processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
        processEngineConfiguration.setFlowable5CompatibilityEnabled(true);
        ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

        // Create process engine and deploy test process
        StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
        standaloneProcessEngineConfiguration.setEngineName("reboot-test");
        standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
        standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
        standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false);
        standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true);
        ProcessEngine processEngine = standaloneProcessEngineConfiguration.buildProcessEngine();

        processEngine.getRepositoryService()
                .createDeployment()
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
                .addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml")
                .deploy();

        // verify existence of process definition
        List<ProcessDefinition> processDefinitions = processEngine
                .getRepositoryService()
                .createProcessDefinitionQuery()
                .list();

        assertEquals(1, processDefinitions.size());

        // Start a new Process instance
        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
        String processInstanceId = processInstance.getId();
        assertNotNull(processInstance);

        // Close the process engine
        processEngine.close();
        assertNotNull(processEngine.getRuntimeService());

        // Reboot the process engine
        standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
        standaloneProcessEngineConfiguration.setEngineName("reboot-test");
        standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
        standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
        standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false);
        standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true);
        processEngine = standaloneProcessEngineConfiguration.buildProcessEngine();

        // Check if the existing process instance is still alive
        processInstance = processEngine
                .getRuntimeService()
                .createProcessInstanceQuery()
                .processInstanceId(processInstanceId)
                .singleResult();

        assertNotNull(processInstance);

        // Complete the task. That will end the process instance
        TaskService taskService = processEngine.getTaskService();
        org.flowable.task.api.Task task = taskService
                .createTaskQuery()
                .list()
                .get(0);
        taskService.complete(task.getId());

        // Check if the process instance has really ended. This means that the process definition has
        // re-loaded into the process definition cache
        processInstance = processEngine
                .getRuntimeService()
                .createProcessInstanceQuery()
                .processInstanceId(processInstanceId)
                .singleResult();

        assertNull(processInstance);

        // Extra check to see if a new process instance can be started as well
        processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
        assertNotNull(processInstance);

        // close the process engine
        processEngine.close();

        // Cleanup schema
        schemaProcessEngine.close();
    }
 
Example 14
Source File: DatabaseTablePrefixTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testPerformDatabaseSchemaOperationCreate() throws Exception {

        // both process engines will be using this datasource.
        PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(),
                "org.h2.Driver",
                "jdbc:h2:mem:activiti-test;DB_CLOSE_DELAY=1000",
                "sa",
                "");

        // create two schemas is the database
        Connection connection = pooledDataSource.getConnection();
        connection.createStatement().execute("drop schema if exists SCHEMA1");
        connection.createStatement().execute("drop schema if exists SCHEMA2");
        connection.createStatement().execute("create schema SCHEMA1");
        connection.createStatement().execute("create schema SCHEMA2");
        connection.close();

        // configure & build two different process engines, each having a separate table prefix
        ProcessEngineConfigurationImpl config1 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl
                .createStandaloneInMemProcessEngineConfiguration()
                .setDataSource(pooledDataSource)
                .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
        config1.setDatabaseTablePrefix("SCHEMA1.");
        config1.setFlowable5CompatibilityEnabled(true);
        config1.setValidateFlowable5EntitiesEnabled(false);
        config1.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
        config1.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(false);
        config1.setEventRegistryConfigurator(new CustomEventRegistryEngineConfigurator());
        ProcessEngine engine1 = config1.buildProcessEngine();

        ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl
                .createStandaloneInMemProcessEngineConfiguration()
                .setDataSource(pooledDataSource)
                .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
        config2.setDatabaseTablePrefix("SCHEMA2.");
        config2.setFlowable5CompatibilityEnabled(true);
        config2.setValidateFlowable5EntitiesEnabled(false);
        config2.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
        config2.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(false);
        config2.setEventRegistryConfigurator(new CustomEventRegistryEngineConfigurator());
        ProcessEngine engine2 = config2.buildProcessEngine();

        // create the tables in SCHEMA1
        connection = pooledDataSource.getConnection();
        connection.createStatement().execute("set schema SCHEMA1");
        engine1.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA1");
        connection.close();

        // create the tables in SCHEMA2
        connection = pooledDataSource.getConnection();
        connection.createStatement().execute("set schema SCHEMA2");
        engine2.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA2");
        connection.close();

        // if I deploy a process to one engine, it is not visible to the other engine:
        try {
            engine1.getRepositoryService()
                    .createDeployment()
                    .addClasspathResource("org/activiti/engine/test/db/oneJobProcess.bpmn20.xml")
                    .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
                    .deploy();

            assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count());
            assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count());

        } finally {
            engine1.close();
            engine2.close();
        }
    }
 
Example 15
Source File: V5ValidationEnabledTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testRunningV5ProcessInstancesAfterReboot() {

        // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the
        // existing process engines to make sure that the db is clean and that there are no existing process engines involved.
        ProcessEngines.destroy();

        // Creating the DB schema (without building a process engine)
        ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
        processEngineConfiguration.setEngineName("reboot-test-schema");
        processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000");
        ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

        // Create process engine and deploy test process
        ProcessEngine processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setValidateFlowable5EntitiesEnabled(false)
                .setFlowable5CompatibilityEnabled(true)
                .buildProcessEngine();

        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, true)
                .deploy();

        // verify existence of process definition
        List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(1, processDefinitions.size());

        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess");

        // deploy new version of one task process definition on v6 engine
        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml")
                .deploy();

        // Close the process engine
        processEngine.close();
        assertNotNull(processEngine.getRuntimeService());

        // Reboot the process engine
        try {
            processEngine = new StandaloneProcessEngineConfiguration()
                    .setEngineName("reboot-test")
                    .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                    .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                    .setAsyncExecutorActivate(false)
                    .buildProcessEngine();
            fail("Expected v5 validation error while booting the engine");

        } catch (FlowableException e) {
            assertTrue(e.getMessage().contains("Found at least one running v5 process instance"));
        }

        processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setValidateFlowable5EntitiesEnabled(false)
                .setFlowable5CompatibilityEnabled(true)
                .buildProcessEngine();

        processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().singleResult();
        assertNotNull(processInstance);

        processEngine.getTaskService().complete(processEngine.getTaskService().createTaskQuery().singleResult().getId());

        assertEquals(0, processEngine.getRuntimeService().createProcessInstanceQuery().count());

        // close the process engine
        processEngine.close();

        // starting process engine without running process instances
        processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .buildProcessEngine();

        // close the process engine
        processEngine.close();

        // Cleanup schema
        schemaProcessEngine.close();
    }
 
Example 16
Source File: V5ValidationEnabledTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testDeployedV5ProcessDefinitionAfterReboot() {

        // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the
        // existing process engines to make sure that the db is clean and that there are no existing process engines involved.
        ProcessEngines.destroy();

        // Creating the DB schema (without building a process engine)
        ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
        processEngineConfiguration.setEngineName("reboot-test-schema");
        processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000");
        ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

        // Create process engine and deploy test process
        ProcessEngine processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setValidateFlowable5EntitiesEnabled(false)
                .setFlowable5CompatibilityEnabled(true)
                .buildProcessEngine();

        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, true)
                .deploy();

        // verify existence of process definition
        List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(1, processDefinitions.size());

        // Close the process engine
        processEngine.close();
        assertNotNull(processEngine.getRuntimeService());

        // Reboot the process engine
        try {
            processEngine = new StandaloneProcessEngineConfiguration()
                    .setEngineName("reboot-test")
                    .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                    .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                    .setAsyncExecutorActivate(false)
                    .buildProcessEngine();
            fail("Expected v5 validation error while booting the engine");

        } catch (FlowableException e) {
            assertTrue(e.getMessage().contains("Found v5 process definitions that are the latest version"));
        }

        processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setValidateFlowable5EntitiesEnabled(false)
                .setFlowable5CompatibilityEnabled(true)
                .buildProcessEngine();

        processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(1, processDefinitions.size());

        // close the process engine
        processEngine.close();

        // Cleanup schema
        schemaProcessEngine.close();
    }
 
Example 17
Source File: V5RedeployTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testNoRedeployNecessaryAfterReboot() {

        // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the
        // existing process engines to make sure that the db is clean and that there are no existing process engines involved.
        ProcessEngines.destroy();

        // Creating the DB schema (without building a process engine)
        ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
        processEngineConfiguration.setEngineName("reboot-test-schema");
        processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000");
        ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

        // Create process engine and deploy test process
        ProcessEngine processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setFlowable5CompatibilityEnabled(true)
                .buildProcessEngine();

        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml")
                .addClasspathResource("org/activiti/engine/test/api/oneSubProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, true)
                .deploy();

        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml")
                .addClasspathResource("org/activiti/engine/test/api/oneSubProcess.bpmn20.xml")
                .deploy();

        // verify existence of process definition
        List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(4, processDefinitions.size());

        // Close the process engine
        processEngine.close();

        // Reboot the process engine
        processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setFlowable5CompatibilityEnabled(true)
                .setRedeployFlowable5ProcessDefinitions(true)
                .buildProcessEngine();

        processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(4, processDefinitions.size());

        processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().latestVersion().list();
        assertEquals(2, processDefinitions.size());

        for (ProcessDefinition processDefinition : processDefinitions) {
            assertNull(processDefinition.getEngineVersion());
        }

        assertEquals(processDefinitions.get(0).getDeploymentId(), processDefinitions.get(1).getDeploymentId());

        // close the process engine
        processEngine.close();

        // Cleanup schema
        schemaProcessEngine.close();
    }
 
Example 18
Source File: V5RedeployTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testOnlyOneRedeployNecessaryAfterReboot() {

        // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the
        // existing process engines to make sure that the db is clean and that there are no existing process engines involved.
        ProcessEngines.destroy();

        // Creating the DB schema (without building a process engine)
        ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
        processEngineConfiguration.setEngineName("reboot-test-schema");
        processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000");
        ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

        // Create process engine and deploy test process
        ProcessEngine processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setFlowable5CompatibilityEnabled(true)
                .buildProcessEngine();

        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml")
                .addClasspathResource("org/activiti/engine/test/api/oneSubProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, true)
                .deploy();

        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneSubProcess.bpmn20.xml")
                .deploy();

        // verify existence of process definition
        List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(3, processDefinitions.size());

        // Close the process engine
        processEngine.close();

        // Reboot the process engine
        processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setFlowable5CompatibilityEnabled(true)
                .setRedeployFlowable5ProcessDefinitions(true)
                .buildProcessEngine();

        processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(4, processDefinitions.size());

        processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().latestVersion().list();
        assertEquals(2, processDefinitions.size());

        for (ProcessDefinition processDefinition : processDefinitions) {
            assertNull(processDefinition.getEngineVersion());
        }

        assertFalse(processDefinitions.get(0).getDeploymentId().equals(processDefinitions.get(1).getDeploymentId()));

        // close the process engine
        processEngine.close();

        // Cleanup schema
        schemaProcessEngine.close();
    }
 
Example 19
Source File: V5RedeployTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testRedeployV5ProcessDefinitionsAfterReboot() {

        // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the
        // existing process engines to make sure that the db is clean and that there are no existing process engines involved.
        ProcessEngines.destroy();

        // Creating the DB schema (without building a process engine)
        ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
        processEngineConfiguration.setEngineName("reboot-test-schema");
        processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000");
        ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

        // Create process engine and deploy test process
        ProcessEngine processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setFlowable5CompatibilityEnabled(true)
                .buildProcessEngine();

        processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml")
                .addClasspathResource("org/activiti/engine/test/api/oneSubProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, true)
                .deploy();

        // verify existence of process definition
        List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(2, processDefinitions.size());

        // Close the process engine
        processEngine.close();

        // Reboot the process engine
        processEngine = new StandaloneProcessEngineConfiguration()
                .setEngineName("reboot-test")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .setJdbcUrl("jdbc:h2:mem:flowable-reboot-test;DB_CLOSE_DELAY=1000")
                .setAsyncExecutorActivate(false)
                .setFlowable5CompatibilityEnabled(true)
                .setRedeployFlowable5ProcessDefinitions(true)
                .buildProcessEngine();

        processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
        assertEquals(4, processDefinitions.size());

        processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().latestVersion().list();
        assertEquals(2, processDefinitions.size());

        for (ProcessDefinition processDefinition : processDefinitions) {
            assertNull(processDefinition.getEngineVersion());
        }

        assertEquals(processDefinitions.get(0).getDeploymentId(), processDefinitions.get(1).getDeploymentId());

        // close the process engine
        processEngine.close();

        // Cleanup schema
        schemaProcessEngine.close();
    }
 
Example 20
Source File: TestHelper.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public static void closeProcessEngines() {
    for (ProcessEngine processEngine : processEngines.values()) {
        processEngine.close();
    }
    processEngines.clear();
}