diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..b2f859fc --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding//target/classes=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 00000000..d4313d4b --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..2b5d9924 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,18 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.pde.core.prefs b/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 00000000..ba582c22 --- /dev/null +++ b/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,2 @@ +BUNDLE_ROOT_PATH=target/classes +eclipse.preferences.version=1 diff --git a/src/main/java/com/zaxxer/hikari/HikariConfig.java b/src/main/java/com/zaxxer/hikari/HikariConfig.java index e1a375c1..e982091b 100644 --- a/src/main/java/com/zaxxer/hikari/HikariConfig.java +++ b/src/main/java/com/zaxxer/hikari/HikariConfig.java @@ -45,7 +45,7 @@ import static com.zaxxer.hikari.util.UtilityElf.safeIsAssignableFrom; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; -@SuppressWarnings({"SameParameterValue", "unused"}) +@SuppressWarnings({"SameParameterValue"}) public class HikariConfig implements HikariConfigMXBean { private static final Logger LOGGER = LoggerFactory.getLogger(HikariConfig.class); @@ -1131,7 +1131,7 @@ public class HikariConfig implements HikariConfigMXBean else if (value == null) { value = "none"; } - LOGGER.debug((prop + "................................................").substring(0, 32) + value); + LOGGER.debug("{}{}", (prop + "................................................".substring(0, 32)), value); } catch (Exception e) { // continue diff --git a/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodahaleHealthChecker.java b/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodahaleHealthChecker.java index 9b04a221..2aee2e83 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodahaleHealthChecker.java +++ b/src/main/java/com/zaxxer/hikari/metrics/dropwizard/CodahaleHealthChecker.java @@ -22,8 +22,6 @@ import java.util.Properties; import java.util.SortedMap; import java.util.concurrent.TimeUnit; -import com.codahale.metrics.Metric; -import com.codahale.metrics.MetricFilter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import com.codahale.metrics.health.HealthCheck; diff --git a/src/main/java/com/zaxxer/hikari/metrics/micrometer/MicrometerMetricsTracker.java b/src/main/java/com/zaxxer/hikari/metrics/micrometer/MicrometerMetricsTracker.java index 08b3009d..b20548b5 100644 --- a/src/main/java/com/zaxxer/hikari/metrics/micrometer/MicrometerMetricsTracker.java +++ b/src/main/java/com/zaxxer/hikari/metrics/micrometer/MicrometerMetricsTracker.java @@ -48,24 +48,23 @@ public class MicrometerMetricsTracker implements IMetricsTracker private static final String METRIC_NAME_MAX_CONNECTIONS = HIKARI_METRIC_NAME_PREFIX + ".connections.max"; private static final String METRIC_NAME_MIN_CONNECTIONS = HIKARI_METRIC_NAME_PREFIX + ".connections.min"; - private final Timer connectionObtainTimer; private final Counter connectionTimeoutCounter; private final Timer connectionUsage; private final Timer connectionCreation; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final Gauge totalConnectionGauge; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final Gauge idleConnectionGauge; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final Gauge activeConnectionGauge; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final Gauge pendingConnectionGauge; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final Gauge maxConnectionGauge; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final Gauge minConnectionGauge; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final PoolStats poolStats; private final MeterRegistry meterRegistry; diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index e505f68b..427d34fa 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -456,7 +456,6 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag } } - @SuppressWarnings("unused") int[] getPoolStateCounts() { return connectionBag.getStateCounts(); diff --git a/src/main/java/com/zaxxer/hikari/pool/ProxyDatabaseMetaData.java b/src/main/java/com/zaxxer/hikari/pool/ProxyDatabaseMetaData.java index 09cc4558..d2ed734e 100644 --- a/src/main/java/com/zaxxer/hikari/pool/ProxyDatabaseMetaData.java +++ b/src/main/java/com/zaxxer/hikari/pool/ProxyDatabaseMetaData.java @@ -19,7 +19,6 @@ public abstract class ProxyDatabaseMetaData implements DatabaseMetaData this.delegate = metaData; } - @SuppressWarnings("unused") final SQLException checkException(SQLException e) { return connection.checkException(e); diff --git a/src/main/java/com/zaxxer/hikari/pool/ProxyFactory.java b/src/main/java/com/zaxxer/hikari/pool/ProxyFactory.java index 467d15f9..0f6d6bf1 100644 --- a/src/main/java/com/zaxxer/hikari/pool/ProxyFactory.java +++ b/src/main/java/com/zaxxer/hikari/pool/ProxyFactory.java @@ -26,7 +26,6 @@ import com.zaxxer.hikari.util.FastList; * * @author Brett Wooldridge */ -@SuppressWarnings("unused") public final class ProxyFactory { private ProxyFactory() diff --git a/src/main/java/com/zaxxer/hikari/pool/ProxyStatement.java b/src/main/java/com/zaxxer/hikari/pool/ProxyStatement.java index 737ab16d..56bf38d4 100644 --- a/src/main/java/com/zaxxer/hikari/pool/ProxyStatement.java +++ b/src/main/java/com/zaxxer/hikari/pool/ProxyStatement.java @@ -40,7 +40,6 @@ public abstract class ProxyStatement implements Statement this.delegate = statement; } - @SuppressWarnings("unused") final SQLException checkException(SQLException e) { return connection.checkException(e); diff --git a/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java b/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java index c6794c25..f3230ef6 100644 --- a/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java +++ b/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java @@ -50,10 +50,10 @@ public final class DriverDataSource implements DataSource } if (username != null) { - driverProperties.put(USER, driverProperties.getProperty("user", username)); + driverProperties.put(USER, driverProperties.getProperty(USER, username)); } if (password != null) { - driverProperties.put(PASSWORD, driverProperties.getProperty("password", password)); + driverProperties.put(PASSWORD, driverProperties.getProperty(PASSWORD, password)); } if (driverClassName != null) { @@ -92,7 +92,7 @@ public final class DriverDataSource implements DataSource if (driverClass != null) { try { - driver = (Driver) driverClass.newInstance(); + driver = (Driver) driverClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { LOGGER.warn("Failed to create instance of driver class {}, trying jdbcUrl resolution", driverClassName, e); } @@ -126,13 +126,13 @@ public final class DriverDataSource implements DataSource { final Properties cloned = (Properties) driverProperties.clone(); if (username != null) { - cloned.put("user", username); + cloned.put(USER, username); if (cloned.containsKey("username")) { cloned.put("username", username); } } if (password != null) { - cloned.put("password", password); + cloned.put(PASSWORD, password); } return driver.connect(jdbcUrl, cloned); diff --git a/src/main/java/com/zaxxer/hikari/util/PropertyElf.java b/src/main/java/com/zaxxer/hikari/util/PropertyElf.java index 0e1036e5..43e71c0b 100644 --- a/src/main/java/com/zaxxer/hikari/util/PropertyElf.java +++ b/src/main/java/com/zaxxer/hikari/util/PropertyElf.java @@ -154,11 +154,11 @@ public final class PropertyElf } else { try { - logger.debug("Try to create a new instance of \"{}\"", propValue.toString()); - writeMethod.invoke(target, Class.forName(propValue.toString()).newInstance()); + logger.debug("Try to create a new instance of \"{}\"", propValue); + writeMethod.invoke(target, Class.forName(propValue.toString()).getDeclaredConstructor().newInstance()); } catch (InstantiationException | ClassNotFoundException e) { - logger.debug("Class \"{}\" not found or could not instantiate it (Default constructor)", propValue.toString()); + logger.debug("Class \"{}\" not found or could not instantiate it (Default constructor)", propValue); writeMethod.invoke(target, propValue); } } diff --git a/src/main/java/com/zaxxer/hikari/util/UtilityElf.java b/src/main/java/com/zaxxer/hikari/util/UtilityElf.java index 62c12264..1017f80e 100644 --- a/src/main/java/com/zaxxer/hikari/util/UtilityElf.java +++ b/src/main/java/com/zaxxer/hikari/util/UtilityElf.java @@ -29,6 +29,11 @@ import static java.util.concurrent.TimeUnit.SECONDS; */ public final class UtilityElf { + private UtilityElf() + { + // non-constructable + } + /** * * @return null if string is null or empty @@ -88,7 +93,7 @@ public final class UtilityElf try { Class loaded = UtilityElf.class.getClassLoader().loadClass(className); if (args.length == 0) { - return clazz.cast(loaded.newInstance()); + return clazz.cast(loaded.getDeclaredConstructor().newInstance()); } Class[] argClasses = new Class[args.length]; diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java index 8d08792a..93833cd2 100644 --- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java +++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/HikariCPCollectorTest.java @@ -20,7 +20,7 @@ import static com.zaxxer.hikari.pool.TestElf.newHikariConfig; import static com.zaxxer.hikari.util.UtilityElf.quietlySleep; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.sql.Connection; import java.util.List; diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java index e2694074..4d74dd66 100644 --- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java +++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusHistogramMetricsTrackerTest.java @@ -28,7 +28,7 @@ import java.sql.SQLTransientConnectionException; import static com.zaxxer.hikari.pool.TestElf.newHikariConfig; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class PrometheusHistogramMetricsTrackerTest { diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java index eb838111..42fa39d2 100644 --- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java +++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerFactoryTest.java @@ -1,6 +1,5 @@ package com.zaxxer.hikari.metrics.prometheus; -import com.zaxxer.hikari.metrics.PoolStats; import com.zaxxer.hikari.mocks.StubPoolStats; import io.prometheus.client.Collector; import io.prometheus.client.CollectorRegistry; diff --git a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java index 677d33f3..8fb8c786 100644 --- a/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java +++ b/src/test/java/com/zaxxer/hikari/metrics/prometheus/PrometheusMetricsTrackerTest.java @@ -31,7 +31,7 @@ import static com.zaxxer.hikari.pool.TestElf.newHikariConfig; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class PrometheusMetricsTrackerTest { diff --git a/src/test/java/com/zaxxer/hikari/mocks/StubConnection.java b/src/test/java/com/zaxxer/hikari/mocks/StubConnection.java index 4660fbc8..a073a720 100644 --- a/src/test/java/com/zaxxer/hikari/mocks/StubConnection.java +++ b/src/test/java/com/zaxxer/hikari/mocks/StubConnection.java @@ -42,7 +42,7 @@ import com.zaxxer.hikari.util.UtilityElf; * * @author Brett Wooldridge */ -public class StubConnection extends StubBaseConnection implements Connection +public class StubConnection extends StubBaseConnection { public static final AtomicInteger count = new AtomicInteger(); public static volatile boolean slowCreate; diff --git a/src/test/java/com/zaxxer/hikari/pool/MetricsTrackerTest.java b/src/test/java/com/zaxxer/hikari/pool/MetricsTrackerTest.java index 494fd4db..1edb59cd 100644 --- a/src/test/java/com/zaxxer/hikari/pool/MetricsTrackerTest.java +++ b/src/test/java/com/zaxxer/hikari/pool/MetricsTrackerTest.java @@ -12,7 +12,8 @@ import java.util.concurrent.TimeUnit; import static com.zaxxer.hikari.pool.TestElf.newHikariDataSource; import static junit.framework.TestCase.fail; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; /** @@ -20,40 +21,43 @@ import static org.junit.Assert.assertTrue; */ public class MetricsTrackerTest { - - @Test(expected = SQLTransientConnectionException.class) + @Test public void connectionTimeoutIsRecorded() throws Exception { - int timeoutMillis = 1000; - int timeToCreateNewConnectionMillis = timeoutMillis * 2; + assertThrows(SQLTransientConnectionException.class, () -> { + int timeoutMillis = 1000; + int timeToCreateNewConnectionMillis = timeoutMillis * 2; + + StubDataSource stubDataSource = new StubDataSource(); + stubDataSource.setConnectionAcquistionTime(timeToCreateNewConnectionMillis); - StubDataSource stubDataSource = new StubDataSource(); - stubDataSource.setConnectionAcquistionTime(timeToCreateNewConnectionMillis); + StubMetricsTracker metricsTracker = new StubMetricsTracker(); - StubMetricsTracker metricsTracker = new StubMetricsTracker(); + try (HikariDataSource ds = newHikariDataSource()) { + ds.setMinimumIdle(0); + ds.setMaximumPoolSize(1); + ds.setConnectionTimeout(timeoutMillis); + ds.setDataSource(stubDataSource); + ds.setMetricsTrackerFactory((poolName, poolStats) -> metricsTracker); - try (HikariDataSource ds = newHikariDataSource()) { - ds.setMinimumIdle(0); - ds.setMaximumPoolSize(1); - ds.setConnectionTimeout(timeoutMillis); - ds.setDataSource(stubDataSource); - ds.setMetricsTrackerFactory((poolName, poolStats) -> metricsTracker); + try (Connection c = ds.getConnection()) { + fail("Connection shouldn't have been successfully created due to configured connection timeout"); - try (Connection c = ds.getConnection()) { - fail("Connection shouldn't have been successfully created due to configured connection timeout"); + } finally { + // assert that connection timeout was measured + assertThat(metricsTracker.connectionTimeoutRecorded, is(true)); + // assert that measured time to acquire connection should be roughly equal or greater than the configured connection timeout time + assertTrue(metricsTracker.connectionAcquiredNanos >= TimeUnit.NANOSECONDS.convert(timeoutMillis, TimeUnit.MILLISECONDS)); - } finally { - // assert that connection timeout was measured - assertThat(metricsTracker.connectionTimeoutRecorded, is(true)); - // assert that measured time to acquire connection should be roughly equal or greater than the configured connection timeout time - assertTrue(metricsTracker.connectionAcquiredNanos >= TimeUnit.NANOSECONDS.convert(timeoutMillis, TimeUnit.MILLISECONDS)); + metricsTracker.close(); + } } - } + }); } + @SuppressWarnings("unused") private static class StubMetricsTracker implements IMetricsTracker { - private Long connectionCreatedMillis; private Long connectionAcquiredNanos; private Long connectionBorrowedMillis; diff --git a/src/test/java/com/zaxxer/hikari/pool/PostgresTest.java b/src/test/java/com/zaxxer/hikari/pool/PostgresTest.java index f05d6442..22cb5e14 100644 --- a/src/test/java/com/zaxxer/hikari/pool/PostgresTest.java +++ b/src/test/java/com/zaxxer/hikari/pool/PostgresTest.java @@ -16,7 +16,6 @@ package com.zaxxer.hikari.pool; -import static com.zaxxer.hikari.pool.TestElf.getPool; import static com.zaxxer.hikari.pool.TestElf.newHikariConfig; import static com.zaxxer.hikari.util.ClockSource.currentTime; import static com.zaxxer.hikari.util.ClockSource.elapsedMillis; @@ -25,12 +24,8 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.*; import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -39,7 +34,6 @@ import org.junit.Before; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import com.zaxxer.hikari.util.UtilityElf; import org.junit.Test; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.utility.DockerImageName; @@ -48,7 +42,7 @@ public class PostgresTest { private static final DockerImageName IMAGE_NAME = DockerImageName.parse("postgres:9.6.20"); - private PostgreSQLContainer postgres; + private PostgreSQLContainer postgres; @Before public void beforeTest() { @@ -191,22 +185,7 @@ public class PostgresTest System.err.println("\n"); } - static private void countdown(int seconds) - { - do { - System.out.printf("Starting in %d seconds...\n", seconds); - if (seconds > 10) { - UtilityElf.quietlySleep(SECONDS.toMillis(10)); - seconds -= 10; - } - else { - UtilityElf.quietlySleep(SECONDS.toMillis(1)); - seconds -= 1; - } - } while (seconds > 0); - } - - static private HikariConfig createConfig(PostgreSQLContainer postgres) { + static private HikariConfig createConfig(PostgreSQLContainer postgres) { HikariConfig config = newHikariConfig(); config.setJdbcUrl(postgres.getJdbcUrl()); config.setUsername(postgres.getUsername()); @@ -214,5 +193,4 @@ public class PostgresTest config.setDriverClassName(postgres.getDriverClassName()); return config; } - } diff --git a/src/test/java/com/zaxxer/hikari/pool/TestElf.java b/src/test/java/com/zaxxer/hikari/pool/TestElf.java index 81c88481..7846970a 100644 --- a/src/test/java/com/zaxxer/hikari/pool/TestElf.java +++ b/src/test/java/com/zaxxer/hikari/pool/TestElf.java @@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Property; import org.apache.logging.log4j.core.layout.CsvLogEventLayout; import org.apache.logging.slf4j.Log4jLogger; import org.slf4j.LoggerFactory; @@ -187,7 +188,7 @@ public final class TestElf StringAppender(final String name, final PrintStream stream) { - super(name, null, CsvLogEventLayout.createDefaultLayout()); + super(name, null, CsvLogEventLayout.createDefaultLayout(), true, Property.EMPTY_ARRAY); this.stream = stream; } diff --git a/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java b/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java index fb104464..2a8f4984 100644 --- a/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java +++ b/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java @@ -57,7 +57,7 @@ public class TestPropertySetter config.validate(); Class clazz = this.getClass().getClassLoader().loadClass(config.getDataSourceClassName()); - DataSource dataSource = (DataSource) clazz.newInstance(); + DataSource dataSource = (DataSource) clazz.getDeclaredConstructor().newInstance(); PropertyElf.setTargetFromProperties(dataSource, config.getDataSourceProperties()); } @@ -70,7 +70,7 @@ public class TestPropertySetter config.addDataSourceProperty("logWriter", writer); Class clazz = this.getClass().getClassLoader().loadClass(config.getDataSourceClassName()); - DataSource dataSource = (DataSource) clazz.newInstance(); + DataSource dataSource = (DataSource) clazz.getDeclaredConstructor().newInstance(); PropertyElf.setTargetFromProperties(dataSource, config.getDataSourceProperties()); assertSame(PrintWriter.class, dataSource.getLogWriter().getClass()); @@ -85,7 +85,7 @@ public class TestPropertySetter config.validate(); Class clazz = this.getClass().getClassLoader().loadClass(config.getDataSourceClassName()); - DataSource dataSource = (DataSource) clazz.newInstance(); + DataSource dataSource = (DataSource) clazz.getDeclaredConstructor().newInstance(); PropertyElf.setTargetFromProperties(dataSource, config.getDataSourceProperties()); } @@ -106,6 +106,7 @@ public class TestPropertySetter fail(); } catch (RuntimeException e) { + // fall-thru } } } diff --git a/src/test/java/com/zaxxer/hikari/pool/SaturatedPoolTest830.java b/src/test/java/com/zaxxer/hikari/pool/TestSaturatedPool830.java similarity index 95% rename from src/test/java/com/zaxxer/hikari/pool/SaturatedPoolTest830.java rename to src/test/java/com/zaxxer/hikari/pool/TestSaturatedPool830.java index db8f9707..7d645ff9 100644 --- a/src/test/java/com/zaxxer/hikari/pool/SaturatedPoolTest830.java +++ b/src/test/java/com/zaxxer/hikari/pool/TestSaturatedPool830.java @@ -16,14 +16,12 @@ package com.zaxxer.hikari.pool; -import static com.zaxxer.hikari.pool.TestElf.getConcurrentBag; import static com.zaxxer.hikari.pool.TestElf.getPool; import static com.zaxxer.hikari.pool.TestElf.newHikariConfig; import static com.zaxxer.hikari.pool.TestElf.setSlf4jLogLevel; import static com.zaxxer.hikari.util.ClockSource.currentTime; import static com.zaxxer.hikari.util.ClockSource.elapsedMillis; import static com.zaxxer.hikari.util.UtilityElf.quietlySleep; -import static java.lang.Math.round; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; @@ -33,7 +31,6 @@ import java.sql.Statement; import java.util.Arrays; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.apache.logging.log4j.Level; @@ -49,9 +46,9 @@ import com.zaxxer.hikari.mocks.StubStatement; /** * @author Brett Wooldridge */ -public class SaturatedPoolTest830 +public class TestSaturatedPool830 { - private static final Logger LOGGER = LoggerFactory.getLogger(SaturatedPoolTest830.class); + private static final Logger LOGGER = LoggerFactory.getLogger(TestSaturatedPool830.class); private static final int MAX_POOL_SIZE = 10; @Test @@ -144,7 +141,7 @@ outer: while (true) { quietlySleep(50); } - assertEquals("Rate not in balance at 10req/s", SECONDS.toMillis(1) / sleep, 10L); + assertEquals("Rate not in balance at 10req/s", 10L, SECONDS.toMillis(1) / sleep); } finally { StubStatement.setSimulatedQueryTime(0); diff --git a/src/test/java/com/zaxxer/hikari/util/PropertyElfTest.java b/src/test/java/com/zaxxer/hikari/util/PropertyElfTest.java index f37b5a50..983ef0bf 100644 --- a/src/test/java/com/zaxxer/hikari/util/PropertyElfTest.java +++ b/src/test/java/com/zaxxer/hikari/util/PropertyElfTest.java @@ -1,6 +1,5 @@ package com.zaxxer.hikari.util; -import org.junit.Assert; import org.junit.Test; import com.zaxxer.hikari.mocks.TestObject; diff --git a/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java b/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java index 2537c199..95098bc0 100644 --- a/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java +++ b/src/test/java/com/zaxxer/hikari/util/TomcatConcurrentBagLeakTest.java @@ -51,7 +51,7 @@ public class TomcatConcurrentBagLeakTest ClassLoader cl = new FauxWebClassLoader(); Class clazz = cl.loadClass(this.getClass().getName() + "$FauxWebContext"); - Object fauxWebContext = clazz.newInstance(); + Object fauxWebContext = clazz.getDeclaredConstructor().newInstance(); Method createConcurrentBag = clazz.getDeclaredMethod("createConcurrentBag"); createConcurrentBag.invoke(fauxWebContext); @@ -68,7 +68,7 @@ public class TomcatConcurrentBagLeakTest ClassLoader cl = this.getClass().getClassLoader(); Class clazz = cl.loadClass(this.getClass().getName() + "$FauxWebContext"); - Object fauxWebContext = clazz.newInstance(); + Object fauxWebContext = clazz.getDeclaredConstructor().newInstance(); Method createConcurrentBag = clazz.getDeclaredMethod("createConcurrentBag"); createConcurrentBag.invoke(fauxWebContext); @@ -102,7 +102,6 @@ public class TomcatConcurrentBagLeakTest } } - @SuppressWarnings("unused") public static class FauxWebContext { private static final Logger log = LoggerFactory.getLogger(FauxWebContext.class); @@ -110,7 +109,7 @@ public class TomcatConcurrentBagLeakTest @SuppressWarnings("WeakerAccess") public Exception failureException; - @SuppressWarnings({"unused", "ResultOfMethodCallIgnored"}) + @SuppressWarnings({"ResultOfMethodCallIgnored"}) public void createConcurrentBag() throws InterruptedException { try (ConcurrentBag bag = new ConcurrentBag<>((x) -> CompletableFuture.completedFuture(Boolean.TRUE))) {