ConcurrentBag tests, more correct DriverDataSource.

pull/192/head
Brett Wooldridge 10 years ago
parent 548620ad5f
commit 558f18a8e3

@ -17,6 +17,7 @@ package com.zaxxer.hikari.util;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
@ -28,8 +29,7 @@ public final class DriverDataSource implements DataSource
{
private final String jdbcUrl;
private final Properties driverProperties;
private PrintWriter logWriter;
private final Driver driver;
public DriverDataSource(String jdbcUrl, Properties properties, String username, String password)
{
@ -43,7 +43,7 @@ public final class DriverDataSource implements DataSource
driverProperties.put("password", driverProperties.getProperty("password", password));
}
DriverManager.getDriver(jdbcUrl);
driver = DriverManager.getDriver(jdbcUrl);
}
catch (SQLException e) {
throw new RuntimeException("Unable to get driver for JDBC URL " + jdbcUrl, e);
@ -65,13 +65,13 @@ public final class DriverDataSource implements DataSource
@Override
public PrintWriter getLogWriter() throws SQLException
{
return logWriter;
throw new SQLFeatureNotSupportedException();
}
@Override
public void setLogWriter(PrintWriter logWriter) throws SQLException
{
this.logWriter = logWriter;
throw new SQLFeatureNotSupportedException();
}
@Override
@ -88,7 +88,7 @@ public final class DriverDataSource implements DataSource
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException
{
throw new SQLFeatureNotSupportedException();
return driver.getParentLogger();
}
@Override

@ -17,6 +17,7 @@ package com.zaxxer.hikari.util;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
@ -28,8 +29,7 @@ public final class DriverDataSource implements DataSource
{
private final String jdbcUrl;
private final Properties driverProperties;
private PrintWriter logWriter;
private final Driver driver;
public DriverDataSource(String jdbcUrl, Properties properties, String username, String password)
{
@ -43,7 +43,7 @@ public final class DriverDataSource implements DataSource
driverProperties.put("password", driverProperties.getProperty("password", password));
}
DriverManager.getDriver(jdbcUrl);
driver = DriverManager.getDriver(jdbcUrl);
}
catch (SQLException e) {
throw new RuntimeException("Unable to get driver for JDBC URL " + jdbcUrl, e);
@ -65,13 +65,13 @@ public final class DriverDataSource implements DataSource
@Override
public PrintWriter getLogWriter() throws SQLException
{
return logWriter;
throw new SQLFeatureNotSupportedException();
}
@Override
public void setLogWriter(PrintWriter logWriter) throws SQLException
{
this.logWriter = logWriter;
throw new SQLFeatureNotSupportedException();
}
@Override
@ -88,7 +88,7 @@ public final class DriverDataSource implements DataSource
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException
{
throw new SQLFeatureNotSupportedException();
return driver.getParentLogger();
}
@Override

@ -84,10 +84,68 @@ public class MiscTest
}
@Test
public void testBagDump()
public void testConcurrentBag() throws InterruptedException
{
ConcurrentBag<BagEntry> bag = new ConcurrentBag<BagEntry>(null);
class TestBagEntry extends BagEntry {
}
ConcurrentBag<TestBagEntry> bag = new ConcurrentBag<TestBagEntry>(null);
Assert.assertEquals(0, bag.values(8).size());
TestBagEntry reserved = new TestBagEntry();
bag.add(reserved);
bag.reserve(reserved); // reserved
TestBagEntry notinuse = new TestBagEntry();
bag.add(new TestBagEntry()); // not in use
TestBagEntry inuse = new TestBagEntry();
bag.add(inuse);
bag.borrow(2L, TimeUnit.SECONDS); // in use
bag.dumpState();
try {
bag.requite(reserved);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
try {
bag.remove(notinuse);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
try {
bag.unreserve(notinuse);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
try {
bag.remove(inuse);
bag.remove(inuse);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
bag.close();
try {
bag.add(new TestBagEntry());
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
}
@Test

Loading…
Cancel
Save