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

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

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

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

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

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

Loading…
Cancel
Save