List of usage examples for org.apache.commons.dbcp BasicDataSource getNumTestsPerEvictionRun
public synchronized int getNumTestsPerEvictionRun()
From source file:com.funambol.server.db.DataSourceContextHelperTest.java
public void testconfigureAndBindDataSources() throws Throwable { DataSourceContextHelper.configureAndBindDataSources(); BasicDataSource dsFnblds = (BasicDataSource) DataSourceTools.lookupDataSource("jdbc/fnblds"); assertNotNull(dsFnblds);/*from w w w . j a v a 2 s .c o m*/ assertEquals("jdbc:hsqldb:hsql://localhost/funambol", dsFnblds.getUrl()); assertEquals("db", dsFnblds.getUsername()); assertEquals("", dsFnblds.getPassword()); assertEquals("org.hsqldb.jdbcDriver", dsFnblds.getDriverClassName()); BasicDataSource dsCore = (BasicDataSource) DataSourceTools.lookupDataSource("jdbc/fnblcore"); assertNotNull(dsCore); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", dsCore.getUrl()); assertEquals("db", dsCore.getUsername()); assertEquals("ss", dsCore.getPassword()); assertEquals("org.hsqldb.jdbcDriver", dsCore.getDriverClassName()); BasicDataSource dsUser = (BasicDataSource) DataSourceTools.lookupDataSource("jdbc/fnbluser"); assertNotNull(dsUser); assertEquals("jdbc:hsqldb:hsql://localhost/user", dsUser.getUrl()); assertEquals("fnbluserpwd", dsUser.getUsername()); assertEquals("fnblpwd", dsUser.getPassword()); assertEquals("org.fnbluser", dsUser.getDriverClassName()); // // This test is to verify that the case (lower or upper) of the configuration // file is taken in consideration // boolean found = true; BasicDataSource dsUserds2 = null; try { dsUserds2 = (BasicDataSource) DataSourceTools.lookupDataSource("jdbc/fnblUSER"); } catch (NameNotFoundException e) { found = false; } assertFalse(found); BasicDataSource dsUPPER = (BasicDataSource) DataSourceTools.lookupDataSource("jdbc/UPPERCASE"); assertNotNull(dsUPPER); assertEquals("jdbc:hsqldb:hsql://localhost/user", dsUPPER.getUrl()); assertEquals("fnbluserpwd", dsUPPER.getUsername()); assertEquals("fnblpwd", dsUPPER.getPassword()); assertEquals("org.fnbluser", dsUPPER.getDriverClassName()); // // This test is to verify that the case of the configuration file is taken // in consideration // found = true; BasicDataSource dsUPPER2 = null; try { dsUPPER2 = (BasicDataSource) DataSourceTools.lookupDataSource("jdbc/uppercase"); } catch (NameNotFoundException e) { found = false; } assertFalse(found); RoutingDataSource routingDS = (RoutingDataSource) DataSourceTools .lookupDataSource("jdbc/fnbluser-routing-with-partition"); routingDS.init(); routingDS.configure(); assertNotNull(routingDS); assertTrue(routingDS.getPartitioningCriteria() instanceof MockPartitioningCriteria); Map<String, DataSource> dataSources = (Map<String, DataSource>) PrivateAccessor.getField(routingDS, "dataSources"); assertTrue(dataSources.size() == 3); org.apache.tomcat.dbcp.dbcp.BasicDataSource ds1 = (org.apache.tomcat.dbcp.dbcp.BasicDataSource) dataSources .get("user_part1"); assertNotNull("user_part1 must be not null", ds1); assertEquals("sa", ds1.getUsername()); assertEquals("", ds1.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part1", ds1.getUrl()); assertEquals(15, ds1.getNumTestsPerEvictionRun()); // from db.xml org.apache.tomcat.dbcp.dbcp.BasicDataSource ds2 = (org.apache.tomcat.dbcp.dbcp.BasicDataSource) dataSources .get("user_part2"); assertNotNull("user_part2 must be not null", ds2); assertEquals("sa", ds2.getUsername()); assertEquals("", ds2.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part2", ds2.getUrl()); assertEquals(15, ds2.getNumTestsPerEvictionRun()); // from db.xml org.apache.tomcat.dbcp.dbcp.BasicDataSource ds3 = (org.apache.tomcat.dbcp.dbcp.BasicDataSource) dataSources .get("user_part3"); assertNotNull("user_part3 must be not null", ds3); assertEquals("sa", ds3.getUsername()); assertEquals("", ds3.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part3", ds3.getUrl()); assertEquals(15, ds3.getNumTestsPerEvictionRun()); // from db.xml }
From source file:org.alfresco.repo.tenant.TenantBasicDataSource.java
public TenantBasicDataSource(BasicDataSource bds, String tenantUrl, int tenantMaxActive) throws SQLException { // tenant-specific this.setUrl(tenantUrl); this.setMaxActive(tenantMaxActive == -1 ? bds.getMaxActive() : tenantMaxActive); // defaults/overrides - see also 'baseDefaultDataSource' (core-services-context.xml + repository.properties) this.setDriverClassName(bds.getDriverClassName()); this.setUsername(bds.getUsername()); this.setPassword(bds.getPassword()); this.setInitialSize(bds.getInitialSize()); this.setMinIdle(bds.getMinIdle()); this.setMaxIdle(bds.getMaxIdle()); this.setDefaultAutoCommit(bds.getDefaultAutoCommit()); this.setDefaultTransactionIsolation(bds.getDefaultTransactionIsolation()); this.setMaxWait(bds.getMaxWait()); this.setValidationQuery(bds.getValidationQuery()); this.setTimeBetweenEvictionRunsMillis(bds.getTimeBetweenEvictionRunsMillis()); this.setMinEvictableIdleTimeMillis(bds.getMinEvictableIdleTimeMillis()); this.setNumTestsPerEvictionRun(bds.getNumTestsPerEvictionRun()); this.setTestOnBorrow(bds.getTestOnBorrow()); this.setTestOnReturn(bds.getTestOnReturn()); this.setTestWhileIdle(bds.getTestWhileIdle()); this.setRemoveAbandoned(bds.getRemoveAbandoned()); this.setRemoveAbandonedTimeout(bds.getRemoveAbandonedTimeout()); this.setPoolPreparedStatements(bds.isPoolPreparedStatements()); this.setMaxOpenPreparedStatements(bds.getMaxOpenPreparedStatements()); this.setLogAbandoned(bds.getLogAbandoned()); }
From source file:org.mybatis.guice.datasource.dbcp.BasicDataSourceProviderTest.java
@Test public void get() throws Throwable { final String driver = "org.mybatis.guice.TestDriver"; final String url = "jdbc:h2:mem:testdb"; final String username = "test_user"; final String password = "test_password"; final boolean autoCommit = true; final Properties driverProperties = new Properties(); driverProperties.put("my_property", "true"); final boolean accessToUnderlyingConnectionAllowed = true; final String defaultCatalog = "test_catalog"; final boolean defaultReadOnly = true; final int defaultTransactionIsolation = 20; final int initialSize = 30; final int maxActive = 40; final int maxIdle = 50; final int maxOpenPreparedStatements = 60; final long maxWait = 70; final int minIdle = 80; final int numTestsPerEvictionRun = 90; final boolean poolPreparedStatements = true; final boolean testOnBorrow = true; final boolean testOnReturn = true; final boolean testWhileIdle = true; final int timeBetweenEvictionRunsMillis = 100; final String validationQuery = "SELECT 1"; Injector injector = Guice.createInjector(new AbstractModule() { @Override//from w w w . j a v a2s . c o m protected void configure() { bind(ClassLoader.class).annotatedWith(Names.named("JDBC.driverClassLoader")) .toInstance(driverClassLoader); bindConstant().annotatedWith(Names.named("JDBC.driver")).to(driver); bindConstant().annotatedWith(Names.named("JDBC.url")).to(url); bindConstant().annotatedWith(Names.named("JDBC.username")).to(username); bindConstant().annotatedWith(Names.named("JDBC.password")).to(password); bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit); bind(Properties.class).annotatedWith(Names.named("JDBC.driverProperties")) .toInstance(driverProperties); bindConstant().annotatedWith(Names.named("DBCP.accessToUnderlyingConnectionAllowed")) .to(accessToUnderlyingConnectionAllowed); bindConstant().annotatedWith(Names.named("DBCP.defaultCatalog")).to(defaultCatalog); bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly); bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation")) .to(defaultTransactionIsolation); bindConstant().annotatedWith(Names.named("DBCP.initialSize")).to(initialSize); bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive); bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle); bindConstant().annotatedWith(Names.named("DBCP.maxOpenPreparedStatements")) .to(maxOpenPreparedStatements); bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait); bindConstant().annotatedWith(Names.named("DBCP.minIdle")).to(minIdle); bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun); bindConstant().annotatedWith(Names.named("DBCP.poolPreparedStatements")).to(poolPreparedStatements); 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); } }); BasicDataSourceProvider provider = injector.getInstance(BasicDataSourceProvider.class); BasicDataSource dataSource = (BasicDataSource) provider.get(); assertEquals(driverClassLoader, dataSource.getDriverClassLoader()); assertEquals(driver, dataSource.getDriverClassName()); assertEquals(url, dataSource.getUrl()); assertEquals(username, dataSource.getUsername()); assertEquals(password, dataSource.getPassword()); assertEquals(autoCommit, dataSource.getDefaultAutoCommit()); // Cannot test driver properties. assertEquals(accessToUnderlyingConnectionAllowed, dataSource.isAccessToUnderlyingConnectionAllowed()); assertEquals(defaultCatalog, dataSource.getDefaultCatalog()); assertEquals(defaultReadOnly, dataSource.getDefaultReadOnly()); assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation()); assertEquals(initialSize, dataSource.getInitialSize()); assertEquals(maxActive, dataSource.getMaxActive()); assertEquals(maxIdle, dataSource.getMaxIdle()); assertEquals(maxOpenPreparedStatements, dataSource.getMaxOpenPreparedStatements()); assertEquals(maxWait, dataSource.getMaxWait()); assertEquals(minIdle, dataSource.getMinIdle()); assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun()); assertEquals(poolPreparedStatements, dataSource.isPoolPreparedStatements()); assertEquals(testOnBorrow, dataSource.getTestOnBorrow()); assertEquals(testOnReturn, dataSource.getTestOnReturn()); assertEquals(testWhileIdle, dataSource.getTestWhileIdle()); assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis()); assertEquals(validationQuery, dataSource.getValidationQuery()); }
From source file:org.mybatis.guice.datasource.dbcp.BasicDataSourceProviderTest.java
@Test public void get_OtherValues() throws Throwable { final String driver = "org.mybatis.guice.TestDriver2"; final String url = "jdbc:h2:mem:testdb2"; final String username = "test_user2"; final String password = "test_password2"; final boolean autoCommit = false; final Properties driverProperties = new Properties(); driverProperties.put("my_property", "false"); final boolean accessToUnderlyingConnectionAllowed = false; final String defaultCatalog = "test_catalog2"; final boolean defaultReadOnly = false; final int defaultTransactionIsolation = 21; final int initialSize = 31; final int maxActive = 41; final int maxIdle = 51; final int maxOpenPreparedStatements = 61; final long maxWait = 71; final int minIdle = 81; final int numTestsPerEvictionRun = 91; final boolean poolPreparedStatements = false; final boolean testOnBorrow = false; final boolean testOnReturn = false; final boolean testWhileIdle = false; final int timeBetweenEvictionRunsMillis = 101; final String validationQuery = "SELECT 2"; Injector injector = Guice.createInjector(new AbstractModule() { @Override//from w w w . ja v a 2 s . c o m protected void configure() { bind(ClassLoader.class).annotatedWith(Names.named("JDBC.driverClassLoader")) .toInstance(driverClassLoader); bindConstant().annotatedWith(Names.named("JDBC.driver")).to(driver); bindConstant().annotatedWith(Names.named("JDBC.url")).to(url); bindConstant().annotatedWith(Names.named("JDBC.username")).to(username); bindConstant().annotatedWith(Names.named("JDBC.password")).to(password); bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit); bind(Properties.class).annotatedWith(Names.named("JDBC.driverProperties")) .toInstance(driverProperties); bindConstant().annotatedWith(Names.named("DBCP.accessToUnderlyingConnectionAllowed")) .to(accessToUnderlyingConnectionAllowed); bindConstant().annotatedWith(Names.named("DBCP.defaultCatalog")).to(defaultCatalog); bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly); bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation")) .to(defaultTransactionIsolation); bindConstant().annotatedWith(Names.named("DBCP.initialSize")).to(initialSize); bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive); bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle); bindConstant().annotatedWith(Names.named("DBCP.maxOpenPreparedStatements")) .to(maxOpenPreparedStatements); bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait); bindConstant().annotatedWith(Names.named("DBCP.minIdle")).to(minIdle); bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun); bindConstant().annotatedWith(Names.named("DBCP.poolPreparedStatements")).to(poolPreparedStatements); 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); } }); BasicDataSourceProvider provider = injector.getInstance(BasicDataSourceProvider.class); BasicDataSource dataSource = (BasicDataSource) provider.get(); assertEquals(driverClassLoader, dataSource.getDriverClassLoader()); assertEquals(driver, dataSource.getDriverClassName()); assertEquals(url, dataSource.getUrl()); assertEquals(username, dataSource.getUsername()); assertEquals(password, dataSource.getPassword()); assertEquals(autoCommit, dataSource.getDefaultAutoCommit()); // Cannot test driver properties. assertEquals(accessToUnderlyingConnectionAllowed, dataSource.isAccessToUnderlyingConnectionAllowed()); assertEquals(defaultCatalog, dataSource.getDefaultCatalog()); assertEquals(defaultReadOnly, dataSource.getDefaultReadOnly()); assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation()); assertEquals(initialSize, dataSource.getInitialSize()); assertEquals(maxActive, dataSource.getMaxActive()); assertEquals(maxIdle, dataSource.getMaxIdle()); assertEquals(maxOpenPreparedStatements, dataSource.getMaxOpenPreparedStatements()); assertEquals(maxWait, dataSource.getMaxWait()); assertEquals(minIdle, dataSource.getMinIdle()); assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun()); assertEquals(poolPreparedStatements, dataSource.isPoolPreparedStatements()); assertEquals(testOnBorrow, dataSource.getTestOnBorrow()); assertEquals(testOnReturn, dataSource.getTestOnReturn()); assertEquals(testWhileIdle, dataSource.getTestWhileIdle()); assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis()); assertEquals(validationQuery, dataSource.getValidationQuery()); }