// 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")
.setJobExecutorActivate(false)
.buildProcessEngine();
processEngine.getRepositoryService()
.createDeployment()
.addClasspathResource("org/camunda/bpm/engine/test/cache/originalProcess.bpmn20.xml")
.deploy();
// verify existance of process definiton
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()
.setProcessEngineName("reboot-test")
.setDatabaseSchemaUpdate(org.camunda.bpm.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000")
.setJobExecutorActivate(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();
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();
}