org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration. 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: OSGiDmnIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
private void createProcessEngine() {
  StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
  configuration.setDatabaseSchemaUpdate("create-drop")
    .setDataSource(createDatasource())
    .setJobExecutorActivate(false);
  configuration.setExpressionManager(new OSGiExpressionManager());
  ProcessEngineFactory processEngineFactory = new ProcessEngineFactory();
  processEngineFactory.setProcessEngineConfiguration(configuration);
  processEngineFactory
    .setBundle(getBundle("org.camunda.bpm.extension.osgi"));
  try {
    processEngineFactory.init();
    processEngine = processEngineFactory.getObject();
    ctx.registerService(ProcessEngine.class.getName(), processEngine,
      new Hashtable<String, String>());
  } catch (Exception e) {
    fail(e.toString());
  }
}
 
Example #2
Source File: AbstractDeploymentListenerIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
private void createProcessEngine() {
	StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
	configuration.setDatabaseSchemaUpdate("create-drop").setDataSource(createDatasource()).setJobExecutorActivate(false);
	ProcessEngineFactory processEngineFactory = new ProcessEngineFactory();
	processEngineFactory.setProcessEngineConfiguration(configuration);
	processEngineFactory
			.setBundle(getBundle("org.camunda.bpm.extension.osgi"));
	try {
		processEngineFactory.init();
		processEngine = processEngineFactory.getObject();
		ctx.registerService(ProcessEngine.class.getName(), processEngine,
		    new Hashtable<String, String>());
	} catch (Exception e) {
		fail(e.toString());
	}
}
 
Example #3
Source File: OSGiBusinessKeyIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
private void createProcessEngine() {
  StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
  configuration.setDatabaseSchemaUpdate("create-drop")
    .setDataSource(createDatasource())
    .setJobExecutorActivate(false);
  configuration.setExpressionManager(new OSGiExpressionManager());
  ProcessEngineFactory processEngineFactory = new ProcessEngineFactory();
  processEngineFactory.setProcessEngineConfiguration(configuration);
  processEngineFactory
    .setBundle(getBundle("org.camunda.bpm.extension.osgi"));
  try {
    processEngineFactory.init();
    processEngine = processEngineFactory.getObject();
    ctx.registerService(ProcessEngine.class.getName(), processEngine,
      new Hashtable<String, String>());
  } catch (Exception e) {
    fail(e.toString());
  }
}
 
Example #4
Source File: OSGiELTenantIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
private void createProcessEngine() {
  StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
  configuration.setDatabaseSchemaUpdate("create-drop")
    .setDataSource(createDatasource())
    .setJobExecutorActivate(false);
  configuration.setExpressionManager(new OSGiExpressionManager());
  ProcessEngineFactory processEngineFactory = new ProcessEngineFactory();
  processEngineFactory.setProcessEngineConfiguration(configuration);
  processEngineFactory
    .setBundle(getBundle("org.camunda.bpm.extension.osgi"));
  try {
    processEngineFactory.init();
    processEngine = processEngineFactory.getObject();
    ctx.registerService(ProcessEngine.class.getName(), processEngine,
      new Hashtable<String, String>());
  } catch (Exception e) {
    fail(e.toString());
  }
}
 
Example #5
Source File: AbstractOSGiELResolverIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
private void createProcessEngine() {
	StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
	configuration.setDatabaseSchemaUpdate("create-drop")
			.setDataSource(createDatasource())
			.setJobExecutorActivate(false);
	configuration.setExpressionManager(new OSGiExpressionManager());
	ProcessEngineFactory processEngineFactory = new ProcessEngineFactory();
	processEngineFactory.setProcessEngineConfiguration(configuration);
	processEngineFactory
			.setBundle(getBundle("org.camunda.bpm.extension.osgi"));
	try {
		processEngineFactory.init();
		processEngine = processEngineFactory.getObject();
		ctx.registerService(ProcessEngine.class.getName(), processEngine,
				new Hashtable<String, String>());
	} catch (Exception e) {
		fail(e.toString());
	}
}
 
