Add compatibility for old timeout configuration

This commit is contained in:
Paul Vorbach 2019-12-05 17:32:14 +01:00
parent 39466f6b8a
commit 0df3843602
4 changed files with 86 additions and 6 deletions

View File

@ -1,10 +1,14 @@
= KafkaHealthCheck
:icons: font
== Version 2.0.0
== Version 1.3.0
* Health check timeouts are configured in duration format.
If you changed the defaults, please adapt your configuration.
* Health check timeouts can now be configured in `java.time.Duration` format. The timeouts can still be configured using
millisecond values (`long`) as well to stay compatible with old configurations.
== Version 1.2.0
* Reduce logging level of health check calls to `TRACE`.
== Version 1.1.0

11
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>com.deviceinsight.kafka</groupId>
<artifactId>kafka-health-check</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Kafka Health Check</name>
@ -23,12 +23,13 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Versions -->
<spring-boot.version>2.1.5.RELEASE</spring-boot.version>
<spring-boot.version>2.1.10.RELEASE</spring-boot.version>
<spring.kafka.version>2.2.4.RELEASE</spring.kafka.version>
<caffeine.version>2.7.0</caffeine.version>
<awaitility.version>3.1.6</awaitility.version>
<junit.jupiter.version>5.4.2</junit.jupiter.version>
<assertj-core.version>3.11.1</assertj-core.version>
<guava.version>28.1-jre</guava.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
@ -87,6 +88,12 @@
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -25,6 +25,11 @@ public class KafkaHealthProperties {
this.sendReceiveTimeout = sendReceiveTimeout;
}
@Deprecated
public void setSendReceiveTimeoutMs(long sendReceiveTimeoutMs) {
setSendReceiveTimeout(Duration.ofMillis(sendReceiveTimeoutMs));
}
public Duration getPollTimeout() {
return pollTimeout;
}
@ -33,6 +38,11 @@ public class KafkaHealthProperties {
this.pollTimeout = pollTimeout;
}
@Deprecated
public void setPollTimeoutMs(long pollTimeoutMs) {
setPollTimeout(Duration.ofMillis(pollTimeoutMs));
}
public Duration getSubscriptionTimeout() {
return subscriptionTimeout;
}
@ -41,9 +51,14 @@ public class KafkaHealthProperties {
this.subscriptionTimeout = subscriptionTimeout;
}
@Deprecated
public void setSubscriptionTimeoutMs(long subscriptionTimeoutMs) {
setSubscriptionTimeout(Duration.ofMillis(subscriptionTimeoutMs));
}
@Override
public String toString() {
return "KafkaHealthProperties{" + "topic='" + topic + '\'' + ", sendReceiveTimeout=" + sendReceiveTimeout +
return "KafkaHealthProperties{topic='" + topic + "', sendReceiveTimeout=" + sendReceiveTimeout +
", pollTimeout=" + pollTimeout + ", subscriptionTimeout=" + subscriptionTimeout + '}';
}
}

View File

@ -0,0 +1,54 @@
package com.deviceinsight.kafka.health;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import java.time.Duration;
import java.util.stream.Stream;
public class KafkaHealthPropertiesTest {
// @formatter:off
private static final ConfigurationPropertySource DURATION_PROPERTY_SOURCE = new MapConfigurationPropertySource(ImmutableMap.of(
"kafka.health.topic", "custom-topic",
"kafka.health.send-receive-timeout", "1m",
"kafka.health.poll-timeout", "2s",
"kafka.health.subscription-timeout", "10s"
));
private static final ConfigurationPropertySource MILLISECONDS_PROPERTY_SOURCE = new MapConfigurationPropertySource(ImmutableMap.of(
"kafka.health.topic", "custom-topic",
"kafka.health.send-receive-timeout-ms", "60000",
"kafka.health.poll-timeout-ms", "2000",
"kafka.health.subscription-timeout-ms", "10000"
));
// @formatter:on
@ParameterizedTest(name = "using {0} based setters")
@MethodSource("configurationPropertySources")
public void test_that_properties_bind_to_KafkaHealthProperties(String sourceName,
ConfigurationPropertySource propertySource) {
KafkaHealthProperties kafkaHealthProperties =
new Binder(propertySource).bind("kafka.health", KafkaHealthProperties.class).get();
assertThat(kafkaHealthProperties.getTopic()).isEqualTo("custom-topic");
assertThat(kafkaHealthProperties.getSendReceiveTimeout()).isEqualTo(Duration.ofMinutes(1));
assertThat(kafkaHealthProperties.getPollTimeout()).isEqualTo(Duration.ofSeconds(2));
assertThat(kafkaHealthProperties.getSubscriptionTimeout()).isEqualTo(Duration.ofSeconds(10));
}
static Stream<Arguments> configurationPropertySources() {
return Stream.of(arguments("Duration", DURATION_PROPERTY_SOURCE),
arguments("long (milliseconds)", MILLISECONDS_PROPERTY_SOURCE));
}
}