This fixes #65 as well as correcting OSGi manifest generation warnings by reorganizing the code and packages somewhat to ensure that the publicly exported com.zaxxer.hikari package does not expose any internal classes.

pull/77/head
Brett Wooldridge 11 years ago
parent 62297a0c88
commit cfda5e022c

@ -82,12 +82,14 @@
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Final</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- OSGi test -->
@ -152,7 +154,8 @@
<configuration>
<instructions>
<Bundle-Name>HikariCP</Bundle-Name>
<Export-Package>com.zaxxer.hikari</Export-Package>
<Export-Package>com.zaxxer.hikari,com.zaxxer.hikari.hibernate</Export-Package>
<Private-Package>com.zaxxer.hikari.*</Private-Package>
<Import-Package>
javassist.*,
javax.management,
@ -160,6 +163,7 @@
javax.sql.rowset,
javax.sql.rowset.serial,
javax.sql.rowset.spi,
com.codahale.metrics;;resolution:=optional,
org.slf4j,
org.hibernate;resolution:=optional,
org.hibernate.cfg;resolution:=optional,

@ -74,7 +74,6 @@ public class HikariConfig implements HikariConfigMBean
private boolean isRegisterMbeans;
private DataSource dataSource;
private Properties dataSourceProperties;
private IConnectionCustomizer connectionCustomizer;
private int transactionIsolation;
static
@ -611,12 +610,11 @@ public class HikariConfig implements HikariConfigMBean
validateNumerics();
if (connectionCustomizerClassName != null && connectionCustomizer == null)
if (connectionCustomizerClassName != null)
{
try
{
Class<?> customizerClass = getClass().getClassLoader().loadClass(connectionCustomizerClassName);
connectionCustomizer = (IConnectionCustomizer) customizerClass.newInstance();
getClass().getClassLoader().loadClass(connectionCustomizerClassName);
}
catch (Exception e)
{
@ -722,11 +720,6 @@ public class HikariConfig implements HikariConfigMBean
}
}
IConnectionCustomizer getConnectionCustomizer()
{
return connectionCustomizer;
}
void copyState(HikariConfig other)
{
for (Field field : HikariConfig.class.getDeclaredFields())

@ -24,6 +24,7 @@ import java.util.HashMap;
import javax.sql.DataSource;
import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.proxy.IHikariConnectionProxy;
import com.zaxxer.hikari.util.DriverDataSource;
@ -39,8 +40,8 @@ public class HikariDataSource extends HikariConfig implements DataSource
private int loginTimeout;
/* Package scopped for testing */
final HikariPool fastPathPool;
volatile HikariPool pool;
private final HikariPool fastPathPool;
private volatile HikariPool pool;
/**
* Default constructor. Setters be used to configure the pool. Using
@ -131,16 +132,16 @@ public class HikariDataSource extends HikariConfig implements DataSource
@Override
public PrintWriter getLogWriter() throws SQLException
{
return (pool.dataSource != null ? pool.dataSource.getLogWriter() : null);
return (pool.getDataSource() != null ? pool.getDataSource().getLogWriter() : null);
}
/** {@inheritDoc} */
@Override
public void setLogWriter(PrintWriter out) throws SQLException
{
if (pool.dataSource != null)
if (pool.getDataSource() != null)
{
pool.dataSource.setLogWriter(out);
pool.getDataSource().setLogWriter(out);
}
}
@ -169,9 +170,9 @@ public class HikariDataSource extends HikariConfig implements DataSource
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException
{
if (pool != null && iface.isInstance(pool.dataSource))
if (pool != null && iface.isInstance(pool.getDataSource()))
{
return (T) pool.dataSource;
return (T) pool.getDataSource();
}
throw new SQLException("Wrapped connection is not an instance of " + iface);
@ -181,7 +182,7 @@ public class HikariDataSource extends HikariConfig implements DataSource
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException
{
return (pool != null & pool.dataSource.getClass().isAssignableFrom(iface));
return (pool != null & pool.getDataSource().getClass().isAssignableFrom(iface));
}
/**
@ -222,9 +223,9 @@ public class HikariDataSource extends HikariConfig implements DataSource
if (pool != null)
{
pool.shutdown();
if (pool.dataSource instanceof DriverDataSource)
if (pool.getDataSource() instanceof DriverDataSource)
{
((DriverDataSource) pool.dataSource).shutdown();
((DriverDataSource) pool.getDataSource()).shutdown();
}
}
@ -233,9 +234,9 @@ public class HikariDataSource extends HikariConfig implements DataSource
for (HikariPool hikariPool : multiPool.values())
{
hikariPool.shutdown();
if (hikariPool.dataSource instanceof DriverDataSource)
if (hikariPool.getDataSource() instanceof DriverDataSource)
{
((DriverDataSource) hikariPool.dataSource).shutdown();
((DriverDataSource) hikariPool.getDataSource()).shutdown();
}
}
}

@ -19,7 +19,7 @@ package com.zaxxer.hikari.metrics;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.zaxxer.hikari.HikariPool;
import com.zaxxer.hikari.pool.HikariPool;
public final class CodaHaleMetricsTracker extends MetricsTracker
{

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.zaxxer.hikari;
package com.zaxxer.hikari.pool;
import java.lang.management.ManagementFactory;
@ -24,6 +24,8 @@ import javax.management.ObjectName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zaxxer.hikari.HikariConfig;
/**
* Helper class to register our MBeans.
*

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.zaxxer.hikari;
package com.zaxxer.hikari.pool;
import java.sql.Connection;
import java.sql.SQLException;
@ -32,6 +32,9 @@ import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariPoolMBean;
import com.zaxxer.hikari.IConnectionCustomizer;
import com.zaxxer.hikari.metrics.CodaHaleMetricsTracker;
import com.zaxxer.hikari.metrics.MetricsTracker;
import com.zaxxer.hikari.metrics.MetricsTracker.Context;
@ -53,7 +56,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
{
private static final Logger LOGGER = LoggerFactory.getLogger(HikariPool.class);
final DataSource dataSource;
private final DataSource dataSource;
private final IConnectionCustomizer connectionCustomizer;
private final HikariConfig configuration;
@ -78,7 +81,12 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
private int transactionIsolation;
private boolean isDebug;
HikariPool(HikariConfig configuration)
/**
* Construct a HikariPool with the specified configuration.
*
* @param configuration a HikariConfig instance
*/
public HikariPool(HikariConfig configuration)
{
this(configuration, configuration.getUsername(), configuration.getPassword());
}
@ -87,8 +95,10 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
* Construct a HikariPool with the specified configuration.
*
* @param configuration a HikariConfig instance
* @param username authentication username
* @param password authentication password
*/
HikariPool(HikariConfig configuration, String username, String password)
public HikariPool(HikariConfig configuration, String username, String password)
{
this.configuration = configuration;
this.username = username;
@ -101,7 +111,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
this.lastConnectionFailure = new AtomicReference<Throwable>();
this.catalog = configuration.getCatalog();
this.connectionCustomizer = configuration.getConnectionCustomizer();
this.connectionCustomizer = initializeCustomizer();
this.isAutoCommit = configuration.isAutoCommit();
this.isIsolateInternalQueries = configuration.isIsolateInternalQueries();
this.isReadOnly = configuration.isReadOnly();
@ -137,7 +147,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
* @return a java.sql.Connection instance
* @throws SQLException thrown if a timeout occurs trying to obtain a connection
*/
Connection getConnection() throws SQLException
public Connection getConnection() throws SQLException
{
final long start = System.currentTimeMillis();
final long maxLife = configuration.getMaxLifetime();
@ -212,7 +222,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
return configuration.getPoolName();
}
void shutdown()
public void shutdown()
{
isShutdown = true;
houseKeepingTimer.cancel();
@ -229,6 +239,38 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
}
}
public DataSource getDataSource()
{
return dataSource;
}
/**
* Permanently close a connection.
*
* @param connectionProxy the connection to actually close
*/
public void closeConnection(IHikariConnectionProxy connectionProxy)
{
try
{
int tc = totalConnections.decrementAndGet();
if (tc < 0)
{
LOGGER.warn("Internal accounting inconsistency, totalConnections=" + tc, new Exception());
}
connectionProxy.realClose();
}
catch (SQLException e)
{
return;
}
finally
{
connectionBag.remove(connectionProxy);
}
}
// ***********************************************************************
// IBagStateListener methods
// ***********************************************************************
@ -443,32 +485,6 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
}
}
/**
* Permanently close a connection.
*
* @param connectionProxy the connection to actually close
*/
void closeConnection(IHikariConnectionProxy connectionProxy)
{
try
{
int tc = totalConnections.decrementAndGet();
if (tc < 0)
{
LOGGER.warn("Internal accounting inconsistency, totalConnections=" + tc, new Exception());
}
connectionProxy.realClose();
}
catch (SQLException e)
{
return;
}
finally
{
connectionBag.remove(connectionProxy);
}
}
private DataSource initializeDataSource()
{
String dsClassName = configuration.getDataSourceClassName();
@ -476,8 +492,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
{
try
{
Class<?> clazz = this.getClass().getClassLoader().loadClass(dsClassName);
DataSource dataSource = (DataSource) clazz.newInstance();
DataSource dataSource = PoolUtilities.createInstance(dsClassName, DataSource.class);
PropertyBeanSetter.setTargetFromProperties(dataSource, configuration.getDataSourceProperties());
return dataSource;
}
@ -494,6 +509,23 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
return configuration.getDataSource();
}
private IConnectionCustomizer initializeCustomizer()
{
if (configuration.getConnectionCustomizerClassName() != null)
{
try
{
return PoolUtilities.createInstance(configuration.getConnectionCustomizerClassName(), IConnectionCustomizer.class);
}
catch (Exception e)
{
LOGGER.error("Connection customizer could not be created", e);
}
}
return null;
}
private void logPoolState(String... prefix)
{
int total = totalConnections.get();

@ -30,7 +30,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zaxxer.hikari.HikariPool;
import com.zaxxer.hikari.pool.HikariPool;
import com.zaxxer.hikari.util.FastStatementList;
/**

@ -21,7 +21,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import com.zaxxer.hikari.HikariPool;
import com.zaxxer.hikari.pool.HikariPool;
/**
* A factory class that produces proxies around instances of the standard

@ -58,6 +58,13 @@ public final class PoolUtilities
}
}
@SuppressWarnings("unchecked")
public static <T> T createInstance(String className, Class<T> clazz) throws Exception
{
Class<?> loaded = PoolUtilities.class.getClassLoader().loadClass(className);
return (T) loaded.newInstance();
}
public static ThreadPoolExecutor createThreadPoolExecutor(final int queueSize, final String threadName)
{
ThreadFactory threadFactory = new ThreadFactory() {

@ -36,14 +36,14 @@ public class ExceptionTest
@Test
public void testException1() throws SQLException
{
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
Connection connection = ds.getConnection();
Assert.assertNotNull(connection);
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
PreparedStatement statement = connection.prepareStatement("SELECT some, thing FROM somewhere WHERE something=?");
Assert.assertNotNull(statement);
@ -63,8 +63,8 @@ public class ExceptionTest
connection.close();
Assert.assertSame("Totals connections not as expected", 0, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 0, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
}
@Test
@ -99,14 +99,14 @@ public class ExceptionTest
HikariDataSource ds = new HikariDataSource(config);
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
Connection connection = ds.getConnection();
Assert.assertNotNull(connection);
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
connection.close();
@ -120,8 +120,8 @@ public class ExceptionTest
Assert.assertSame("Connection is closed", e.getMessage());
}
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
}
}

@ -23,7 +23,7 @@ public class RampUpDown
HikariDataSource ds = new HikariDataSource(config);
ds.setIdleTimeout(1000);
Assert.assertSame("Totals connections not as expected", 5, ds.pool.getTotalConnections());
Assert.assertSame("Totals connections not as expected", 5, TestElf.getPool(ds).getTotalConnections());
Connection[] connections = new Connection[ds.getMaximumPoolSize()];
for (int i = 0; i < connections.length; i++)
@ -31,7 +31,7 @@ public class RampUpDown
connections[i] = ds.getConnection();
}
Assert.assertSame("Totals connections not as expected", 60, ds.pool.getTotalConnections());
Assert.assertSame("Totals connections not as expected", 60, TestElf.getPool(ds).getTotalConnections());
for (Connection connection : connections)
{
@ -40,7 +40,7 @@ public class RampUpDown
Thread.sleep(2500);
Assert.assertSame("Totals connections not as expected", 5, ds.pool.getTotalConnections());
Assert.assertSame("Totals connections not as expected", 5, TestElf.getPool(ds).getTotalConnections());
ds.shutdown();
}

@ -21,14 +21,14 @@ public class StatementTest
HikariDataSource ds = new HikariDataSource(config);
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
Connection connection = ds.getConnection();
Assert.assertNotNull(connection);
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
Statement statement = connection.createStatement();
Assert.assertNotNull(statement);

@ -253,8 +253,8 @@ public class TestConnectionTimeoutRetry
Thread.sleep(1000);
Assert.assertSame("Totals connections not as expected", 10, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 3, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 10, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 3, TestElf.getPool(ds).getIdleConnections());
connection1.close();
connection2.close();
@ -264,7 +264,7 @@ public class TestConnectionTimeoutRetry
connection6.close();
connection7.close();
Assert.assertSame("Totals connections not as expected", 10, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 10, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 10, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 10, TestElf.getPool(ds).getIdleConnections());
}
}

@ -49,14 +49,14 @@ public class TestConnections
HikariDataSource ds = new HikariDataSource(config);
try
{
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
Connection connection = ds.getConnection();
Assert.assertNotNull(connection);
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
PreparedStatement statement = connection.prepareStatement("SELECT * FROM device WHERE device_id=?");
Assert.assertNotNull(statement);
@ -72,8 +72,8 @@ public class TestConnections
statement.close();
connection.close();
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
}
finally
{
@ -101,22 +101,22 @@ public class TestConnections
ds.setMaxLifetime(700);
Assert.assertSame("Total connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Total connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
Connection connection = ds.getConnection();
Assert.assertNotNull(connection);
Assert.assertSame("Second total connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Second idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Second total connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Second idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
connection.close();
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
Connection connection2 = ds.getConnection();
Assert.assertSame("Expected the same connection", connection, connection2);
Assert.assertSame("Second total connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Second idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Second total connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Second idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
connection2.close();
Thread.sleep(2000);
@ -126,8 +126,8 @@ public class TestConnections
connection2.close();
Assert.assertSame("Post total connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Post idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Post total connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Post idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
}
finally
{
@ -172,15 +172,15 @@ public class TestConnections
HikariDataSource ds = new HikariDataSource(config);
try
{
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
// This will take the pool down to zero
Connection connection = ds.getConnection();
Assert.assertNotNull(connection);
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
PreparedStatement statement = connection.prepareStatement("SELECT some, thing FROM somewhere WHERE something=?");
Assert.assertNotNull(statement);
@ -201,15 +201,15 @@ public class TestConnections
// The connection will be ejected from the pool here
connection.close();
Assert.assertSame("Totals connections not as expected", 0, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 0, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 0, TestElf.getPool(ds).getIdleConnections());
// This will cause a backfill
connection = ds.getConnection();
connection.close();
Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Totals connections not as expected", 1, TestElf.getPool(ds).getTotalConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
}
finally
{

@ -0,0 +1,27 @@
package com.zaxxer.hikari;
import java.lang.reflect.Field;
import com.zaxxer.hikari.pool.HikariPool;
public final class TestElf
{
private TestElf()
{
// default constructor
}
public static HikariPool getPool(HikariDataSource ds)
{
try
{
Field field = ds.getClass().getDeclaredField("pool");
field.setAccessible(true);
return (HikariPool) field.get(ds);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}

@ -42,7 +42,7 @@ public class UnwrapTest
HikariDataSource ds = new HikariDataSource(config);
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
Assert.assertSame("Idle connections not as expected", 1, TestElf.getPool(ds).getIdleConnections());
Connection connection = ds.getConnection();
Assert.assertNotNull(connection);

Loading…
Cancel
Save