Example #6
Source File: ProcessEngineFactoryWithELResolverTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
@Test
public void initWithBlueprintELResolverAndWithoutResolverFactories()
		throws Exception {
	StandaloneProcessEngineConfiguration config = mock(StandaloneProcessEngineConfiguration.class);
	when(config.getResolverFactories()).thenReturn(null);
	factory.setProcessEngineConfiguration(config);
	factory.setExpressionManager(new BlueprintExpressionManager());
	factory.init();
	// captures
	ArgumentCaptor<BlueprintExpressionManager> elManagerCaptor = ArgumentCaptor
			.forClass(BlueprintExpressionManager.class);
	verify(config).setExpressionManager(elManagerCaptor.capture());
	ArgumentCaptor<OsgiScriptingEngines> scriptCaptor = ArgumentCaptor
			.forClass(OsgiScriptingEngines.class);
	verify(config).setScriptingEngines(scriptCaptor.capture());
	// checks
	checkScriptingEngine(scriptCaptor.getValue());
	checkExpressionManager(elManagerCaptor.getValue());
}
 
Example #7
Source File: ProcessEngineFactoryWithELResolverTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
@Test
public void initWithResolverFactories() throws Exception {
	StandaloneProcessEngineConfiguration config = mock(StandaloneProcessEngineConfiguration.class);
	ResolverFactory resolverFactory = mock(ResolverFactory.class);
	when(config.getResolverFactories()).thenReturn(
			Collections.singletonList(resolverFactory));
	factory.setProcessEngineConfiguration(config);
	factory.init();
	// captures
	ArgumentCaptor<OsgiScriptingEngines> scriptCaptor = ArgumentCaptor
			.forClass(OsgiScriptingEngines.class);
	verify(config).setScriptingEngines(scriptCaptor.capture());
	// checks
	assertThat(scriptCaptor.getValue().getScriptBindingsFactory()
			.getResolverFactories(), hasItem(resolverFactory));
}
 
Example #8
Source File: PropertyHelperTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Assert that String, int and boolean properties can be set.
 */
public void testProcessEngineConfigurationProperties() {
  ProcessEngineConfiguration engineConfiguration = new StandaloneProcessEngineConfiguration();

  Map<String, String> propertiesToSet = new HashMap<String, String>();
  propertiesToSet.put(JOB_EXECUTOR_DEPLOYMENT_AWARE_PROP, "true");
  propertiesToSet.put(JOB_EXECUTOR_PREFER_TIMER_JOBS, "true");
  propertiesToSet.put(JOB_EXECUTOR_ACQUIRE_BY_DUE_DATE, "true");
  propertiesToSet.put(MAIL_SERVER_PORT_PROP, "42");
  propertiesToSet.put(JDBC_URL_PROP, "someUrl");

  PropertyHelper.applyProperties(engineConfiguration, propertiesToSet);

  Assert.assertTrue(engineConfiguration.isJobExecutorDeploymentAware());
  Assert.assertTrue(engineConfiguration.isJobExecutorPreferTimerJobs());
  Assert.assertTrue(engineConfiguration.isJobExecutorAcquireByDueDate());
  Assert.assertEquals(42, engineConfiguration.getMailServerPort());
  Assert.assertEquals("someUrl", engineConfiguration.getJdbcUrl());
}
 
Example #9
Source File: SpringTransactionsProcessEngineConfiguration.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Collection< ? extends CommandInterceptor> getDefaultCommandInterceptorsTxRequired() {
  if (transactionManager==null) {
    throw new ProcessEngineException("transactionManager is required property for SpringProcessEngineConfiguration, use "+StandaloneProcessEngineConfiguration.class.getName()+" otherwise");
  }

  List<CommandInterceptor> defaultCommandInterceptorsTxRequired = new ArrayList<CommandInterceptor>();
  defaultCommandInterceptorsTxRequired.add(new LogInterceptor());
  defaultCommandInterceptorsTxRequired.add(new ProcessApplicationContextInterceptor(this));
  defaultCommandInterceptorsTxRequired.add(new SpringTransactionInterceptor(transactionManager, TransactionTemplate.PROPAGATION_REQUIRED));
  CommandContextInterceptor commandContextInterceptor = new CommandContextInterceptor(commandContextFactory, this);
  defaultCommandInterceptorsTxRequired.add(commandContextInterceptor);
  return defaultCommandInterceptorsTxRequired;
}
 
