More tests... still need to be merged into the Java 6 branch.

pull/192/head
Brett Wooldridge 11 years ago
parent 4c35cedcb1
commit 9ce9dc0465

@ -0,0 +1,49 @@
/*
* Copyright (C) 2013 Brett Wooldridge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zaxxer.hikari;
import java.io.PrintWriter;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Brett Wooldridge
*/
public class MiscTests
{
@Test
public void testLogWriter() throws SQLException
{
HikariConfig config = new HikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(4);
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
final HikariDataSource ds = new HikariDataSource(config);
try {
PrintWriter writer = new PrintWriter(System.out);
ds.setLogWriter(writer);
Assert.assertSame(writer, ds.getLogWriter());
}
finally
{
ds.close();
}
}
}

@ -20,12 +20,14 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Test;
import com.zaxxer.hikari.mocks.StubConnection;
import com.zaxxer.hikari.pool.HikariPool;
/**
* System property testProxy can be one of:
@ -322,4 +324,31 @@ public class TestConnections
ds.close();
}
}
@Test
public void testGetWithUsername() throws Exception
{
HikariConfig config = new HikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(4);
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
final HikariDataSource ds = new HikariDataSource(config);
try {
Connection connection1 = ds.getConnection("foo", "bar");
connection1.close();
Connection connection2 = ds.getConnection("faz", "baf");
connection2.close();
HashMap<Object,HikariPool> multiPool = TestElf.getMultiPool(ds);
Assert.assertTrue(multiPool.size() > 1);
Object[] array = multiPool.keySet().toArray();
Assert.assertNotEquals(array[0], array[1]);
}
finally {
ds.close();
}
}
}

@ -17,6 +17,7 @@
package com.zaxxer.hikari;
import java.lang.reflect.Field;
import java.util.HashMap;
import com.zaxxer.hikari.pool.HikariPool;
@ -27,22 +28,32 @@ import com.zaxxer.hikari.pool.HikariPool;
*/
public final class TestElf
{
private TestElf()
{
// default constructor
}
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);
}
}
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);
}
}
@SuppressWarnings("unchecked")
public static HashMap<Object, HikariPool> getMultiPool(HikariDataSource ds)
{
try {
Field field = ds.getClass().getDeclaredField("multiPool");
field.setAccessible(true);
return (HashMap<Object, HikariPool>) field.get(ds);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}

Loading…
Cancel
Save