Skip to content

Commit

Permalink
lint cleanup and Visual Studio Code files
Browse files Browse the repository at this point in the history
  • Loading branch information
brettwooldridge committed Jan 13, 2021
1 parent f715bda commit 04919ad
Show file tree
Hide file tree
Showing 27 changed files with 101 additions and 92 deletions.
7 changes: 7 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -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/<project>=UTF-8
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
18 changes: 18 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
2 changes: 2 additions & 0 deletions .settings/org.eclipse.pde.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_ROOT_PATH=target/classes
eclipse.preferences.version=1
4 changes: 2 additions & 2 deletions src/main/java/com/zaxxer/hikari/HikariConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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);
Expand Down Expand Up @@ -1131,7 +1131,7 @@ else if (value instanceof String) {
else if (value == null) {
value = "none";
}
LOGGER.debug((prop + "................................................").substring(0, 32) + value);
LOGGER.debug("{}{}", (prop + "................................................".substring(0, 32)), value);
}
catch (Exception e) {
// continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/zaxxer/hikari/pool/HikariPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ void closeConnection(final PoolEntry poolEntry, final String closureReason)
}
}

@SuppressWarnings("unused")
int[] getPoolStateCounts()
{
return connectionBag.getStateCounts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public abstract class ProxyDatabaseMetaData implements DatabaseMetaData
this.delegate = metaData;
}

@SuppressWarnings("unused")
final SQLException checkException(SQLException e)
{
return connection.checkException(e);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/zaxxer/hikari/pool/ProxyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*
* @author Brett Wooldridge
*/
@SuppressWarnings("unused")
public final class ProxyFactory
{
private ProxyFactory()
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/zaxxer/hikari/pool/ProxyStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public abstract class ProxyStatement implements Statement
this.delegate = statement;
}

@SuppressWarnings("unused")
final SQLException checkException(SQLException e)
{
return connection.checkException(e);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/zaxxer/hikari/util/DriverDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public DriverDataSource(String jdbcUrl, String driverClassName, Properties prope
}

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) {
Expand Down Expand Up @@ -92,7 +92,7 @@ public DriverDataSource(String jdbcUrl, String driverClassName, Properties prope

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);
}
Expand Down Expand Up @@ -126,13 +126,13 @@ public Connection getConnection(final String username, final String password) th
{
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);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/zaxxer/hikari/util/PropertyElf.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ else if (paramClass == String.class) {
}
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);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/zaxxer/hikari/util/UtilityElf.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
*/
public final class UtilityElf
{
private UtilityElf()
{
// non-constructable
}

/**
*
* @return null if string is null or empty
Expand Down Expand Up @@ -88,7 +93,7 @@ public static <T> T createInstance(final String className, final Class<T> clazz,
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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class PrometheusHistogramMetricsTrackerTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
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
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/zaxxer/hikari/mocks/StubConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* @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;
Expand Down
50 changes: 27 additions & 23 deletions src/test/java/com/zaxxer/hikari/pool/MetricsTrackerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,52 @@
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;

/**
* @author wvuong@chariotsolutions.com on 2/16/17.
*/
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;
Expand Down
26 changes: 2 additions & 24 deletions src/test/java/com/zaxxer/hikari/pool/PostgresTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,12 +24,8 @@
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;

Expand All @@ -39,7 +34,6 @@

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;
Expand All @@ -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() {
Expand Down Expand Up @@ -191,28 +185,12 @@ public void before()
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());
config.setPassword(postgres.getPassword());
config.setDriverClassName(postgres.getDriverClassName());
return config;
}

}
Loading

0 comments on commit 04919ad

Please sign in to comment.