use of org.apache.ibatis.datasource.pooled.PooledDataSource in project mybatis-3 by mybatis.
the class PooledDataSourceTest method shouldReconnectWhenServerKilledLeakedConnection.
@Ignore("See the comments")
@Test
public void shouldReconnectWhenServerKilledLeakedConnection() throws Exception {
// See #748
// Requirements:
// 1. MySQL JDBC driver dependency.
// 2. MySQL server instance with the following.
// - CREATE DATABASE `test`;
// - SET GLOBAL wait_timeout=3;
// 3. Tweak the connection info below.
final String URL = "jdbc:mysql://localhost:3306/test";
final String USERNAME = "admin";
final String PASSWORD = "";
Connection con;
PooledDataSource ds = new PooledDataSource();
ds.setDriver("com.mysql.jdbc.Driver");
ds.setUrl(URL);
ds.setUsername(USERNAME);
ds.setPassword(PASSWORD);
ds.setPoolMaximumActiveConnections(1);
ds.setPoolMaximumIdleConnections(1);
ds.setPoolTimeToWait(1000);
ds.setPoolMaximumCheckoutTime(2000);
ds.setPoolPingEnabled(true);
ds.setPoolPingQuery("select 1");
ds.setDefaultAutoCommit(true);
// MySQL wait_timeout * 1000 or less. (unit:ms)
ds.setPoolPingConnectionsNotUsedFor(1000);
con = ds.getConnection();
exexuteQuery(con);
// Simulate connection leak by not closing.
// con.close();
// Wait for disconnected from mysql...
Thread.sleep(TimeUnit.SECONDS.toMillis(3));
// Should return usable connection.
con = ds.getConnection();
exexuteQuery(con);
con.close();
}
use of org.apache.ibatis.datasource.pooled.PooledDataSource in project mybatis-3 by mybatis.
the class PooledDataSourceTest method ShouldReturnRealConnection.
@Test
public void ShouldReturnRealConnection() throws Exception {
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
Connection c = ds.getConnection();
JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c);
}
use of org.apache.ibatis.datasource.pooled.PooledDataSource in project Activiti by Activiti.
the class ConnectionPoolTest method testMyBatisConnectionPoolProperlyConfigured.
public void testMyBatisConnectionPoolProperlyConfigured() {
ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/engine/test/db/connection-pool.activiti.cfg.xml");
config.buildProcessEngine();
// Expected values
int maxActive = 25;
int maxIdle = 10;
int maxCheckoutTime = 30000;
int maxWaitTime = 25000;
assertEquals(maxActive, config.getJdbcMaxActiveConnections());
assertEquals(maxIdle, config.getJdbcMaxIdleConnections());
assertEquals(maxCheckoutTime, config.getJdbcMaxCheckoutTime());
assertEquals(maxWaitTime, config.getJdbcMaxWaitTime());
// Verify that these properties are correctly set in the MyBatis datasource
DataSource datasource = config.getDbSqlSessionFactory().getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource();
assertTrue(datasource instanceof PooledDataSource);
PooledDataSource pooledDataSource = (PooledDataSource) datasource;
assertEquals(maxActive, pooledDataSource.getPoolMaximumActiveConnections());
assertEquals(maxIdle, pooledDataSource.getPoolMaximumIdleConnections());
assertEquals(maxCheckoutTime, pooledDataSource.getPoolMaximumCheckoutTime());
assertEquals(maxWaitTime, pooledDataSource.getPoolTimeToWait());
}
Aggregations