diff --git a/src/main/java/com/zaxxer/hikari/util/PropertyElf.java b/src/main/java/com/zaxxer/hikari/util/PropertyElf.java index 7b912cba..7797be02 100644 --- a/src/main/java/com/zaxxer/hikari/util/PropertyElf.java +++ b/src/main/java/com/zaxxer/hikari/util/PropertyElf.java @@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory; import java.lang.reflect.Method; import java.time.Duration; import java.util.*; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -147,7 +146,7 @@ public final class PropertyElf var paramClass = writeMethod.getParameterTypes()[0]; String value = propValue.toString(); if (paramClass == int.class) { - writeMethod.invoke(target, parseDuration(value).map(duration -> (int) duration.toMillis()).orElseGet(() -> Integer.parseInt(value))); + writeMethod.invoke(target, Integer.parseInt(propValue.toString())); } else if (paramClass == long.class) { writeMethod.invoke(target, parseDuration(value).map(Duration::toMillis).orElseGet(() -> Long.parseLong(value))); @@ -189,10 +188,10 @@ public final class PropertyElf private static Optional parseDuration(String value) { - Matcher matcher = DURATION_PATTERN.matcher(value); + var matcher = DURATION_PATTERN.matcher(value); if (matcher.matches()) { - long number = Long.parseLong(matcher.group("number")); - String unit = matcher.group("unit"); + var number = Long.parseLong(matcher.group("number")); + var unit = matcher.group("unit"); switch (unit) { case "ms": return Optional.of(Duration.ofMillis(number)); diff --git a/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java b/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java index bc095411..c25a3a25 100644 --- a/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java +++ b/src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java @@ -98,7 +98,7 @@ public class TestPropertySetter HikariConfig config = new HikariConfig(durationProperties); config.validate(); - assertEquals(Duration.ofMillis(11), Duration.ofMillis(config.getConnectionTimeout())); + assertEquals(Duration.ofMillis(2000), Duration.ofMillis(config.getConnectionTimeout())); assertEquals(Duration.ofSeconds(22), Duration.ofMillis(config.getValidationTimeout())); assertEquals(Duration.ofMinutes(33), Duration.ofMillis(config.getIdleTimeout())); assertEquals(Duration.ofHours(44), Duration.ofMillis(config.getLeakDetectionThreshold())); @@ -108,7 +108,7 @@ public class TestPropertySetter DataSource dataSource = (DataSource) clazz.getDeclaredConstructor().newInstance(); PropertyElf.setTargetFromProperties(dataSource, config.getDataSourceProperties()); - assertEquals(Duration.ofMinutes(47), Duration.ofMillis(dataSource.getLoginTimeout())); + assertEquals(Duration.ofMinutes(1), Duration.ofMillis(dataSource.getLoginTimeout())); } @Test diff --git a/src/test/resources/duration-config.properties b/src/test/resources/duration-config.properties index bc90571e..e98f96bd 100644 --- a/src/test/resources/duration-config.properties +++ b/src/test/resources/duration-config.properties @@ -1,8 +1,8 @@ -connectionTimeout = 11ms +connectionTimeout = 2000ms validationTimeout = 22s idleTimeout = 33m leakDetectionThreshold = 44h maxLifetime = 55d dataSourceClassName=com.zaxxer.hikari.mocks.StubDataSource -dataSource.loginTimeout = 47m +dataSource.loginTimeout = 60000