/** * Mostly for code coverage. * * @throws IOException * @throws NoSuchMethodException * @throws SecurityException * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws ClassNotFoundException */ @Test public void testDataSource() throws SQLException, IOException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { config.setAcquireIncrement(5); config.setMinConnectionsPerPartition(30); config.setMaxConnectionsPerPartition(100); config.setPartitionCount(1); BoneCPDataSource dsb = new BoneCPDataSource(config); dsb.setPartitionCount(1); dsb.setAcquireRetryDelay(-1); dsb.setAcquireRetryAttempts(0); dsb.setMaxConnectionsPerPartition(100); dsb.setMinConnectionsPerPartition(30); dsb.setTransactionRecoveryEnabled(true); dsb.setConnectionHook(new CoverageHook()); dsb.setLazyInit(false); dsb.setStatementsCachedPerConnection(30); dsb.setStatementsCacheSize(30); dsb.setReleaseHelperThreads(0); dsb.setDriverClass("com.jolbox.bonecp.MockJDBCDriver"); dsb.isWrapperFor(String.class); dsb.setIdleMaxAge(0L); dsb.setAcquireIncrement(5); dsb.setIdleConnectionTestPeriod(0L); dsb.setConnectionTestStatement("test"); dsb.setInitSQL(CommonTestUtils.TEST_QUERY); dsb.setCloseConnectionWatch(true); dsb.setLogStatementsEnabled(false); dsb.getConnection().close(); assertNotNull(dsb.getConfig()); assertNotNull(dsb.toString()); dsb.setConnectionHookClassName("bad class name"); assertEquals("bad class name", dsb.getConnectionHookClassName()); assertNull(dsb.getConnectionHook()); dsb.setConnectionHookClassName("com.jolbox.bonecp.hooks.CustomHook"); assertTrue(dsb.getConnectionHook() instanceof CustomHook); File tmp = File.createTempFile("bonecp", ""); dsb.setLogWriter(new PrintWriter(tmp)); assertNotNull(dsb.getLogWriter()); try { dsb.setLoginTimeout(0); fail("Should throw exception"); } catch (UnsupportedOperationException e) { // do nothing } try { dsb.getLoginTimeout(); fail("Should throw exception"); } catch (UnsupportedOperationException e) { // do nothing } Connection c = dsb.getConnection("test", "test"); assertNotNull(c); BoneCPDataSource dsb2 = new BoneCPDataSource(); // empty constructor test dsb2.setDriverClass("inexistent"); try { dsb2.getConnection(); fail("Should fail"); } catch (SQLException e) { // do nothing } assertNull(dsb.unwrap(String.class)); assertEquals("com.jolbox.bonecp.MockJDBCDriver", dsb.getDriverClass()); dsb.setClassLoader(getClass().getClassLoader()); dsb.loadClass("java.lang.String"); assertEquals(getClass().getClassLoader(), dsb.getClassLoader()); }