Example usage for org.apache.commons.dbcp.datasources SharedPoolDataSource isTestWhileIdle

List of usage examples for org.apache.commons.dbcp.datasources SharedPoolDataSource isTestWhileIdle

Introduction

In this page you can find the example usage for org.apache.commons.dbcp.datasources SharedPoolDataSource isTestWhileIdle.

Prototype

public final boolean isTestWhileIdle() 

Source Link

Usage

From source file:org.mybatis.guice.datasource.dbcp.SharedPoolDataSourceProviderTest.java

@Test
public void get() throws Throwable {
    final boolean autoCommit = true;
    final int loginTimeout = 10;
    final boolean defaultReadOnly = true;
    final int defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED;
    final String description = "test_description";
    final int minEvictableIdleTimeMillis = 30;
    final int numTestsPerEvictionRun = 40;
    final boolean rollbackAfterValidation = true;
    final boolean testOnBorrow = true;
    final boolean testOnReturn = true;
    final boolean testWhileIdle = true;
    final int timeBetweenEvictionRunsMillis = 50;
    final String validationQuery = "SELECT 1";
    final int maxActive = 60;
    final int maxIdle = 70;
    final int maxWait = 80;
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override/*  ww w  .  ja va  2s .  c  om*/
        protected void configure() {
            bind(ConnectionPoolDataSource.class).toInstance(connectionPoolDataSource);
            bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit);
            bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout);
            bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly);
            bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation"))
                    .to(defaultTransactionIsolation);
            bindConstant().annotatedWith(Names.named("DBCP.description")).to(description);
            bindConstant().annotatedWith(Names.named("DBCP.minEvictableIdleTimeMillis"))
                    .to(minEvictableIdleTimeMillis);
            bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun);
            bindConstant().annotatedWith(Names.named("DBCP.rollbackAfterValidation"))
                    .to(rollbackAfterValidation);
            bindConstant().annotatedWith(Names.named("DBCP.testOnBorrow")).to(testOnBorrow);
            bindConstant().annotatedWith(Names.named("DBCP.testOnReturn")).to(testOnReturn);
            bindConstant().annotatedWith(Names.named("DBCP.testWhileIdle")).to(testWhileIdle);
            bindConstant().annotatedWith(Names.named("DBCP.timeBetweenEvictionRunsMillis"))
                    .to(timeBetweenEvictionRunsMillis);
            bindConstant().annotatedWith(Names.named("DBCP.validationQuery")).to(validationQuery);
            bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive);
            bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle);
            bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait);
        }
    });
    SharedPoolDataSourceProvider provider = injector.getInstance(SharedPoolDataSourceProvider.class);

    SharedPoolDataSource dataSource = (SharedPoolDataSource) provider.get();

    assertEquals(connectionPoolDataSource, dataSource.getConnectionPoolDataSource());
    assertEquals(autoCommit, dataSource.isDefaultAutoCommit());
    assertEquals(defaultReadOnly, dataSource.isDefaultReadOnly());
    assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation());
    assertEquals(description, dataSource.getDescription());
    assertEquals(loginTimeout, dataSource.getLoginTimeout());
    assertEquals(minEvictableIdleTimeMillis, dataSource.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun());
    assertEquals(rollbackAfterValidation, dataSource.isRollbackAfterValidation());
    assertEquals(testOnBorrow, dataSource.isTestOnBorrow());
    assertEquals(testOnReturn, dataSource.isTestOnReturn());
    assertEquals(testWhileIdle, dataSource.isTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis());
    assertEquals(validationQuery, dataSource.getValidationQuery());
    assertEquals(maxActive, dataSource.getMaxActive());
    assertEquals(maxIdle, dataSource.getMaxIdle());
    assertEquals(maxWait, dataSource.getMaxWait());
}

From source file:org.mybatis.guice.datasource.dbcp.SharedPoolDataSourceProviderTest.java

@Test
public void get_OtherValues() throws Throwable {
    final boolean autoCommit = false;
    final int loginTimeout = 11;
    final boolean defaultReadOnly = false;
    final int defaultTransactionIsolation = Connection.TRANSACTION_REPEATABLE_READ;
    final String description = "test_description2";
    final int minEvictableIdleTimeMillis = 31;
    final int numTestsPerEvictionRun = 41;
    final boolean rollbackAfterValidation = false;
    final boolean testOnBorrow = false;
    final boolean testOnReturn = false;
    final boolean testWhileIdle = false;
    final int timeBetweenEvictionRunsMillis = 51;
    final String validationQuery = "SELECT 2";
    final int maxActive = 61;
    final int maxIdle = 71;
    final int maxWait = 81;
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override//w  w  w.ja v  a2s . co m
        protected void configure() {
            bind(ConnectionPoolDataSource.class).toInstance(connectionPoolDataSource);
            bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit);
            bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout);
            bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly);
            bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation"))
                    .to(defaultTransactionIsolation);
            bindConstant().annotatedWith(Names.named("DBCP.description")).to(description);
            bindConstant().annotatedWith(Names.named("DBCP.minEvictableIdleTimeMillis"))
                    .to(minEvictableIdleTimeMillis);
            bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun);
            bindConstant().annotatedWith(Names.named("DBCP.rollbackAfterValidation"))
                    .to(rollbackAfterValidation);
            bindConstant().annotatedWith(Names.named("DBCP.testOnBorrow")).to(testOnBorrow);
            bindConstant().annotatedWith(Names.named("DBCP.testOnReturn")).to(testOnReturn);
            bindConstant().annotatedWith(Names.named("DBCP.testWhileIdle")).to(testWhileIdle);
            bindConstant().annotatedWith(Names.named("DBCP.timeBetweenEvictionRunsMillis"))
                    .to(timeBetweenEvictionRunsMillis);
            bindConstant().annotatedWith(Names.named("DBCP.validationQuery")).to(validationQuery);
            bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive);
            bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle);
            bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait);
        }
    });
    SharedPoolDataSourceProvider provider = injector.getInstance(SharedPoolDataSourceProvider.class);

    SharedPoolDataSource dataSource = (SharedPoolDataSource) provider.get();

    assertEquals(connectionPoolDataSource, dataSource.getConnectionPoolDataSource());
    assertEquals(autoCommit, dataSource.isDefaultAutoCommit());
    assertEquals(defaultReadOnly, dataSource.isDefaultReadOnly());
    assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation());
    assertEquals(description, dataSource.getDescription());
    assertEquals(loginTimeout, dataSource.getLoginTimeout());
    assertEquals(minEvictableIdleTimeMillis, dataSource.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun());
    assertEquals(rollbackAfterValidation, dataSource.isRollbackAfterValidation());
    assertEquals(testOnBorrow, dataSource.isTestOnBorrow());
    assertEquals(testOnReturn, dataSource.isTestOnReturn());
    assertEquals(testWhileIdle, dataSource.isTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis());
    assertEquals(validationQuery, dataSource.getValidationQuery());
    assertEquals(maxActive, dataSource.getMaxActive());
    assertEquals(maxIdle, dataSource.getMaxIdle());
    assertEquals(maxWait, dataSource.getMaxWait());
}