fix PropertyElf after merging 2266

pull/2271/head
Brett Wooldridge 2 months ago
parent 22eb91b9c1
commit b320aa88c6
No known key found for this signature in database
GPG Key ID: 4CC08E7F47C3EC76

@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -147,7 +146,7 @@ public final class PropertyElf
var paramClass = writeMethod.getParameterTypes()[0]; var paramClass = writeMethod.getParameterTypes()[0];
String value = propValue.toString(); String value = propValue.toString();
if (paramClass == int.class) { 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) { else if (paramClass == long.class) {
writeMethod.invoke(target, parseDuration(value).map(Duration::toMillis).orElseGet(() -> Long.parseLong(value))); writeMethod.invoke(target, parseDuration(value).map(Duration::toMillis).orElseGet(() -> Long.parseLong(value)));
@ -189,10 +188,10 @@ public final class PropertyElf
private static Optional<Duration> parseDuration(String value) private static Optional<Duration> parseDuration(String value)
{ {
Matcher matcher = DURATION_PATTERN.matcher(value); var matcher = DURATION_PATTERN.matcher(value);
if (matcher.matches()) { if (matcher.matches()) {
long number = Long.parseLong(matcher.group("number")); var number = Long.parseLong(matcher.group("number"));
String unit = matcher.group("unit"); var unit = matcher.group("unit");
switch (unit) { switch (unit) {
case "ms": case "ms":
return Optional.of(Duration.ofMillis(number)); return Optional.of(Duration.ofMillis(number));

@ -98,7 +98,7 @@ public class TestPropertySetter
HikariConfig config = new HikariConfig(durationProperties); HikariConfig config = new HikariConfig(durationProperties);
config.validate(); 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.ofSeconds(22), Duration.ofMillis(config.getValidationTimeout()));
assertEquals(Duration.ofMinutes(33), Duration.ofMillis(config.getIdleTimeout())); assertEquals(Duration.ofMinutes(33), Duration.ofMillis(config.getIdleTimeout()));
assertEquals(Duration.ofHours(44), Duration.ofMillis(config.getLeakDetectionThreshold())); assertEquals(Duration.ofHours(44), Duration.ofMillis(config.getLeakDetectionThreshold()));
@ -108,7 +108,7 @@ public class TestPropertySetter
DataSource dataSource = (DataSource) clazz.getDeclaredConstructor().newInstance(); DataSource dataSource = (DataSource) clazz.getDeclaredConstructor().newInstance();
PropertyElf.setTargetFromProperties(dataSource, config.getDataSourceProperties()); PropertyElf.setTargetFromProperties(dataSource, config.getDataSourceProperties());
assertEquals(Duration.ofMinutes(47), Duration.ofMillis(dataSource.getLoginTimeout())); assertEquals(Duration.ofMinutes(1), Duration.ofMillis(dataSource.getLoginTimeout()));
} }
@Test @Test

@ -1,8 +1,8 @@
connectionTimeout = 11ms connectionTimeout = 2000ms
validationTimeout = 22s validationTimeout = 22s
idleTimeout = 33m idleTimeout = 33m
leakDetectionThreshold = 44h leakDetectionThreshold = 44h
maxLifetime = 55d maxLifetime = 55d
dataSourceClassName=com.zaxxer.hikari.mocks.StubDataSource dataSourceClassName=com.zaxxer.hikari.mocks.StubDataSource
dataSource.loginTimeout = 47m dataSource.loginTimeout = 60000

Loading…
Cancel
Save