lint cleanup and Visual Studio Code files

pull/1716/head
Brett Wooldridge 4 years ago
parent f715bdaa53
commit 04919ad540

@ -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

@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false

@ -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

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

@ -0,0 +1,2 @@
BUNDLE_ROOT_PATH=target/classes
eclipse.preferences.version=1

@ -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

@ -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;

@ -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;

@ -456,7 +456,6 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag
}
}
@SuppressWarnings("unused")
int[] getPoolStateCounts()
{
return connectionBag.getStateCounts();

@ -19,7 +19,6 @@ public abstract class ProxyDatabaseMetaData implements DatabaseMetaData
this.delegate = metaData;
}
@SuppressWarnings("unused")
final SQLException checkException(SQLException e)
{
return connection.checkException(e);

@ -26,7 +26,6 @@ import com.zaxxer.hikari.util.FastList;
*
* @author Brett Wooldridge
*/
@SuppressWarnings("unused")
public final class ProxyFactory
{
private ProxyFactory()

@ -40,7 +40,6 @@ public abstract class ProxyStatement implements Statement
this.delegate = statement;
}
@SuppressWarnings("unused")
final SQLException checkException(SQLException e)
{
return connection.checkException(e);

@ -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);

@ -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);
}
}

@ -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];

@ -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;

@ -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 {

@ -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;

@ -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
{

@ -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;

@ -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,10 +21,10 @@ import static org.junit.Assert.assertTrue;
*/
public class MetricsTrackerTest
{
@Test(expected = SQLTransientConnectionException.class)
@Test
public void connectionTimeoutIsRecorded() throws Exception
{
assertThrows(SQLTransientConnectionException.class, () -> {
int timeoutMillis = 1000;
int timeToCreateNewConnectionMillis = timeoutMillis * 2;
@ -47,13 +48,16 @@ public class MetricsTrackerTest
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;

@ -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;
}
}

@ -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;
}

@ -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
}
}
}

@ -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);

@ -1,6 +1,5 @@
package com.zaxxer.hikari.util;
import org.junit.Assert;
import org.junit.Test;
import com.zaxxer.hikari.mocks.TestObject;

@ -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<PoolEntry> bag = new ConcurrentBag<>((x) -> CompletableFuture.completedFuture(Boolean.TRUE))) {

Loading…
Cancel
Save