Example #10
Source File: ScriptEngineBundleTrackerCustomizerIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
private void createProcessEngine() {
  StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
  configuration.setDatabaseSchemaUpdate("create-drop").setDataSource(createDatasource()).setJobExecutorActivate(false);
  ProcessEngineFactory processEngineFactory = new ProcessEngineFactoryWithELResolver();
  processEngineFactory.setProcessEngineConfiguration(configuration);
  processEngineFactory.setBundle(getBundle("org.camunda.bpm.extension.osgi"));
  try {
    processEngineFactory.init();
    processEngine = processEngineFactory.getObject();
    ctx.registerService(ProcessEngine.class.getName(), processEngine, new Hashtable<String, String>());
  } catch (Exception e) {
    fail(e.toString());
  }
}
 
Example #11
Source File: PerfTestProcessEngine.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static ProcessEngine createProcessEngine(javax.sql.DataSource datasource, Properties properties) {

    ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneProcessEngineConfiguration();
    processEngineConfiguration.setDataSource(datasource);
    processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

    processEngineConfiguration.setHistory(properties.getProperty("historyLevel"));

    processEngineConfiguration.setJdbcBatchProcessing(Boolean.valueOf(properties.getProperty("jdbcBatchProcessing")));

    // load plugins
    String processEnginePlugins = properties.getProperty("processEnginePlugins", "");
    for (String pluginName : processEnginePlugins.split(",")) {
      if(pluginName.length() > 1) {
        Object pluginInstance = ReflectUtil.instantiate(pluginName);
        if(!(pluginInstance instanceof ProcessEnginePlugin)) {
          throw new PerfTestException("Plugin "+pluginName +" is not an instance of ProcessEnginePlugin");

        } else {
          List<ProcessEnginePlugin> plugins = processEngineConfiguration.getProcessEnginePlugins();
          if(plugins == null) {
            plugins = new ArrayList<ProcessEnginePlugin>();
            processEngineConfiguration.setProcessEnginePlugins(plugins);
          }
          plugins.add((ProcessEnginePlugin) pluginInstance);

        }
      }
    }

    return processEngineConfiguration.buildProcessEngine();
  }
 
Example #12
Source File: PropertyHelperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testNonExistingPropertyForProcessEngineConfiguration() {
  ProcessEngineConfiguration engineConfiguration = new StandaloneProcessEngineConfiguration();
  Map<String, String> propertiesToSet = new HashMap<String, String>();
  propertiesToSet.put("aNonExistingProperty", "someValue");

  try {
    PropertyHelper.applyProperties(engineConfiguration, propertiesToSet);
    Assert.fail();
  } catch (Exception e) {
    // happy path
  }
}
 
Example #13
Source File: PropertyHelperTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Assures that property names are matched on the setter name according to java beans conventions
 * and not on the field name.
 */
public void testConfigurationPropertiesWithMismatchingFieldAndSetter() {
  ProcessEngineConfigurationImpl engineConfiguration = new StandaloneProcessEngineConfiguration();

  Map<String, String> propertiesToSet = new HashMap<String, String>();
  propertiesToSet.put(DB_IDENTITY_USED_PROP, "false");
  PropertyHelper.applyProperties(engineConfiguration, propertiesToSet);

  Assert.assertFalse(engineConfiguration.isDbIdentityUsed());

  propertiesToSet.put(DB_IDENTITY_USED_PROP, "true");
  PropertyHelper.applyProperties(engineConfiguration, propertiesToSet);

  Assert.assertTrue(engineConfiguration.isDbIdentityUsed());
}
 
