Additional connection tests.

pull/60/head
Brett Wooldridge 11 years ago
parent 621dcdf12e
commit 4b0cca092c

@ -62,6 +62,18 @@ public class ConnectionStateTest
}
}
@Test
public void testIsolation() throws Exception
{
HikariConfig config = new HikariConfig();
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
config.setTransactionIsolation("TRANSACTION_REPEATABLE_READ");
config.validate();
int transactionIsolation = config.getTransactionIsolation();
Assert.assertSame(Connection.TRANSACTION_REPEATABLE_READ, transactionIsolation);
}
@Test
public void testCatalog() throws SQLException
{

@ -24,6 +24,8 @@ import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import com.zaxxer.hikari.mocks.StubConnection;
/**
* System property testProxy can be one of:
* "com.zaxxer.hikari.JavaProxyFactory"
@ -216,14 +218,50 @@ public class TestConnections
}
@Test
public void testIsolation() throws Exception
public void testMaximumPoolLimit() throws Exception
{
HikariConfig config = new HikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(4);
config.setInitializationFailFast(true);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
config.setTransactionIsolation("TRANSACTION_REPEATABLE_READ");
config.validate();
int transactionIsolation = config.getTransactionIsolation();
Assert.assertSame(Connection.TRANSACTION_REPEATABLE_READ, transactionIsolation);
StubConnection.count.set(0);
final HikariDataSource ds = new HikariDataSource(config);
Thread[] threads = new Thread[20];
for (int i = 0; i < threads.length; i++)
{
threads[i] = new Thread(new Runnable() {
public void run()
{
try
{
Connection connection = ds.getConnection();
Thread.sleep(1000);
connection.close();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
for (int i = 0; i < threads.length; i++)
{
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
{
threads[i].join();
}
Assert.assertEquals(4, StubConnection.count.get());
}
}

@ -34,6 +34,7 @@ import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
/**
*
@ -41,6 +42,8 @@ import java.util.concurrent.Executor;
*/
public class StubConnection extends StubBaseConnection implements Connection
{
public static AtomicInteger count = new AtomicInteger();
private static long foo;
private boolean autoCommit;
private int isolation;
@ -51,6 +54,11 @@ public class StubConnection extends StubBaseConnection implements Connection
foo = System.currentTimeMillis();
}
public StubConnection()
{
count.incrementAndGet();
}
/** {@inheritDoc} */
@Override
public <T> T unwrap(Class<T> iface) throws SQLException

Loading…
Cancel
Save