use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.
the class DatabaseTablePrefixTest method testPerformDatabaseSchemaOperationCreate.
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(// disable auto create/drop schema
"NO_CHECK");
config1.setDatabaseTablePrefix("SCHEMA1.");
ProcessEngine engine1 = config1.buildProcessEngine();
ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl.createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource).setDatabaseSchemaUpdate(// disable auto create/drop schema
"NO_CHECK");
config2.setDatabaseTablePrefix("SCHEMA2.");
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();
// engine:
try {
engine1.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/db/oneJobProcess.bpmn20.xml").deploy();
assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count());
assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count());
} finally {
engine1.close();
engine2.close();
}
}
use of org.activiti.engine.ProcessEngine 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();
}
use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.
the class AsyncExecutorTest method testRegularAsyncExecution.
@Test
public void testRegularAsyncExecution() {
ProcessEngine processEngine = null;
try {
// Deploy
processEngine = createProcessEngine(true);
setClockToCurrentTime(processEngine);
deploy(processEngine, "AsyncExecutorTest.testRegularAsyncExecution.bpmn20.xml");
// Start process instance. Wait for all jobs to be done
processEngine.getRuntimeService().startProcessInstanceByKey("asyncExecutor");
// Move clock 3 minutes. Nothing should happen
addSecondsToCurrentTime(processEngine, 180L);
try {
waitForAllJobsBeingExecuted(processEngine, 500L);
Assert.fail();
} catch (ActivitiException e) {
// Expected
}
Assert.assertEquals(1, processEngine.getTaskService().createTaskQuery().taskName("The Task").count());
Assert.assertEquals(0, processEngine.getTaskService().createTaskQuery().taskName("Task after timer").count());
Assert.assertEquals(1, processEngine.getManagementService().createJobQuery().count());
Assert.assertEquals(0, getAsyncExecutorJobCount(processEngine));
// Move clock 3 minutes and 1 second. Triggers the timer
addSecondsToCurrentTime(processEngine, 181);
waitForAllJobsBeingExecuted(processEngine);
// Verify if all is as expected
Assert.assertEquals(0, processEngine.getTaskService().createTaskQuery().taskName("The Task").count());
Assert.assertEquals(1, processEngine.getTaskService().createTaskQuery().taskName("Task after timer").count());
Assert.assertEquals(0, processEngine.getManagementService().createJobQuery().count());
Assert.assertEquals(1, getAsyncExecutorJobCount(processEngine));
} finally {
// Clean up
if (processEngine != null) {
cleanup(processEngine);
}
}
}
use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.
the class ReportingUtil method generateTaskDurationReport.
// WARNING!!! DemoWare!!!
public static void generateTaskDurationReport(String processDefinitionId) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
// Fetch process definition
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
// Report descriptin
String reportDescription = "Average task duration report for process definition " + processDefinition.getName() + " ( version " + processDefinition.getVersion() + ")";
// Script (just plain String for the moment)
String script = "importPackage(java.sql);" + "importPackage(java.lang);" + "importPackage(org.activiti.explorer.reporting);" + "" + "var processDefinitionId = '" + processDefinitionId + "';" + "" + "var result = ReportingUtil.executeSelectSqlQuery(\"select NAME_, avg(DURATION_) from ACT_HI_TASKINST where PROC_DEF_ID_ = '" + processDefinitionId + "' and END_TIME_ is not null group by NAME_\");" + "" + "var reportData = new ReportData();" + "var dataset = reportData.newDataset();" + "dataset.type = 'pieChart';" + "dataset.description = '" + reportDescription + "';" + "" + "while (result.next()) { " + " var name = result.getString(1);" + " var val = result.getLong(2) / 1000;" + " dataset.add(name, val);" + "}" + "" + "execution.setVariable('reportData', reportData.toBytes());";
// Generate bpmn model
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name(processDefinition.getName() + " task duration report").description(reportDescription).addScriptStep(script);
// Convert to BPMN 2.0 XML
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
conversion.getBpmnModel().setTargetNamespace("activiti-report");
// Generate DI
BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(conversion.getBpmnModel());
bpmnAutoLayout.execute();
// Deploy
repositoryService.createDeployment().name(processDefinition.getName() + " - task duration report").addString(conversion.getProcess().getId() + ".bpmn20.xml", conversion.getBpmn20Xml()).deploy();
}
use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.
the class IntegrationAutoConfigurationTest method testLaunchingGatewayProcessDefinition.
@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(InboundGatewayConfiguration.class);
RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);
Assert.assertNotNull("the process engine should not be null", processEngine);
Assert.assertNotNull("we should have a default repositoryService included", repositoryService);
String integrationGatewayProcess = "integrationGatewayProcess";
List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().processDefinitionKey(integrationGatewayProcess).list();
ProcessDefinition processDefinition = processDefinitionList.iterator().next();
Assert.assertEquals(processDefinition.getKey(), integrationGatewayProcess);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("customerId", 232);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(integrationGatewayProcess, vars);
Assert.assertNotNull("the processInstance should not be null", processInstance);
org.junit.Assert.assertTrue(applicationContext.getBean(InboundGatewayConfiguration.AnalysingService.class).getStringAtomicReference().get().equals(projectId));
}
Aggregations