diff --git a/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java b/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java index d54fcc45..7f3f199d 100644 --- a/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java +++ b/hikaricp-java6/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java @@ -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 diff --git a/hikaricp/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java b/hikaricp/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java index d54fcc45..7f3f199d 100644 --- a/hikaricp/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java +++ b/hikaricp/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java @@ -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 diff --git a/hikaricp/src/test/java/com/zaxxer/hikari/MiscTest.java b/hikaricp/src/test/java/com/zaxxer/hikari/MiscTest.java index 852d276c..47f76a6c 100644 --- a/hikaricp/src/test/java/com/zaxxer/hikari/MiscTest.java +++ b/hikaricp/src/test/java/com/zaxxer/hikari/MiscTest.java @@ -84,10 +84,68 @@ public class MiscTest } @Test - public void testBagDump() + public void testConcurrentBag() throws InterruptedException { - ConcurrentBag bag = new ConcurrentBag(null); + class TestBagEntry extends BagEntry { + } + + ConcurrentBag bag = new ConcurrentBag(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