AthenzDataSource extends PoolingDataSource<PoolableConnection> implements PoolableDataSource { @Override public Connection getConnection() throws SQLException { Connection conn = super.getConnection(); if (networkTimeout > 0) { conn.setNetworkTimeout(timeoutThreadPool, networkTimeout); } return conn; } AthenzDataSource(ObjectPool<PoolableConnection> pool); @Override synchronized void clearPoolConnections(); @Override Connection getConnection(); static final String ATHENZ_PROP_DATASTORE_NETWORK_TIMEOUT; static final String ATHENZ_PROP_DATASTORE_TIMEOUT_THREADS; }
@Test public void testGetConnection() throws Exception { System.setProperty("athenz.db.pool_validation_query", ""); System.setProperty("athenz.datastore.timeout_threads", "-3"); MockConnectionFactory connectionFactory = new MockConnectionFactory(); Connection connection = Mockito.mock(Connection.class); Mockito.when(connection.isValid(anyInt())).thenReturn(true); connectionFactory.setConnection(connection); PoolableDataSource src = DataSourceFactory.create(connectionFactory); assertNotNull(src); Connection conn = src.getConnection(); assertNotNull(conn); System.clearProperty("athenz.db.pool_validation_query"); System.clearProperty("athenz.datastore.timeout_threads"); }
@Test public void testGetConnectionWithNetorkOption() throws Exception { System.setProperty("athenz.db.pool_validation_query", ""); System.setProperty("athenz.datastore.network_timeout", "20000"); MockConnectionFactory connectionFactory = new MockConnectionFactory(); Connection connection = Mockito.mock(Connection.class); Mockito.when(connection.isValid(anyInt())).thenReturn(true); connectionFactory.setConnection(connection); PoolableDataSource src = DataSourceFactory.create(connectionFactory); assertNotNull(src); Connection conn = src.getConnection(); assertNotNull(conn); System.clearProperty("athenz.db.pool_validation_query"); System.clearProperty("athenz.datastore.network_timeout"); }