Skip to content

Commit

Permalink
fix PropertyElf after merging 2266
Browse files Browse the repository at this point in the history
  • Loading branch information
brettwooldridge committed Nov 26, 2024
1 parent 22eb91b commit b320aa8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/main/java/com/zaxxer/hikari/util/PropertyElf.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -147,7 +146,7 @@ private static void setProperty(final Object target, final String propName, fina
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)));
Expand Down Expand Up @@ -189,10 +188,10 @@ private static String capitalizedPropertyName(String propertyName)

private static Optional<Duration> 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));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/zaxxer/hikari/pool/TestPropertySetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testDurationPropertiesSet() throws Exception
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()));
Expand All @@ -108,7 +108,7 @@ public void testDurationPropertiesSet() throws Exception
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
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/duration-config.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b320aa8

Please sign in to comment.