create leak task first and reverted long to int change

pull/571/head
Nitin 9 years ago
parent 2e5dd85133
commit 47ac982cc3

@ -50,21 +50,21 @@ public class HikariConfig implements HikariConfigMXBean
{ {
private static final Logger LOGGER = LoggerFactory.getLogger(HikariConfig.class); private static final Logger LOGGER = LoggerFactory.getLogger(HikariConfig.class);
private static final int CONNECTION_TIMEOUT = (int) SECONDS.toMillis(30); private static final long CONNECTION_TIMEOUT = SECONDS.toMillis(30);
private static final int VALIDATION_TIMEOUT = (int) SECONDS.toMillis(5); private static final long VALIDATION_TIMEOUT = SECONDS.toMillis(5);
private static final int IDLE_TIMEOUT = (int) MINUTES.toMillis(10); private static final long IDLE_TIMEOUT = MINUTES.toMillis(10);
private static final int MAX_LIFETIME = (int) MINUTES.toMillis(30); private static final long MAX_LIFETIME = MINUTES.toMillis(30);
private static final AtomicInteger POOL_NUMBER; private static final AtomicInteger POOL_NUMBER;
private static boolean unitTest; private static boolean unitTest;
// Properties changeable at runtime through the MBean // Properties changeable at runtime through the MBean
// //
private volatile int connectionTimeout; private volatile long connectionTimeout;
private volatile int validationTimeout; private volatile long validationTimeout;
private volatile int idleTimeout; private volatile long idleTimeout;
private volatile int leakDetectionThreshold; private volatile long leakDetectionThreshold;
private volatile int maxLifetime; private volatile long maxLifetime;
private volatile int maxPoolSize; private volatile int maxPoolSize;
private volatile int minIdle; private volatile int minIdle;
@ -227,14 +227,14 @@ public class HikariConfig implements HikariConfigMXBean
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getConnectionTimeout() public long getConnectionTimeout()
{ {
return connectionTimeout; return connectionTimeout;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setConnectionTimeout(int connectionTimeoutMs) public void setConnectionTimeout(long connectionTimeoutMs)
{ {
if (connectionTimeoutMs == 0) { if (connectionTimeoutMs == 0) {
this.connectionTimeout = Integer.MAX_VALUE; this.connectionTimeout = Integer.MAX_VALUE;
@ -253,14 +253,14 @@ public class HikariConfig implements HikariConfigMXBean
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getValidationTimeout() public long getValidationTimeout()
{ {
return validationTimeout; return validationTimeout;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setValidationTimeout(int validationTimeoutMs) public void setValidationTimeout(long validationTimeoutMs)
{ {
if (validationTimeoutMs < 250) { if (validationTimeoutMs < 250) {
throw new IllegalArgumentException("validationTimeout cannot be less than 250ms"); throw new IllegalArgumentException("validationTimeout cannot be less than 250ms");
@ -350,14 +350,14 @@ public class HikariConfig implements HikariConfigMXBean
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getIdleTimeout() public long getIdleTimeout()
{ {
return idleTimeout; return idleTimeout;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setIdleTimeout(int idleTimeoutMs) public void setIdleTimeout(long idleTimeoutMs)
{ {
if (idleTimeoutMs < 0) { if (idleTimeoutMs < 0) {
throw new IllegalArgumentException("idleTimeout cannot be negative"); throw new IllegalArgumentException("idleTimeout cannot be negative");
@ -588,28 +588,28 @@ public class HikariConfig implements HikariConfigMXBean
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getLeakDetectionThreshold() public long getLeakDetectionThreshold()
{ {
return leakDetectionThreshold; return leakDetectionThreshold;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setLeakDetectionThreshold(int leakDetectionThresholdMs) public void setLeakDetectionThreshold(long leakDetectionThresholdMs)
{ {
this.leakDetectionThreshold = leakDetectionThresholdMs; this.leakDetectionThreshold = leakDetectionThresholdMs;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public int getMaxLifetime() public long getMaxLifetime()
{ {
return maxLifetime; return maxLifetime;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setMaxLifetime(int maxLifetimeMs) public void setMaxLifetime(long maxLifetimeMs)
{ {
this.maxLifetime = maxLifetimeMs; this.maxLifetime = maxLifetimeMs;
} }
@ -842,7 +842,7 @@ public class HikariConfig implements HikariConfigMXBean
if (leakDetectionThreshold > 0 && !unitTest) { if (leakDetectionThreshold > 0 && !unitTest) {
if (leakDetectionThreshold < SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0)) { if (leakDetectionThreshold < SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0)) {
LOGGER.warn("{} - leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it.", poolName); LOGGER.warn("{} - leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it.", poolName);
leakDetectionThreshold = 0; leakDetectionThreshold = 0L;
} }
} }

@ -30,7 +30,7 @@ public interface HikariConfigMXBean
* *
* @return the connection timeout in milliseconds * @return the connection timeout in milliseconds
*/ */
int getConnectionTimeout(); long getConnectionTimeout();
/** /**
* Set the maximum number of milliseconds that a client will wait for a connection from the pool. If this * Set the maximum number of milliseconds that a client will wait for a connection from the pool. If this
@ -39,7 +39,7 @@ public interface HikariConfigMXBean
* *
* @param connectionTimeoutMs the connection timeout in milliseconds * @param connectionTimeoutMs the connection timeout in milliseconds
*/ */
void setConnectionTimeout(int connectionTimeoutMs); void setConnectionTimeout(long connectionTimeoutMs);
/** /**
* Get the maximum number of milliseconds that the pool will wait for a connection to be validated as * Get the maximum number of milliseconds that the pool will wait for a connection to be validated as
@ -47,7 +47,7 @@ public interface HikariConfigMXBean
* *
* @return the validation timeout in milliseconds * @return the validation timeout in milliseconds
*/ */
int getValidationTimeout(); long getValidationTimeout();
/** /**
* Sets the maximum number of milliseconds that the pool will wait for a connection to be validated as * Sets the maximum number of milliseconds that the pool will wait for a connection to be validated as
@ -55,7 +55,7 @@ public interface HikariConfigMXBean
* *
* @param validationTimeoutMs the validation timeout in milliseconds * @param validationTimeoutMs the validation timeout in milliseconds
*/ */
void setValidationTimeout(int validationTimeoutMs); void setValidationTimeout(long validationTimeoutMs);
/** /**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit * This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
@ -65,7 +65,7 @@ public interface HikariConfigMXBean
* *
* @return the idle timeout in milliseconds * @return the idle timeout in milliseconds
*/ */
int getIdleTimeout(); long getIdleTimeout();
/** /**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit * This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
@ -75,7 +75,7 @@ public interface HikariConfigMXBean
* *
* @param idleTimeoutMs the idle timeout in milliseconds * @param idleTimeoutMs the idle timeout in milliseconds
*/ */
void setIdleTimeout(int idleTimeoutMs); void setIdleTimeout(long idleTimeoutMs);
/** /**
* This property controls the amount of time that a connection can be out of the pool before a message is * This property controls the amount of time that a connection can be out of the pool before a message is
@ -83,7 +83,7 @@ public interface HikariConfigMXBean
* *
* @return the connection leak detection threshold in milliseconds * @return the connection leak detection threshold in milliseconds
*/ */
int getLeakDetectionThreshold(); long getLeakDetectionThreshold();
/** /**
* This property controls the amount of time that a connection can be out of the pool before a message is * This property controls the amount of time that a connection can be out of the pool before a message is
@ -91,7 +91,7 @@ public interface HikariConfigMXBean
* *
* @param leakDetectionThresholdMs the connection leak detection threshold in milliseconds * @param leakDetectionThresholdMs the connection leak detection threshold in milliseconds
*/ */
void setLeakDetectionThreshold(int leakDetectionThresholdMs); void setLeakDetectionThreshold(long leakDetectionThresholdMs);
/** /**
* This property controls the maximum lifetime of a connection in the pool. When a connection reaches this * This property controls the maximum lifetime of a connection in the pool. When a connection reaches this
@ -100,7 +100,7 @@ public interface HikariConfigMXBean
* *
* @return the maximum connection lifetime in milliseconds * @return the maximum connection lifetime in milliseconds
*/ */
int getMaxLifetime(); long getMaxLifetime();
/** /**
* This property controls the maximum lifetime of a connection in the pool. When a connection reaches this * This property controls the maximum lifetime of a connection in the pool. When a connection reaches this
@ -109,7 +109,7 @@ public interface HikariConfigMXBean
* *
* @param maxLifetimeMs the maximum connection lifetime in milliseconds * @param maxLifetimeMs the maximum connection lifetime in milliseconds
*/ */
void setMaxLifetime(int maxLifetimeMs); void setMaxLifetime(long maxLifetimeMs);
/** /**
* The property controls the maximum size that the pool is allowed to reach, including both idle and in-use * The property controls the maximum size that the pool is allowed to reach, including both idle and in-use

@ -565,7 +565,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
// failed to get connection from db, sleep and retry // failed to get connection from db, sleep and retry
quietlySleep(sleepBackoff); quietlySleep(sleepBackoff);
sleepBackoff = Math.min(SECONDS.toMillis(10), Math.min(connectionTimeout, (int) (sleepBackoff * 1.3))); sleepBackoff = Math.min(SECONDS.toMillis(10), Math.min(connectionTimeout, (long) (sleepBackoff * 1.3)));
} }
// Pool is suspended or shutdown or at max size // Pool is suspended or shutdown or at max size
return Boolean.FALSE; return Boolean.FALSE;

@ -42,8 +42,8 @@ abstract class PoolBase
protected final HikariConfig config; protected final HikariConfig config;
protected final String poolName; protected final String poolName;
protected int connectionTimeout; protected long connectionTimeout;
protected int validationTimeout; protected long validationTimeout;
private static final String[] RESET_STATES = {"readOnly", "autoCommit", "isolation", "catalog", "netTimeout"}; private static final String[] RESET_STATES = {"readOnly", "autoCommit", "isolation", "catalog", "netTimeout"};
private static final int UNINITIALIZED = -1; private static final int UNINITIALIZED = -1;
@ -110,7 +110,7 @@ abstract class PoolBase
try { try {
LOGGER.debug("{} - Closing connection {}: {}", poolName, connection, closureReason); LOGGER.debug("{} - Closing connection {}: {}", poolName, connection, closureReason);
try { try {
setNetworkTimeout(connection, (int) SECONDS.toMillis(15)); setNetworkTimeout(connection, SECONDS.toMillis(15));
} }
finally { finally {
connection.close(); // continue with the close even if setNetworkTimeout() throws connection.close(); // continue with the close even if setNetworkTimeout() throws
@ -126,14 +126,14 @@ abstract class PoolBase
{ {
try { try {
if (isUseJdbc4Validation) { if (isUseJdbc4Validation) {
return connection.isValid((int) MILLISECONDS.toSeconds(Math.max(1000, validationTimeout))); return connection.isValid((int) MILLISECONDS.toSeconds(Math.max(1000L, validationTimeout)));
} }
setNetworkTimeout(connection, validationTimeout); setNetworkTimeout(connection, validationTimeout);
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
if (isNetworkTimeoutSupported != TRUE) { if (isNetworkTimeoutSupported != TRUE) {
setQueryTimeout(statement, (int) MILLISECONDS.toSeconds(Math.max(1000, validationTimeout))); setQueryTimeout(statement, (int) MILLISECONDS.toSeconds(Math.max(1000L, validationTimeout)));
} }
statement.execute(config.getConnectionTestQuery()); statement.execute(config.getConnectionTestQuery());
@ -424,12 +424,12 @@ abstract class PoolBase
* @param timeoutMs the number of milliseconds before timeout * @param timeoutMs the number of milliseconds before timeout
* @return the pre-existing network timeout value * @return the pre-existing network timeout value
*/ */
private int getAndSetNetworkTimeout(final Connection connection, final int timeoutMs) private int getAndSetNetworkTimeout(final Connection connection, final long timeoutMs)
{ {
if (isNetworkTimeoutSupported != FALSE) { if (isNetworkTimeoutSupported != FALSE) {
try { try {
final int originalTimeout = connection.getNetworkTimeout(); final int originalTimeout = connection.getNetworkTimeout();
connection.setNetworkTimeout(netTimeoutExecutor, timeoutMs); connection.setNetworkTimeout(netTimeoutExecutor, (int) timeoutMs);
isNetworkTimeoutSupported = TRUE; isNetworkTimeoutSupported = TRUE;
return originalTimeout; return originalTimeout;
} }
@ -452,10 +452,10 @@ abstract class PoolBase
* @param timeoutMs the number of milliseconds before timeout * @param timeoutMs the number of milliseconds before timeout
* @throws SQLException throw if the connection.setNetworkTimeout() call throws * @throws SQLException throw if the connection.setNetworkTimeout() call throws
*/ */
private void setNetworkTimeout(final Connection connection, final int timeoutMs) throws SQLException private void setNetworkTimeout(final Connection connection, final long timeoutMs) throws SQLException
{ {
if (isNetworkTimeoutSupported == TRUE) { if (isNetworkTimeoutSupported == TRUE) {
connection.setNetworkTimeout(netTimeoutExecutor, timeoutMs); connection.setNetworkTimeout(netTimeoutExecutor, (int) timeoutMs);
} }
} }
@ -510,11 +510,11 @@ abstract class PoolBase
* @param dataSource the DataSource * @param dataSource the DataSource
* @param connectionTimeout the timeout in milliseconds * @param connectionTimeout the timeout in milliseconds
*/ */
private void setLoginTimeout(final DataSource dataSource, final int connectionTimeout) private void setLoginTimeout(final DataSource dataSource, final long connectionTimeout)
{ {
if (connectionTimeout != Integer.MAX_VALUE) { if (connectionTimeout != Integer.MAX_VALUE) {
try { try {
dataSource.setLoginTimeout((int) MILLISECONDS.toSeconds(Math.max(1000, connectionTimeout))); dataSource.setLoginTimeout((int) MILLISECONDS.toSeconds(Math.max(1000L, connectionTimeout)));
} }
catch (Throwable e) { catch (Throwable e) {
LOGGER.warn("{} - Failed to set login timeout for data source. ({})", poolName, e.getMessage()); LOGGER.warn("{} - Failed to set login timeout for data source. ({})", poolName, e.getMessage());

@ -36,7 +36,7 @@ class ProxyLeakTask implements Runnable
private static final ProxyLeakTask NO_LEAK; private static final ProxyLeakTask NO_LEAK;
private ScheduledExecutorService executorService; private ScheduledExecutorService executorService;
private int leakDetectionThreshold; private long leakDetectionThreshold;
private ScheduledFuture<?> scheduledFuture; private ScheduledFuture<?> scheduledFuture;
private String connectionName; private String connectionName;
private Exception exception; private Exception exception;
@ -49,7 +49,7 @@ class ProxyLeakTask implements Runnable
}; };
} }
ProxyLeakTask(final int leakDetectionThreshold, final ScheduledExecutorService executorService) ProxyLeakTask(final long leakDetectionThreshold, final ScheduledExecutorService executorService)
{ {
this.executorService = executorService; this.executorService = executorService;
this.leakDetectionThreshold = leakDetectionThreshold; this.leakDetectionThreshold = leakDetectionThreshold;
@ -71,7 +71,7 @@ class ProxyLeakTask implements Runnable
return (leakDetectionThreshold == 0) ? NO_LEAK : new ProxyLeakTask(this, bagEntry); return (leakDetectionThreshold == 0) ? NO_LEAK : new ProxyLeakTask(this, bagEntry);
} }
void updateLeakDetectionThreshold(final int leakDetectionThreshold) void updateLeakDetectionThreshold(final long leakDetectionThreshold)
{ {
this.leakDetectionThreshold = leakDetectionThreshold; this.leakDetectionThreshold = leakDetectionThreshold;
} }

@ -98,7 +98,7 @@ public class MiscTest
config.setPoolName("test"); config.setPoolName("test");
config.setThreadFactory(Executors.defaultThreadFactory()); config.setThreadFactory(Executors.defaultThreadFactory());
config.setMetricRegistry(null); config.setMetricRegistry(null);
config.setLeakDetectionThreshold((int) TimeUnit.SECONDS.toMillis(1)); config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(1));
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
TestElf.setConfigUnitTest(true); TestElf.setConfigUnitTest(true);
@ -108,9 +108,9 @@ public class MiscTest
TestElf.getPool(ds).logPoolState(); TestElf.getPool(ds).logPoolState();
Connection connection = ds.getConnection(); Connection connection = ds.getConnection();
UtilityElf.quietlySleep((int) TimeUnit.SECONDS.toMillis(4)); UtilityElf.quietlySleep(TimeUnit.SECONDS.toMillis(4));
connection.close(); connection.close();
UtilityElf.quietlySleep((int) TimeUnit.SECONDS.toMillis(1)); UtilityElf.quietlySleep(TimeUnit.SECONDS.toMillis(1));
ps.close(); ps.close();
String s = new String(baos.toByteArray()); String s = new String(baos.toByteArray());
Assert.assertNotNull("Exception string was null", s); Assert.assertNotNull("Exception string was null", s);

@ -47,8 +47,8 @@ public class PostgresTest
config.setMinimumIdle(3); config.setMinimumIdle(3);
config.setMaximumPoolSize(10); config.setMaximumPoolSize(10);
config.setConnectionTimeout(3000); config.setConnectionTimeout(3000);
config.setIdleTimeout((int) TimeUnit.SECONDS.toMillis(10)); config.setIdleTimeout(TimeUnit.SECONDS.toMillis(10));
config.setValidationTimeout((int) TimeUnit.SECONDS.toMillis(2)); config.setValidationTimeout(TimeUnit.SECONDS.toMillis(2));
config.setJdbcUrl("jdbc:pgsql://localhost:5432/test"); config.setJdbcUrl("jdbc:pgsql://localhost:5432/test");
config.setUsername("brettw"); config.setUsername("brettw");
@ -82,7 +82,7 @@ public class PostgresTest
config.setMinimumIdle(3); config.setMinimumIdle(3);
config.setMaximumPoolSize(10); config.setMaximumPoolSize(10);
config.setConnectionTimeout(1000); config.setConnectionTimeout(1000);
config.setIdleTimeout((int) TimeUnit.SECONDS.toMillis(60)); config.setIdleTimeout(TimeUnit.SECONDS.toMillis(60));
config.setJdbcUrl("jdbc:pgsql://localhost:5432/test"); config.setJdbcUrl("jdbc:pgsql://localhost:5432/test");
config.setUsername("brettw"); config.setUsername("brettw");
@ -127,7 +127,7 @@ public class PostgresTest
config.setMinimumIdle(3); config.setMinimumIdle(3);
config.setMaximumPoolSize(10); config.setMaximumPoolSize(10);
config.setConnectionTimeout(1000); config.setConnectionTimeout(1000);
config.setIdleTimeout((int) TimeUnit.SECONDS.toMillis(60)); config.setIdleTimeout(TimeUnit.SECONDS.toMillis(60));
config.setJdbcUrl("jdbc:pgsql://localhost:5432/test"); config.setJdbcUrl("jdbc:pgsql://localhost:5432/test");
config.setUsername("brettw"); config.setUsername("brettw");
@ -162,8 +162,8 @@ public class PostgresTest
config.setMinimumIdle(0); config.setMinimumIdle(0);
config.setMaximumPoolSize(15); config.setMaximumPoolSize(15);
config.setConnectionTimeout(10000); config.setConnectionTimeout(10000);
config.setIdleTimeout((int) TimeUnit.MINUTES.toMillis(1)); config.setIdleTimeout(TimeUnit.MINUTES.toMillis(1));
config.setMaxLifetime((int) TimeUnit.MINUTES.toMillis(2)); config.setMaxLifetime(TimeUnit.MINUTES.toMillis(2));
config.setRegisterMbeans(true); config.setRegisterMbeans(true);
config.setJdbcUrl("jdbc:postgresql://localhost:5432/netld"); config.setJdbcUrl("jdbc:postgresql://localhost:5432/netld");

@ -71,7 +71,7 @@ public class TestConnections
config.setConnectionInitSql("SELECT 1"); config.setConnectionInitSql("SELECT 1");
config.setReadOnly(true); config.setReadOnly(true);
config.setConnectionTimeout(2500); config.setConnectionTimeout(2500);
config.setLeakDetectionThreshold((int) TimeUnit.SECONDS.toMillis(30)); config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(30));
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) { try (HikariDataSource ds = new HikariDataSource(config)) {
@ -488,7 +488,7 @@ public class TestConnections
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setMinimumIdle(1); config.setMinimumIdle(1);
config.setMaximumPoolSize(2); config.setMaximumPoolSize(2);
config.setConnectionTimeout((int) TimeUnit.SECONDS.toMillis(3)); config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(3));
config.setConnectionTestQuery("VALUES 1"); config.setConnectionTestQuery("VALUES 1");
config.setInitializationFailFast(false); config.setInitializationFailFast(false);
config.setDataSource(stubDataSource); config.setDataSource(stubDataSource);

@ -98,7 +98,7 @@ public class TestProxies
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setMinimumIdle(0); config.setMinimumIdle(0);
config.setMaximumPoolSize(1); config.setMaximumPoolSize(1);
config.setConnectionTimeout((int) TimeUnit.SECONDS.toMillis(1)); config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(1));
config.setConnectionTestQuery("VALUES 1"); config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

@ -110,7 +110,7 @@ public class TestValidation
{ {
try { try {
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setConnectionTimeout(10); config.setConnectionTimeout(10L);
Assert.fail(); Assert.fail();
} }
catch (IllegalArgumentException ise) { catch (IllegalArgumentException ise) {
@ -123,7 +123,7 @@ public class TestValidation
{ {
try { try {
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setIdleTimeout(-1); config.setIdleTimeout(-1L);
Assert.fail("negative idle timeout accepted"); Assert.fail("negative idle timeout accepted");
} }
catch (IllegalArgumentException ise) { catch (IllegalArgumentException ise) {
@ -140,7 +140,7 @@ public class TestValidation
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
config.setIdleTimeout((int) TimeUnit.SECONDS.toMillis(5)); config.setIdleTimeout(TimeUnit.SECONDS.toMillis(5));
config.validate(); config.validate();
Assert.assertTrue(new String(baos.toByteArray()).contains("less than 10000ms")); Assert.assertTrue(new String(baos.toByteArray()).contains("less than 10000ms"));
} }
@ -154,8 +154,8 @@ public class TestValidation
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
config.setMaxLifetime((int) TimeUnit.MINUTES.toMillis(2)); config.setMaxLifetime(TimeUnit.MINUTES.toMillis(2));
config.setIdleTimeout((int) TimeUnit.MINUTES.toMillis(3)); config.setIdleTimeout(TimeUnit.MINUTES.toMillis(3));
config.validate(); config.validate();
String s = new String(baos.toByteArray()); String s = new String(baos.toByteArray());
@ -194,9 +194,9 @@ public class TestValidation
try { try {
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setConnectionTimeout(Integer.MAX_VALUE); config.setConnectionTimeout(Integer.MAX_VALUE);
config.setIdleTimeout(1000); config.setIdleTimeout(1000L);
config.setLeakDetectionThreshold(1000); config.setLeakDetectionThreshold(1000L);
config.setMaxLifetime(-1); config.setMaxLifetime(-1L);
config.validate(); config.validate();
Assert.fail(); Assert.fail();
} }
@ -210,7 +210,7 @@ public class TestValidation
{ {
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
config.setLeakDetectionThreshold(1000); config.setLeakDetectionThreshold(1000L);
config.validate(); config.validate();
Assert.assertEquals(0L, config.getLeakDetectionThreshold()); Assert.assertEquals(0L, config.getLeakDetectionThreshold());
} }

Loading…
Cancel
Save