Java Code Examples for org.apache.ibatis.datasource.pooled.PooledDataSource#forceCloseAll()
The following examples show how to use
org.apache.ibatis.datasource.pooled.PooledDataSource#forceCloseAll() .
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: TaskanaEngineTestConfiguration.java From taskana with Apache License 2.0 | 6 votes |
/** * create Default Datasource for in-memory database. * * @return the default datasource. */ private static DataSource createDefaultDataSource() { // JdbcDataSource ds = new JdbcDataSource(); // ds.setURL("jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0"); // ds.setPassword("sa"); // ds.setUser("sa"); String jdbcDriver = "org.h2.Driver"; String jdbcUrl = "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;" + "INIT=CREATE SCHEMA IF NOT EXISTS TASKANA\\;" + "SET COLLATION DEFAULT_de_DE "; String dbUserName = "sa"; String dbPassword = "sa"; PooledDataSource ds = new PooledDataSource( Thread.currentThread().getContextClassLoader(), jdbcDriver, jdbcUrl, dbUserName, dbPassword); ds.setPoolTimeToWait(POOL_TIME_TO_WAIT); ds.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly return ds; }
Example 2
Source File: AbstractAccTest.java From taskana with Apache License 2.0 | 6 votes |
/** * create Default DataSource for in-memory database. * * @return the TASKANA default datasource. */ private static DataSource createDefaultDataSource() { String jdbcDriver = "org.h2.Driver"; String jdbcUrl = "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0"; String dbUserName = "sa"; String dbPassword = "sa"; PooledDataSource ds = new PooledDataSource( Thread.currentThread().getContextClassLoader(), jdbcDriver, jdbcUrl, dbUserName, dbPassword); ds.setPoolTimeToWait(POOL_TIME_TO_WAIT); ds.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly return ds; }
Example 3
Source File: ForceCloseMybatisConnectionPoolTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the AbstractEngineConfiguration is configured with forceCloseMybatisConnectionPool = false StandaloneInMemDmnEngineConfiguration standaloneInMemDmnEngineConfiguration = new StandaloneInMemDmnEngineConfiguration(); standaloneInMemDmnEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-dmn-" + this.getClass().getName()); standaloneInMemDmnEngineConfiguration.setForceCloseMybatisConnectionPool(false); DmnEngine dmnEngine = standaloneInMemDmnEngineConfiguration.buildDmnEngine(); PooledDataSource pooledDataSource = (PooledDataSource) standaloneInMemDmnEngineConfiguration.getDataSource(); PoolState state = pooledDataSource.getPoolState(); assertThat(state.getIdleConnectionCount()).isPositive(); // then // if the engine is closed dmnEngine.close(); // the idle connections are not closed assertThat(state.getIdleConnectionCount()).isPositive(); pooledDataSource.forceCloseAll(); assertThat(state.getIdleConnectionCount()).isZero(); }
Example 4
Source File: ForceCloseMybatisConnectionPoolTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the AbstractEngineConfiguration is configured with forceCloseMybatisConnectionPool = false StandaloneInMemIdmEngineConfiguration standaloneInMemIdmEngineConfiguration = new StandaloneInMemIdmEngineConfiguration(); standaloneInMemIdmEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-idm-" + this.getClass().getName()); standaloneInMemIdmEngineConfiguration.setForceCloseMybatisConnectionPool(false); standaloneInMemIdmEngineConfiguration.setDatabaseSchemaUpdate("drop-create"); IdmEngine idmEngine = standaloneInMemIdmEngineConfiguration.buildIdmEngine(); PooledDataSource pooledDataSource = (PooledDataSource) standaloneInMemIdmEngineConfiguration.getDataSource(); PoolState state = pooledDataSource.getPoolState(); assertThat(state.getIdleConnectionCount()).isPositive(); // then // if the engine is closed idmEngine.close(); // the idle connections are not closed assertThat(state.getIdleConnectionCount()).isPositive(); pooledDataSource.forceCloseAll(); assertThat(state.getIdleConnectionCount()).isZero(); }
Example 5
Source File: ForceCloseMybatisConnectionPoolTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the AbstractEngineConfiguration is configured with forceCloseMybatisConnectionPool = false StandaloneInMemCmmnEngineConfiguration standaloneInMemCmmnEngineConfiguration = new StandaloneInMemCmmnEngineConfiguration(); standaloneInMemCmmnEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-cmmn-" + this.getClass().getName()); standaloneInMemCmmnEngineConfiguration.setForceCloseMybatisConnectionPool(false); standaloneInMemCmmnEngineConfiguration.buildCmmnEngine(); PooledDataSource pooledDataSource = (PooledDataSource) standaloneInMemCmmnEngineConfiguration.getDataSource(); PoolState state = pooledDataSource.getPoolState(); assertThat(state.getIdleConnectionCount()).isPositive(); // then // if the engine is closed standaloneInMemCmmnEngineConfiguration.close(); // the idle connections are not closed assertThat(state.getIdleConnectionCount()).isPositive(); pooledDataSource.forceCloseAll(); assertThat(state.getIdleConnectionCount()).isZero(); }
Example 6
Source File: ForceCloseMybatisConnectionPoolTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the process engine is configured with forceCloseMybatisConnectionPool = false StandaloneInMemProcessEngineConfiguration standaloneInMemProcessEngineConfiguration = new StandaloneInMemProcessEngineConfiguration(); standaloneInMemProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-bpmn-" + this.getClass().getName()); standaloneInMemProcessEngineConfiguration.setForceCloseMybatisConnectionPool(false); ProcessEngine processEngine = standaloneInMemProcessEngineConfiguration.buildProcessEngine(); PooledDataSource pooledDataSource = (PooledDataSource) standaloneInMemProcessEngineConfiguration.getDataSource(); PoolState state = pooledDataSource.getPoolState(); assertThat(state.getIdleConnectionCount()).isGreaterThan(0); // then // if the process engine is closed processEngine.close(); // the idle connections are not closed assertThat(state.getIdleConnectionCount()).isGreaterThan(0); pooledDataSource.forceCloseAll(); assertThat(state.getIdleConnectionCount()).isZero(); }
Example 7
Source File: ForceCloseMybatisConnectionPoolTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the AbstractEngineConfiguration is configured with forceCloseMybatisConnectionPool = false StandaloneInMemAppEngineConfiguration appEngineConfiguration = new StandaloneInMemAppEngineConfiguration(); appEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-app-" + this.getClass().getName()); appEngineConfiguration.setForceCloseMybatisConnectionPool(false); AppEngine appEngine = appEngineConfiguration.buildAppEngine(); PooledDataSource pooledDataSource = (PooledDataSource) appEngineConfiguration.getDataSource(); PoolState state = pooledDataSource.getPoolState(); assertThat(state.getIdleConnectionCount()).isPositive(); // then // if the engine is closed appEngine.close(); // the idle connections are not closed assertThat(state.getIdleConnectionCount()).isPositive(); pooledDataSource.forceCloseAll(); assertThat(state.getIdleConnectionCount()).isZero(); }
Example 8
Source File: ForceCloseMybatisConnectionPoolTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the AbstractEngineConfiguration is configured with forceCloseMybatisConnectionPool = false StandaloneInMemFormEngineConfiguration standaloneInMemFormEngineConfiguration = new StandaloneInMemFormEngineConfiguration(); standaloneInMemFormEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-form-" + this.getClass().getName()); standaloneInMemFormEngineConfiguration.setForceCloseMybatisConnectionPool(false); FormEngine formEngine = standaloneInMemFormEngineConfiguration.buildFormEngine(); PooledDataSource pooledDataSource = (PooledDataSource) standaloneInMemFormEngineConfiguration.getDataSource(); PoolState state = pooledDataSource.getPoolState(); assertThat(state.getIdleConnectionCount()).isPositive(); // then // if the engine is closed formEngine.close(); // the idle connections are not closed assertThat(state.getIdleConnectionCount()).isPositive(); pooledDataSource.forceCloseAll(); assertThat(state.getIdleConnectionCount()).isZero(); }
Example 9
Source File: ForceCloseMybatisConnectionPoolTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the AbstractEngineConfiguration is configured with forceCloseMybatisConnectionPool = false StandaloneInMemContentEngineConfiguration standaloneInMemContentEngineConfiguration = new StandaloneInMemContentEngineConfiguration(); standaloneInMemContentEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable-content-" + this.getClass().getName()); standaloneInMemContentEngineConfiguration.setForceCloseMybatisConnectionPool(false); ContentEngine contentEngine = standaloneInMemContentEngineConfiguration.buildContentEngine(); PooledDataSource pooledDataSource = (PooledDataSource) standaloneInMemContentEngineConfiguration.getDataSource(); PoolState state = pooledDataSource.getPoolState(); assertThat(state.getIdleConnectionCount()).isPositive(); // then // if the engine is closed contentEngine.close(); // the idle connections are not closed assertThat(state.getIdleConnectionCount()).isPositive(); pooledDataSource.forceCloseAll(); assertThat(state.getIdleConnectionCount()).isEqualTo(0); }
Example 10
Source File: SampleDataGeneratorTest.java From taskana with Apache License 2.0 | 5 votes |
@Test void getScriptsValidSql() { PooledDataSource pooledDataSource = new PooledDataSource("org.h2.Driver", JDBC_URL, "sa", "sa"); assertThatCode(() -> new DbSchemaCreator(pooledDataSource, "TASKANA").run()) .doesNotThrowAnyException(); assertThatCode(() -> new SampleDataGenerator(pooledDataSource, "TASKANA").generateSampleData()) .doesNotThrowAnyException(); pooledDataSource.forceCloseAll(); }
Example 11
Source File: SampleDataGeneratorTest.java From taskana with Apache License 2.0 | 5 votes |
@Test void tableExists() { PooledDataSource pooledDataSource = new PooledDataSource("org.h2.Driver", JDBC_URL, "sa", "sa"); assertThatCode(() -> new DbSchemaCreator(pooledDataSource, "TASKANA").run()) .doesNotThrowAnyException(); SampleDataGenerator sampleDataGenerator = new SampleDataGenerator(pooledDataSource, "TASKANA"); assertThat(sampleDataGenerator.tableExists("TASK")).isTrue(); assertThat(sampleDataGenerator.tableExists("TASKRANDOM")).isFalse(); pooledDataSource.forceCloseAll(); }
Example 12
Source File: PooledDataSourceTest.java From mybaties with Apache License 2.0 | 5 votes |
@Test public void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); try { runScript(ds, JPETSTORE_DDL); ds.setDefaultAutoCommit(false); ds.setDriverProperties(new Properties() { { setProperty("username", "sa"); setProperty("password", ""); } }); ds.setPoolMaximumActiveConnections(3); ds.setPoolMaximumIdleConnections(2); ds.setPoolMaximumCheckoutTime(10000); ds.setPoolPingConnectionsNotUsedFor(1); ds.setPoolPingEnabled(true); ds.setPoolPingQuery("SELECT * FROM PRODUCT"); ds.setPoolTimeToWait(10000); ds.setLogWriter(null); List<Connection> connections = new ArrayList<Connection>(); for (int i = 0; i < 3; i++) { connections.add(ds.getConnection()); } assertEquals(3, ds.getPoolState().getActiveConnectionCount()); for (Connection c : connections) { c.close(); } assertEquals(2, ds.getPoolState().getIdleConnectionCount()); assertEquals(4, ds.getPoolState().getRequestCount()); assertEquals(0, ds.getPoolState().getBadConnectionCount()); assertEquals(0, ds.getPoolState().getHadToWaitCount()); assertEquals(0, ds.getPoolState().getAverageOverdueCheckoutTime()); assertEquals(0, ds.getPoolState().getClaimedOverdueConnectionCount()); assertEquals(0, ds.getPoolState().getAverageWaitTime()); assertNotNull(ds.getPoolState().toString()); } finally { ds.forceCloseAll(); } }
Example 13
Source File: ScriptRunnerTest.java From mybaties with Apache License 2.0 | 5 votes |
private void assertProductsTableExistsAndLoaded() throws IOException, SQLException { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); try { Connection conn = ds.getConnection(); SqlRunner executor = new SqlRunner(conn); List<Map<String, Object>> products = executor.selectAll("SELECT * FROM PRODUCT"); assertEquals(16, products.size()); } finally { ds.forceCloseAll(); } }
Example 14
Source File: PooledDataSourceTest.java From mybatis with Apache License 2.0 | 5 votes |
@Test public void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); try { runScript(ds, JPETSTORE_DDL); ds.setDefaultAutoCommit(false); ds.setDriverProperties(new Properties() { { setProperty("username", "sa"); setProperty("password", ""); } }); ds.setPoolMaximumActiveConnections(3); ds.setPoolMaximumIdleConnections(2); ds.setPoolMaximumCheckoutTime(10000); ds.setPoolPingConnectionsNotUsedFor(1); ds.setPoolPingEnabled(true); ds.setPoolPingQuery("SELECT * FROM PRODUCT"); ds.setPoolTimeToWait(10000); ds.setLogWriter(null); List<Connection> connections = new ArrayList<Connection>(); for (int i = 0; i < 3; i++) { connections.add(ds.getConnection()); } assertEquals(3, ds.getPoolState().getActiveConnectionCount()); for (Connection c : connections) { c.close(); } assertEquals(2, ds.getPoolState().getIdleConnectionCount()); assertEquals(4, ds.getPoolState().getRequestCount()); assertEquals(0, ds.getPoolState().getBadConnectionCount()); assertEquals(0, ds.getPoolState().getHadToWaitCount()); assertEquals(0, ds.getPoolState().getAverageOverdueCheckoutTime()); assertEquals(0, ds.getPoolState().getClaimedOverdueConnectionCount()); assertEquals(0, ds.getPoolState().getAverageWaitTime()); assertNotNull(ds.getPoolState().toString()); } finally { ds.forceCloseAll(); } }
Example 15
Source File: ScriptRunnerTest.java From mybatis with Apache License 2.0 | 5 votes |
private void assertProductsTableExistsAndLoaded() throws IOException, SQLException { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); try { Connection conn = ds.getConnection(); SqlRunner executor = new SqlRunner(conn); List<Map<String, Object>> products = executor.selectAll("SELECT * FROM PRODUCT"); assertEquals(16, products.size()); } finally { ds.forceCloseAll(); } }
Example 16
Source File: ForceCloseMybatisConnectionPoolTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testForceCloseMybatisConnectionPoolFalse() { // given // that the process engine is configured with forceCloseMybatisConnectionPool = false ProcessEngineConfigurationImpl configurationImpl = new StandaloneInMemProcessEngineConfiguration() .setJdbcUrl("jdbc:h2:mem:camunda-forceclose") .setProcessEngineName("engine-forceclose") .setForceCloseMybatisConnectionPool(false); ProcessEngine processEngine = configurationImpl .buildProcessEngine(); PooledDataSource pooledDataSource = (PooledDataSource) configurationImpl.getDataSource(); PoolState state = pooledDataSource.getPoolState(); int idleConnections = state.getIdleConnectionCount(); // then // if the process engine is closed processEngine.close(); // the idle connections are not closed Assert.assertEquals(state.getIdleConnectionCount(), idleConnections); pooledDataSource.forceCloseAll(); Assert.assertTrue(state.getIdleConnectionCount() == 0); }