Search in sources :

Example 1 with StandaloneProcessEngineConfiguration

use of org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration in project Activiti by Activiti.

the class ConfigurationFactory method getConfiguration.

public StandaloneProcessEngineConfiguration getConfiguration() {
    StandaloneProcessEngineConfiguration conf = new StandaloneProcessEngineConfiguration();
    conf.setDataSource(dataSource);
    conf.setDatabaseSchemaUpdate(databaseSchemaUpdate);
    conf.setJobExecutorActivate(jobExecutorActivate);
    return conf;
}
Also used : StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)

Example 2 with StandaloneProcessEngineConfiguration

use of org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration in project Activiti by Activiti.

the class ProcessDefinitionInfoCacheTest method testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.

public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();
    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(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/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();
    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    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").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();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 3 with StandaloneProcessEngineConfiguration

use of org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration in project Activiti by Activiti.

the class ProcessDefinitionCacheTest method testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.

public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema").setDatabaseSchemaUpdate(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().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(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/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();
    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    Task task = taskService2.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("original task");
    // Delete the deployment on second process engine
    repositoryService2.deleteDeployment(deploymentId, true);
    assertThat(repositoryService2.createDeploymentQuery().count()).isEqualTo(0);
    assertThat(runtimeService2.createProcessInstanceQuery().count()).isEqualTo(0);
    // 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").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();
    assertThat(task.getName()).isEqualTo("revised task");
    // cleanup
    repositoryService1.deleteDeployment(deploymentId, true);
    processEngine1.close();
    processEngine2.close();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 4 with StandaloneProcessEngineConfiguration

use of org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration in project Activiti by Activiti.

the class ProcessDefinitionInfoCacheTest method testStartProcessInstanceByIdAfterReboot.

// Test for a bug: when the process engine is rebooted the
// cache is cleaned and the deployed process definition is
// removed from the process cache. This led to problems because
// the id wasn't fetched from the DB after a redeploy.
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.setProcessEngineName("reboot-info-test-schema");
    processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-info-test;DB_CLOSE_DELAY=1000");
    ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();
    // Create process engine and deploy test process
    ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-info-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-reboot-info-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).setEnableProcessDefinitionInfoCache(true).buildProcessEngine();
    processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy();
    // verify existance of process definiton
    List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
    assertEquals(1, processDefinitions.size());
    String processDefinitionId = processDefinitions.get(0).getId();
    ObjectNode infoNode = processEngine.getDynamicBpmnService().getProcessDefinitionInfo(processDefinitionId);
    assertNotNull(infoNode);
    infoNode = processEngineConfiguration.getObjectMapper().createObjectNode();
    infoNode.put("test", "test");
    processEngine.getDynamicBpmnService().saveProcessDefinitionInfo(processDefinitionId, infoNode);
    infoNode = processEngine.getDynamicBpmnService().getProcessDefinitionInfo(processDefinitionId);
    assertNotNull(infoNode);
    assertEquals("test", infoNode.get("test").asText());
    // Start a new Process instance
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId);
    String processInstanceId = processInstance.getId();
    assertNotNull(processInstance);
    // Close the process engine
    processEngine.close();
    assertNotNull(processEngine.getRuntimeService());
    // Reboot the process engine
    processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-info-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-reboot-info-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).setEnableProcessDefinitionInfoCache(true).buildProcessEngine();
    infoNode = processEngine.getDynamicBpmnService().getProcessDefinitionInfo(processDefinitionId);
    assertNotNull(infoNode);
    assertEquals("test", infoNode.get("test").asText());
    // 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();
    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();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TaskService(org.activiti.engine.TaskService) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) StandaloneInMemProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 5 with StandaloneProcessEngineConfiguration

use of org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration in project Activiti by Activiti.

the class ProcessDefinitionCacheTest method testStartProcessInstanceByIdAfterReboot.

// Test for a bug: when the process engine is rebooted the
// cache is cleaned and the deployed process definition is
// removed from the process cache. This led to problems because
// the id wasn't fetched from the DB after a redeploy.
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.setProcessEngineName("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().setProcessEngineName("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/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy();
    // verify existence of process definition
    List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
    assertThat(processDefinitions).hasSize(1);
    // Start a new Process instance
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    String processInstanceId = processInstance.getId();
    assertThat(processInstance).isNotNull();
    // Close the process engine
    processEngine.close();
    assertThat(processEngine.getRuntimeService()).isNotNull();
    // Reboot the process engine
    processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(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();
    assertThat(processInstance).isNotNull();
    // Complete the task. That will end the process instance
    TaskService taskService = processEngine.getTaskService();
    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();
    assertThat(processInstance).isNull();
    // Extra check to see if a new process instance can be started as well
    processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    assertThat(processInstance).isNotNull();
    // close the process engine
    processEngine.close();
    // Cleanup schema
    schemaProcessEngine.close();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) TaskService(org.activiti.engine.TaskService) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) StandaloneInMemProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) ProcessEngine(org.activiti.engine.ProcessEngine)

Aggregations

StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)5 ProcessEngine (org.activiti.engine.ProcessEngine)4 TaskService (org.activiti.engine.TaskService)4 Task (org.activiti.engine.task.Task)4 RepositoryService (org.activiti.engine.RepositoryService)2 RuntimeService (org.activiti.engine.RuntimeService)2 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 StandaloneInMemProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1