Example #14
Source File: SequentialJobAcquisitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteJobsForSingleEngine() {
  // configure and build a process engine
  StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
  standaloneProcessEngineConfiguration.setProcessEngineName(getClass().getName() + "-engine1");
  standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:jobexecutor-test-engine");
  standaloneProcessEngineConfiguration.setJobExecutorActivate(false);
  standaloneProcessEngineConfiguration.setJobExecutor(jobExecutor);
  standaloneProcessEngineConfiguration.setDbMetricsReporterActivate(false);
  ProcessEngine engine = standaloneProcessEngineConfiguration.buildProcessEngine();

  createdProcessEngines.add(engine);

  engine.getRepositoryService().createDeployment()
    .addClasspathResource(PROCESS_RESOURCE)
    .deploy();

  jobExecutor.shutdown();

  engine.getRuntimeService()
    .startProcessInstanceByKey("intermediateTimerEventExample");

  Assert.assertEquals(1, engine.getManagementService().createJobQuery().count());

  Calendar calendar = Calendar.getInstance();
  calendar.add(Field.DAY_OF_YEAR.getCalendarField(), 6);
  ClockUtil.setCurrentTime(calendar.getTime());
  jobExecutor.start();
  waitForJobExecutorToProcessAllJobs(10000, 100, jobExecutor, engine.getManagementService(), true);

  Assert.assertEquals(0, engine.getManagementService().createJobQuery().count());
}
 
Example #15
Source File: ProcessEngineFactoryWithELResolverTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void initWithoutBlueprintELResolverCausesNPEInBlueprintExpressionManager()
		throws Exception {
	StandaloneProcessEngineConfiguration config = mock(StandaloneProcessEngineConfiguration.class);
	factory.setProcessEngineConfiguration(config);
	factory.init();
	// captures
	ArgumentCaptor<BlueprintExpressionManager> elManagerCaptor = ArgumentCaptor
			.forClass(BlueprintExpressionManager.class);
	verify(config).setExpressionManager(elManagerCaptor.capture());
	elManagerCaptor.getValue().createElResolver();
}
 
Example #16
Source File: ConfigurationFactory.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
public StandaloneProcessEngineConfiguration getConfiguration() {
	StandaloneProcessEngineConfiguration conf = new StandaloneProcessEngineConfiguration();
	conf.setDataSource(dataSource);
	conf.setDatabaseSchemaUpdate(databaseSchemaUpdate);
	conf.setJobExecutorActivate(jobExecutorActivate);
	return conf;
}
 
Example #17
Source File: RuntimeServiceTest.java    From camunda-bpm-platform 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.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/api/oneTaskProcess.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()
    .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();
}
 
