@Override protected PooledConnection createConnectionInternal() throws SQLException { return dataSource.getPooledConnection(); }
@Override protected PooledConnection createConnectionInternal() throws SQLException { return dataSource.getPooledConnection(); }
pooledConnection = dds.getPooledConnection(); } catch (SQLException e) { throw new KlabRuntimeException(e);
@Test public void testGetPooledConnectionClosedIfRejected() throws Exception { JdbcDataSource h2DataSource = new JdbcDataSource(); h2DataSource.setURL("jdbc:h2:mem:"); JdbcDataSource targetDataSource = Mockito.spy(h2DataSource); AtomicReference<Connection> targetConnectionReference = new AtomicReference<>(); when(targetDataSource.getPooledConnection()).thenAnswer((Answer<PooledConnection>) invocation -> { PooledConnection pc = Mockito.spy((PooledConnection) invocation.callRealMethod()); when(pc.getConnection()).thenAnswer((Answer<Connection>) invocation1 -> { Connection c = (Connection) invocation1.callRealMethod(); targetConnectionReference.set(c); return c; }); return pc; }); SniffyDataSource sniffyDataSource = new SniffyDataSource(targetDataSource); PooledConnection sniffyPooledConnection = sniffyDataSource.getPooledConnection(); ConnectionsRegistry.INSTANCE.setDataSourceStatus("jdbc:h2:mem:", "", -1); try { sniffyPooledConnection.getConnection(); fail(); } catch (SQLException e) { assertNotNull(e); } finally { ConnectionsRegistry.INSTANCE.clear(); } assertTrue(targetConnectionReference.get().isClosed()); }