Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testPerformDatabaseSchemaOperationCreateTwice() throws Exception
        public virtual void testPerformDatabaseSchemaOperationCreateTwice()
        {
            // both process engines will be using this datasource.
            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.ClassLoader, "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000", "sa", "");

            Connection connection = pooledDataSource.Connection;

            connection.createStatement().execute("drop schema if exists " + SCHEMA_NAME);
            connection.createStatement().execute("create schema " + SCHEMA_NAME);
            connection.close();

            ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK");

            config1.DatabaseTablePrefix       = SCHEMA_NAME + ".";
            config1.DatabaseSchema            = SCHEMA_NAME;
            config1.DbMetricsReporterActivate = false;
            ProcessEngine engine1 = config1.buildProcessEngine();

            // create the tables for the first time
            connection = pooledDataSource.Connection;
            connection.createStatement().execute("set schema " + SCHEMA_NAME);
            engine1.ManagementService.databaseSchemaUpgrade(connection, "", SCHEMA_NAME);
            connection.close();
            // create the tables for the second time; here we shouldn't crash since the
            // session should tell us that the tables are already present and
            // databaseSchemaUpdate is set to noop
            connection = pooledDataSource.Connection;
            connection.createStatement().execute("set schema " + SCHEMA_NAME);
            engine1.ManagementService.databaseSchemaUpgrade(connection, "", SCHEMA_NAME);
            engine1.close();
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPerformDatabaseSchemaOperationCreate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void shouldPerformDatabaseSchemaOperationCreate()
        {
            // both process engines will be using this datasource.
            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.ClassLoader, "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000", "sa", "");

            // create two schemas is the database
            Connection connection = pooledDataSource.Connection;

            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 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDbMetricsReporterActivate(false).setDatabaseSchemaUpdate("NO_CHECK");     // disable auto create/drop schema

            config1.DatabaseTablePrefix        = "SCHEMA1.";
            config1.UseSharedSqlSessionFactory = true;
            ProcessEngine engine1 = config1.buildProcessEngine();

            ProcessEngineConfigurationImpl config2 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine2").setDataSource(pooledDataSource).setDbMetricsReporterActivate(false).setDatabaseSchemaUpdate("NO_CHECK");     // disable auto create/drop schema

            config2.DatabaseTablePrefix        = "SCHEMA2.";
            config2.UseSharedSqlSessionFactory = true;
            ProcessEngine engine2 = config2.buildProcessEngine();

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

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

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

                assertEquals(1, engine1.RepositoryService.createDeploymentQuery().count());
                assertEquals(0, engine2.RepositoryService.createDeploymentQuery().count());
            }
            finally
            {
                engine1.close();
                engine2.close();
                ProcessEngineConfigurationImpl.cachedSqlSessionFactory = null;
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testForceCloseMybatisConnectionPoolTrue()
        public virtual void testForceCloseMybatisConnectionPoolTrue()
        {
            // given
            // that the process engine is configured with forceCloseMybatisConnectionPool = true
            ProcessEngineConfigurationImpl configurationImpl = (new StandaloneInMemProcessEngineConfiguration()).setJdbcUrl("jdbc:h2:mem:camunda-forceclose").setProcessEngineName("engine-forceclose").setForceCloseMybatisConnectionPool(true);

            ProcessEngine processEngine = configurationImpl.buildProcessEngine();

            PooledDataSource pooledDataSource = (PooledDataSource)configurationImpl.DataSource;
            PoolState        state            = pooledDataSource.PoolState;


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

            // the idle connections are closed
            Assert.assertTrue(state.IdleConnectionCount == 0);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testTablePresentWithSchemaAndPrefix() throws java.sql.SQLException
        public virtual void testTablePresentWithSchemaAndPrefix()
        {
            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.ClassLoader, "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000", "sa", "");

            Connection connection = pooledDataSource.Connection;

            connection.createStatement().execute("drop schema if exists " + SCHEMA_NAME);
            connection.createStatement().execute("create schema " + SCHEMA_NAME);
            connection.createStatement().execute("create table " + SCHEMA_NAME + "." + PREFIX_NAME + "SOME_TABLE(id varchar(64));");
            connection.close();

            ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK");

            config1.DatabaseTablePrefix       = SCHEMA_NAME + "." + PREFIX_NAME;
            config1.DatabaseSchema            = SCHEMA_NAME;
            config1.DbMetricsReporterActivate = false;
            ProcessEngine   engine          = config1.buildProcessEngine();
            CommandExecutor commandExecutor = config1.CommandExecutorTxRequired;

            commandExecutor.execute(new CommandAnonymousInnerClass(this));

            engine.close();
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void afterPropertiesSet() throws Exception
        public virtual void afterPropertiesSet()
        {
            dataSource = new PooledDataSource(ReflectUtil.ClassLoader, "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000;MVCC=TRUE;", "sa", "");

            // create schema in the
            Connection connection = dataSource.Connection;

            connection.createStatement().execute("drop schema if exists SCHEMA1");
            connection.createStatement().execute("create schema SCHEMA1");
            connection.close();

            ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(dataSource).setDbMetricsReporterActivate(false).setDatabaseSchemaUpdate("NO_CHECK");     // disable auto create/drop schema

            config1.DatabaseTablePrefix = "SCHEMA1.";
            ProcessEngine engine1 = config1.buildProcessEngine();

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

            engine1.close();
        }
Esempio n. 6
0
        public virtual void testMyBatisConnectionPoolProperlyConfigured()
        {
            ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl)ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/camunda/bpm/engine/test/api/cfg/connection-pool.camunda.cfg.xml");

            ProcessEngine engine = config.buildProcessEngine();

            // Expected values
            int maxActive            = 25;
            int maxIdle              = 10;
            int maxCheckoutTime      = 30000;
            int maxWaitTime          = 25000;
            int?jdbcStatementTimeout = 300;

            assertEquals(maxActive, config.JdbcMaxActiveConnections);
            assertEquals(maxIdle, config.JdbcMaxIdleConnections);
            assertEquals(maxCheckoutTime, config.JdbcMaxCheckoutTime);
            assertEquals(maxWaitTime, config.JdbcMaxWaitTime);
            assertEquals(jdbcStatementTimeout, config.JdbcStatementTimeout);

            // Verify that these properties are correctly set in the MyBatis datasource
            Configuration sessionFactoryConfiguration = config.DbSqlSessionFactory.SqlSessionFactory.Configuration;
            DataSource    datasource = sessionFactoryConfiguration.Environment.DataSource;

            assertTrue(datasource is PooledDataSource);

            PooledDataSource pooledDataSource = (PooledDataSource)datasource;

            assertEquals(maxActive, pooledDataSource.PoolMaximumActiveConnections);
            assertEquals(maxIdle, pooledDataSource.PoolMaximumIdleConnections);
            assertEquals(maxCheckoutTime, pooledDataSource.PoolMaximumCheckoutTime);
            assertEquals(maxWaitTime, pooledDataSource.PoolTimeToWait);

            assertEquals(jdbcStatementTimeout, sessionFactoryConfiguration.DefaultStatementTimeout);

            engine.close();
        }