Example #18
Source File: RepositoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {

    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration()
      .setProcessEngineName("reboot-test-schema")
      .setDatabaseSchemaUpdate(org.camunda.bpm.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.camunda.bpm.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/camunda/bpm/engine/test/api/repository/RepositoryServiceTest.testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.v1.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/camunda/bpm/engine/test/api/repository/RepositoryServiceTest.testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.v2.bpmn20.xml")
      .deploy()
      .getId();

    // Start process instance on second process engine -> must use revised process definition
    processDefinitionId = 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 #19
Source File: SequentialJobAcquisitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testExecuteJobsForTwoEnginesSameAcquisition() {
  // configure and build a process engine
  StandaloneProcessEngineConfiguration engineConfiguration1 = new StandaloneInMemProcessEngineConfiguration();
  engineConfiguration1.setProcessEngineName(getClass().getName() + "-engine1");
  engineConfiguration1.setJdbcUrl("jdbc:h2:mem:activiti1");
  engineConfiguration1.setJobExecutorActivate(false);
  engineConfiguration1.setJobExecutor(jobExecutor);
  engineConfiguration1.setDbMetricsReporterActivate(false);
  ProcessEngine engine1 = engineConfiguration1.buildProcessEngine();
  createdProcessEngines.add(engine1);

  // and a second one
  StandaloneProcessEngineConfiguration engineConfiguration2 = new StandaloneInMemProcessEngineConfiguration();
  engineConfiguration2.setProcessEngineName(getClass().getName() + "engine2");
  engineConfiguration2.setJdbcUrl("jdbc:h2:mem:activiti2");
  engineConfiguration2.setJobExecutorActivate(false);
  engineConfiguration2.setJobExecutor(jobExecutor);
  engineConfiguration2.setDbMetricsReporterActivate(false);
  ProcessEngine engine2 = engineConfiguration2.buildProcessEngine();
  createdProcessEngines.add(engine2);

  // stop the acquisition
  jobExecutor.shutdown();

  // deploy the processes

  engine1.getRepositoryService().createDeployment()
    .addClasspathResource(PROCESS_RESOURCE)
    .deploy();

  engine2.getRepositoryService().createDeployment()
   .addClasspathResource(PROCESS_RESOURCE)
   .deploy();

  // start one instance for each engine:

  engine1.getRuntimeService().startProcessInstanceByKey("intermediateTimerEventExample");
  engine2.getRuntimeService().startProcessInstanceByKey("intermediateTimerEventExample");

  Assert.assertEquals(1, engine1.getManagementService().createJobQuery().count());
  Assert.assertEquals(1, engine2.getManagementService().createJobQuery().count());

  Calendar calendar = Calendar.getInstance();
  calendar.add(Field.DAY_OF_YEAR.getCalendarField(), 6);
  ClockUtil.setCurrentTime(calendar.getTime());

  jobExecutor.start();
  // assert task completed for the first engine
  waitForJobExecutorToProcessAllJobs(10000, 100, jobExecutor, engine1.getManagementService(), true);

  jobExecutor.start();
  // assert task completed for the second engine
  waitForJobExecutorToProcessAllJobs(10000, 100, jobExecutor, engine2.getManagementService(), true);

  Assert.assertEquals(0, engine1.getManagementService().createJobQuery().count());
  Assert.assertEquals(0, engine2.getManagementService().createJobQuery().count());
}
 
Example #20
Source File: SequentialJobAcquisitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testJobAddedGuardForTwoEnginesSameAcquisition() throws InterruptedException {
 // configure and build a process engine
  StandaloneProcessEngineConfiguration engineConfiguration1 = new StandaloneInMemProcessEngineConfiguration();
  engineConfiguration1.setProcessEngineName(getClass().getName() + "-engine1");
  engineConfiguration1.setJdbcUrl("jdbc:h2:mem:activiti1");
  engineConfiguration1.setJobExecutorActivate(false);
  engineConfiguration1.setJobExecutor(jobExecutor);
  engineConfiguration1.setDbMetricsReporterActivate(false);
  ProcessEngine engine1 = engineConfiguration1.buildProcessEngine();
  createdProcessEngines.add(engine1);

  // and a second one
  StandaloneProcessEngineConfiguration engineConfiguration2 = new StandaloneInMemProcessEngineConfiguration();
  engineConfiguration2.setProcessEngineName(getClass().getName() + "engine2");
  engineConfiguration2.setJdbcUrl("jdbc:h2:mem:activiti2");
  engineConfiguration2.setJobExecutorActivate(false);
  engineConfiguration2.setJobExecutor(jobExecutor);
  engineConfiguration2.setDbMetricsReporterActivate(false);
  ProcessEngine engine2 = engineConfiguration2.buildProcessEngine();
  createdProcessEngines.add(engine2);

  // stop the acquisition
  jobExecutor.shutdown();

  // deploy the processes

  engine1.getRepositoryService().createDeployment()
    .addClasspathResource(PROCESS_RESOURCE)
    .deploy();

  engine2.getRepositoryService().createDeployment()
   .addClasspathResource(PROCESS_RESOURCE)
   .deploy();

  // start one instance for each engine:

  engine1.getRuntimeService().startProcessInstanceByKey("intermediateTimerEventExample");
  engine2.getRuntimeService().startProcessInstanceByKey("intermediateTimerEventExample");

  Calendar calendar = Calendar.getInstance();
  calendar.add(Field.DAY_OF_YEAR.getCalendarField(), 6);
  ClockUtil.setCurrentTime(calendar.getTime());

  Assert.assertEquals(1, engine1.getManagementService().createJobQuery().count());
  Assert.assertEquals(1, engine2.getManagementService().createJobQuery().count());

  // assert task completed for the first engine
  jobExecutor.start();
  waitForJobExecutorToProcessAllJobs(10000, 100, jobExecutor, engine1.getManagementService(), false);

  // assert task completed for the second engine
  jobExecutor.start();
  waitForJobExecutorToProcessAllJobs(10000, 100, jobExecutor, engine2.getManagementService(), false);

  Thread.sleep(2000);

  Assert.assertFalse(((SequentialJobAcquisitionRunnable) jobExecutor.getAcquireJobsRunnable()).isJobAdded());

  Assert.assertEquals(0, engine1.getManagementService().createJobQuery().count());
  Assert.assertEquals(0, engine2.getManagementService().createJobQuery().count());
}
 
Example #21
Source File: AuthorizationCheckRevokesCfgTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testAutoIsDefault() {
  assertEquals(ProcessEngineConfiguration.AUTHORIZATION_CHECK_REVOKE_AUTO, new StandaloneProcessEngineConfiguration().getAuthorizationCheckRevokes());
}
 
Example #22
Source File: StartProcessEngineStep.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void performOperationStep(DeploymentOperation operationContext) {

    final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
    final AbstractProcessApplication processApplication = operationContext.getAttachment(PROCESS_APPLICATION);

    ClassLoader classLoader = null;

    if(processApplication != null) {
      classLoader = processApplication.getProcessApplicationClassloader();
    }

    String configurationClassName = processEngineXml.getConfigurationClass();

    if(configurationClassName == null || configurationClassName.isEmpty()) {
      configurationClassName = StandaloneProcessEngineConfiguration.class.getName();
    }

    // create & instantiate configuration class
    Class<? extends ProcessEngineConfigurationImpl> configurationClass = loadClass(configurationClassName, classLoader, ProcessEngineConfigurationImpl.class);
    ProcessEngineConfigurationImpl configuration = createInstance(configurationClass);

    // set UUid generator
    // TODO: move this to configuration and use as default?
    ProcessEngineConfigurationImpl configurationImpl = configuration;
    configurationImpl.setIdGenerator(new StrongUuidGenerator());

    // set configuration values
    String name = processEngineXml.getName();
    configuration.setProcessEngineName(name);

    String datasourceJndiName = processEngineXml.getDatasource();
    configuration.setDataSourceJndiName(datasourceJndiName);

    // apply properties
    Map<String, String> properties = processEngineXml.getProperties();
    setJobExecutorActivate(configuration, properties);
    PropertyHelper.applyProperties(configuration, properties);

    // instantiate plugins:
    configurePlugins(configuration, processEngineXml, classLoader);

    if(processEngineXml.getJobAcquisitionName() != null && !processEngineXml.getJobAcquisitionName().isEmpty()) {
      JobExecutor jobExecutor = getJobExecutorService(serviceContainer);
      ensureNotNull("Cannot find referenced job executor with name '" + processEngineXml.getJobAcquisitionName() + "'", "jobExecutor", jobExecutor);

      // set JobExecutor on process engine
      configurationImpl.setJobExecutor(jobExecutor);
    }

    // start the process engine inside the container.
    JmxManagedProcessEngine managedProcessEngineService = createProcessEngineControllerInstance(configuration);
    serviceContainer.startService(ServiceTypes.PROCESS_ENGINE, configuration.getProcessEngineName(), managedProcessEngineService);

  }
 
Example #23
Source File: ProcessEngineConfiguration.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public static ProcessEngineConfiguration createStandaloneProcessEngineConfiguration() {
  return new StandaloneProcessEngineConfiguration();
}