test for failure in case of InitializationFailFast

pull/670/head
Nitin 9 years ago
parent 15468fb4bd
commit 953b0be06d

@ -390,7 +390,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
{
metricsTracker.recordConnectionUsage(poolEntry);
connectionBag.recycle(poolEntry);
connectionBag.requite(poolEntry);
}
/**
@ -421,7 +421,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
// ***********************************************************************
/**
* Getting new connection from data source.
* Creating new poolEntry.
*/
private PoolEntry createPoolEntry()
{
@ -553,7 +553,7 @@ public class HikariPool extends PoolBase implements HikariPoolMXBean, IBagStateL
// ***********************************************************************
/**
* Creating and adding connections to the pool.
* Creating and adding poolEntries (connections) to the pool.
*/
private class PoolEntryCreator implements Callable<Boolean>
{

@ -309,6 +309,11 @@ abstract class PoolBase
this.dataSource = dataSource;
}
/**
* Obtain connection from data source.
*
* @return a Connection connection
*/
Connection newConnection() throws Exception
{
Connection connection = null;

@ -46,7 +46,7 @@ import static com.zaxxer.hikari.util.ConcurrentBag.IConcurrentBagEntry.STATE_RES
* Note that items that are "borrowed" from the bag are not actually
* removed from any collection, so garbage collection will not occur
* even if the reference is abandoned. Thus care must be taken to
* "recycle" borrowed objects otherwise a memory leak will result. Only
* "requite" borrowed objects otherwise a memory leak will result. Only
* the "remove" method can completely remove an object from the bag.
*
* @author Brett Wooldridge
@ -177,14 +177,14 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
/**
* This method will return a borrowed object to the bag. Objects
* that are borrowed from the bag but never "recycled" will result
* that are borrowed from the bag but never "requited" will result
* in a memory leak.
*
* @param bagEntry the value to return to the bag
* @throws NullPointerException if value is null
* @throws IllegalStateException if the bagEntry was not borrowed from the bag
*/
public void recycle(final T bagEntry)
public void requite(final T bagEntry)
{
bagEntry.lazySet(STATE_NOT_IN_USE);

@ -89,7 +89,7 @@ public class TestConcurrentBag
PrintStream ps = new PrintStream(baos, true);
TestElf.setSlf4jTargetStream(ConcurrentBag.class, ps);
bag.recycle(reserved);
bag.requite(reserved);
bag.remove(notinuse);
Assert.assertTrue(new String(baos.toByteArray()).contains("not borrowed or reserved"));

@ -507,6 +507,14 @@ public class TestConnections
catch (SQLException e) {
Assert.assertSame("Bad query or something.", e.getNextException().getMessage());
}
config.setInitializationFailFast(true);
try (HikariDataSource ds = new HikariDataSource(config)) {
Assert.fail("Initialization should have failed");
}
catch (PoolInitializationException e) {
// passed
}
}
@Test

Loading…
Cancel
Save