Improve test coverage.

pull/192/head
Brett Wooldridge 10 years ago
parent 8b96191726
commit 57ae67a08a

@ -47,7 +47,6 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
private final HashMap<MultiPoolKey, HikariPool> multiPool;
private volatile boolean isShutdown;
private int loginTimeout;
private final HikariPool fastPathPool;
private volatile HikariPool pool;
@ -152,14 +151,21 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
@Override
public void setLoginTimeout(int seconds) throws SQLException
{
this.loginTimeout = seconds;
for (HikariPool hikariPool : multiPool.values()) {
hikariPool.getDataSource().setLoginTimeout(seconds);
}
}
/** {@inheritDoc} */
@Override
public int getLoginTimeout() throws SQLException
{
return loginTimeout;
HikariPool hikariPool = multiPool.values().iterator().next();
if (hikariPool != null) {
return hikariPool.getDataSource().getLoginTimeout();
}
return 0;
}
/** {@inheritDoc} */

@ -57,6 +57,8 @@ public class TestConnections
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
HikariDataSource ds = new HikariDataSource(config);
ds.setLoginTimeout(10);
Assert.assertSame(10, ds.getLoginTimeout());
try {
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
@ -385,6 +387,9 @@ public class TestConnections
Connection connection = ds.getConnection();
connection.close();
PoolUtilities.quietlySleep(1001L);
connection = ds.getConnection();
}
finally {
StubConnection.oldDriver = false;

@ -30,109 +30,110 @@ import javax.sql.DataSource;
*/
public class StubDataSource implements DataSource
{
private String user;
private String password;
private PrintWriter logWriter;
private SQLException throwException;
public String getUser()
{
return user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public void setURL(String url)
{
// we don't care
}
/** {@inheritDoc} */
@Override
public PrintWriter getLogWriter() throws SQLException
{
return logWriter;
}
/** {@inheritDoc} */
@Override
public void setLogWriter(PrintWriter out) throws SQLException
{
this.logWriter = out;
}
/** {@inheritDoc} */
@Override
public void setLoginTimeout(int seconds) throws SQLException
{
}
/** {@inheritDoc} */
@Override
public int getLoginTimeout() throws SQLException
{
return 0;
}
/** {@inheritDoc} */
public Logger getParentLogger() throws SQLFeatureNotSupportedException
{
return null;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException
{
if (iface.isInstance(this)) {
return (T) this;
}
throw new SQLException("Wrapped DataSource is not an instance of " + iface);
}
/** {@inheritDoc} */
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException
{
return false;
}
/** {@inheritDoc} */
@Override
public Connection getConnection() throws SQLException
{
if (throwException != null)
{
throw throwException;
}
return new StubConnection();
}
/** {@inheritDoc} */
@Override
public Connection getConnection(String username, String password) throws SQLException
{
return new StubConnection();
}
public void setThrowException(SQLException e)
{
this.throwException = e;
}
private String user;
private String password;
private PrintWriter logWriter;
private SQLException throwException;
private int loginTimeout;
public String getUser()
{
return user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public void setURL(String url)
{
// we don't care
}
/** {@inheritDoc} */
@Override
public PrintWriter getLogWriter() throws SQLException
{
return logWriter;
}
/** {@inheritDoc} */
@Override
public void setLogWriter(PrintWriter out) throws SQLException
{
this.logWriter = out;
}
/** {@inheritDoc} */
@Override
public void setLoginTimeout(int seconds) throws SQLException
{
this.loginTimeout = seconds;
}
/** {@inheritDoc} */
@Override
public int getLoginTimeout() throws SQLException
{
return loginTimeout;
}
/** {@inheritDoc} */
public Logger getParentLogger() throws SQLFeatureNotSupportedException
{
return null;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException
{
if (iface.isInstance(this)) {
return (T) this;
}
throw new SQLException("Wrapped DataSource is not an instance of " + iface);
}
/** {@inheritDoc} */
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException
{
return false;
}
/** {@inheritDoc} */
@Override
public Connection getConnection() throws SQLException
{
if (throwException != null) {
throw throwException;
}
return new StubConnection();
}
/** {@inheritDoc} */
@Override
public Connection getConnection(String username, String password) throws SQLException
{
return new StubConnection();
}
public void setThrowException(SQLException e)
{
this.throwException = e;
}
}

@ -47,7 +47,6 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
private final HashMap<MultiPoolKey, HikariPool> multiPool;
private volatile boolean isShutdown;
private int loginTimeout;
private final HikariPool fastPathPool;
private volatile HikariPool pool;
@ -152,14 +151,21 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
@Override
public void setLoginTimeout(int seconds) throws SQLException
{
this.loginTimeout = seconds;
for (HikariPool hikariPool : multiPool.values()) {
hikariPool.getDataSource().setLoginTimeout(seconds);
}
}
/** {@inheritDoc} */
@Override
public int getLoginTimeout() throws SQLException
{
return loginTimeout;
HikariPool hikariPool = multiPool.values().iterator().next();
if (hikariPool != null) {
return hikariPool.getDataSource().getLoginTimeout();
}
return 0;
}
/** {@inheritDoc} */

@ -57,6 +57,8 @@ public class TestConnections
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
HikariDataSource ds = new HikariDataSource(config);
ds.setLoginTimeout(10);
Assert.assertSame(10, ds.getLoginTimeout());
try {
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
@ -385,6 +387,9 @@ public class TestConnections
Connection connection = ds.getConnection();
connection.close();
PoolUtilities.quietlySleep(1001L);
connection = ds.getConnection();
}
finally {
StubConnection.oldDriver = false;

@ -30,109 +30,110 @@ import javax.sql.DataSource;
*/
public class StubDataSource implements DataSource
{
private String user;
private String password;
private PrintWriter logWriter;
private SQLException throwException;
public String getUser()
{
return user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public void setURL(String url)
{
// we don't care
}
/** {@inheritDoc} */
@Override
public PrintWriter getLogWriter() throws SQLException
{
return logWriter;
}
/** {@inheritDoc} */
@Override
public void setLogWriter(PrintWriter out) throws SQLException
{
this.logWriter = out;
}
/** {@inheritDoc} */
@Override
public void setLoginTimeout(int seconds) throws SQLException
{
}
/** {@inheritDoc} */
@Override
public int getLoginTimeout() throws SQLException
{
return 0;
}
/** {@inheritDoc} */
public Logger getParentLogger() throws SQLFeatureNotSupportedException
{
return null;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException
{
if (iface.isInstance(this)) {
return (T) this;
}
throw new SQLException("Wrapped DataSource is not an instance of " + iface);
}
/** {@inheritDoc} */
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException
{
return false;
}
/** {@inheritDoc} */
@Override
public Connection getConnection() throws SQLException
{
if (throwException != null)
{
throw throwException;
}
return new StubConnection();
}
/** {@inheritDoc} */
@Override
public Connection getConnection(String username, String password) throws SQLException
{
return new StubConnection();
}
public void setThrowException(SQLException e)
{
this.throwException = e;
}
private String user;
private String password;
private PrintWriter logWriter;
private SQLException throwException;
private int loginTimeout;
public String getUser()
{
return user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public void setURL(String url)
{
// we don't care
}
/** {@inheritDoc} */
@Override
public PrintWriter getLogWriter() throws SQLException
{
return logWriter;
}
/** {@inheritDoc} */
@Override
public void setLogWriter(PrintWriter out) throws SQLException
{
this.logWriter = out;
}
/** {@inheritDoc} */
@Override
public void setLoginTimeout(int seconds) throws SQLException
{
this.loginTimeout = seconds;
}
/** {@inheritDoc} */
@Override
public int getLoginTimeout() throws SQLException
{
return loginTimeout;
}
/** {@inheritDoc} */
public Logger getParentLogger() throws SQLFeatureNotSupportedException
{
return null;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException
{
if (iface.isInstance(this)) {
return (T) this;
}
throw new SQLException("Wrapped DataSource is not an instance of " + iface);
}
/** {@inheritDoc} */
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException
{
return false;
}
/** {@inheritDoc} */
@Override
public Connection getConnection() throws SQLException
{
if (throwException != null) {
throw throwException;
}
return new StubConnection();
}
/** {@inheritDoc} */
@Override
public Connection getConnection(String username, String password) throws SQLException
{
return new StubConnection();
}
public void setThrowException(SQLException e)
{
this.throwException = e;
}
}

Loading…
Cancel
Save