This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit d8ceefb911882c073a7da69310afbfdbf0825b54 Author: LanKhuat <[email protected]> AuthorDate: Wed Mar 25 18:01:50 2020 +0700 JAMES-3117 Remove 'intialDelay', change 'period' to Duration type --- .../destination/conf/healthcheck.properties | 3 - .../destination/conf/healthcheck.properties | 7 +- .../destination/conf/healthcheck.properties | 7 +- .../destination/conf/healthcheck.properties | 7 +- .../destination/conf/healthcheck.properties | 7 +- .../jpa/destination/conf/healthcheck.properties | 7 +- .../memory/destination/conf/healthcheck.properties | 7 +- .../james/PeriodicalHealthChecksConfiguration.java | 54 +++------ .../PeriodicalHealthChecksConfigurationTest.java | 128 ++++++++------------- src/site/xdoc/server/config-healthcheck.xml | 3 - 10 files changed, 79 insertions(+), 151 deletions(-) diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/healthcheck.properties b/dockerfiles/run/guice/cassandra-ldap/destination/conf/healthcheck.properties index 23b9879..235a828 100644 --- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/healthcheck.properties +++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/healthcheck.properties @@ -22,9 +22,6 @@ # Read https://james.apache.org/server/config-healthcheck.html for further details -# Optional. Initial delay in seconds before PeriodicalHealthChecks starts. Default value is 60 -# healthcheck.initial.delay=60 - # Optional. Period in seconds between two PeriodicalHealthChecks. Default value is 60 # healthcheck.period=60 diff --git a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/healthcheck.properties b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/healthcheck.properties index 23b9879..24873dc 100644 --- a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/healthcheck.properties +++ b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/healthcheck.properties @@ -22,9 +22,6 @@ # Read https://james.apache.org/server/config-healthcheck.html for further details -# Optional. Initial delay in seconds before PeriodicalHealthChecks starts. Default value is 60 -# healthcheck.initial.delay=60 - -# Optional. Period in seconds between two PeriodicalHealthChecks. Default value is 60 -# healthcheck.period=60 +# Optional. Period between two PeriodicalHealthChecks. The formats accepted are based on the ISO-8601 duration format. Default duration is 60 seconds. +# healthcheck.period=PT60s diff --git a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/healthcheck.properties b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/healthcheck.properties index 23b9879..24873dc 100644 --- a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/healthcheck.properties +++ b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/healthcheck.properties @@ -22,9 +22,6 @@ # Read https://james.apache.org/server/config-healthcheck.html for further details -# Optional. Initial delay in seconds before PeriodicalHealthChecks starts. Default value is 60 -# healthcheck.initial.delay=60 - -# Optional. Period in seconds between two PeriodicalHealthChecks. Default value is 60 -# healthcheck.period=60 +# Optional. Period between two PeriodicalHealthChecks. The formats accepted are based on the ISO-8601 duration format. Default duration is 60 seconds. +# healthcheck.period=PT60s diff --git a/dockerfiles/run/guice/cassandra/destination/conf/healthcheck.properties b/dockerfiles/run/guice/cassandra/destination/conf/healthcheck.properties index 23b9879..24873dc 100644 --- a/dockerfiles/run/guice/cassandra/destination/conf/healthcheck.properties +++ b/dockerfiles/run/guice/cassandra/destination/conf/healthcheck.properties @@ -22,9 +22,6 @@ # Read https://james.apache.org/server/config-healthcheck.html for further details -# Optional. Initial delay in seconds before PeriodicalHealthChecks starts. Default value is 60 -# healthcheck.initial.delay=60 - -# Optional. Period in seconds between two PeriodicalHealthChecks. Default value is 60 -# healthcheck.period=60 +# Optional. Period between two PeriodicalHealthChecks. The formats accepted are based on the ISO-8601 duration format. Default duration is 60 seconds. +# healthcheck.period=PT60s diff --git a/dockerfiles/run/guice/jpa-smtp/destination/conf/healthcheck.properties b/dockerfiles/run/guice/jpa-smtp/destination/conf/healthcheck.properties index 23b9879..24873dc 100644 --- a/dockerfiles/run/guice/jpa-smtp/destination/conf/healthcheck.properties +++ b/dockerfiles/run/guice/jpa-smtp/destination/conf/healthcheck.properties @@ -22,9 +22,6 @@ # Read https://james.apache.org/server/config-healthcheck.html for further details -# Optional. Initial delay in seconds before PeriodicalHealthChecks starts. Default value is 60 -# healthcheck.initial.delay=60 - -# Optional. Period in seconds between two PeriodicalHealthChecks. Default value is 60 -# healthcheck.period=60 +# Optional. Period between two PeriodicalHealthChecks. The formats accepted are based on the ISO-8601 duration format. Default duration is 60 seconds. +# healthcheck.period=PT60s diff --git a/dockerfiles/run/guice/jpa/destination/conf/healthcheck.properties b/dockerfiles/run/guice/jpa/destination/conf/healthcheck.properties index 23b9879..24873dc 100644 --- a/dockerfiles/run/guice/jpa/destination/conf/healthcheck.properties +++ b/dockerfiles/run/guice/jpa/destination/conf/healthcheck.properties @@ -22,9 +22,6 @@ # Read https://james.apache.org/server/config-healthcheck.html for further details -# Optional. Initial delay in seconds before PeriodicalHealthChecks starts. Default value is 60 -# healthcheck.initial.delay=60 - -# Optional. Period in seconds between two PeriodicalHealthChecks. Default value is 60 -# healthcheck.period=60 +# Optional. Period between two PeriodicalHealthChecks. The formats accepted are based on the ISO-8601 duration format. Default duration is 60 seconds. +# healthcheck.period=PT60s diff --git a/dockerfiles/run/guice/memory/destination/conf/healthcheck.properties b/dockerfiles/run/guice/memory/destination/conf/healthcheck.properties index 23b9879..24873dc 100644 --- a/dockerfiles/run/guice/memory/destination/conf/healthcheck.properties +++ b/dockerfiles/run/guice/memory/destination/conf/healthcheck.properties @@ -22,9 +22,6 @@ # Read https://james.apache.org/server/config-healthcheck.html for further details -# Optional. Initial delay in seconds before PeriodicalHealthChecks starts. Default value is 60 -# healthcheck.initial.delay=60 - -# Optional. Period in seconds between two PeriodicalHealthChecks. Default value is 60 -# healthcheck.period=60 +# Optional. Period between two PeriodicalHealthChecks. The formats accepted are based on the ISO-8601 duration format. Default duration is 60 seconds. +# healthcheck.period=PT60s diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecksConfiguration.java b/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecksConfiguration.java index e8e052f..aa8bbfb 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecksConfiguration.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecksConfiguration.java @@ -19,6 +19,7 @@ package org.apache.james; +import java.time.Duration; import java.util.Objects; import org.apache.commons.configuration2.Configuration; @@ -28,71 +29,53 @@ import com.google.common.base.Preconditions; public class PeriodicalHealthChecksConfiguration { - static final String HEALTH_CHECK_INITIAL_DELAY = "healthcheck.initial.delay"; - static final String HEALTH_CHECK_PERIOD = "healthcheck.period"; - static final long DEFAULT_HEALTH_CHECK_INITIAL_DELAY = 60; - static final long DEFAULT_HEALTH_CHECK_PERIOD = 60; - static final long ZERO = 0; + private static final String HEALTH_CHECK_PERIOD = "healthcheck.period"; + private static final String DEFAULT_HEALTH_CHECK_PERIOD = "PT60s"; public static final PeriodicalHealthChecksConfiguration DEFAULT_CONFIGURATION = builder() - .initialDelay(DEFAULT_HEALTH_CHECK_INITIAL_DELAY) - .period(DEFAULT_HEALTH_CHECK_PERIOD) + .period(Duration.parse(DEFAULT_HEALTH_CHECK_PERIOD)) .build(); public interface Builder { @FunctionalInterface - interface RequiredInitialDelay { - RequiredPeriod initialDelay(long initialDelay); - } - - @FunctionalInterface interface RequiredPeriod { - ReadyToBuild period(long period); + ReadyToBuild period(Duration period); } class ReadyToBuild { - private final long initialDelay; - private final long period; + private final Duration period; - ReadyToBuild(long initialDelay, long period) { - this.initialDelay = initialDelay; + ReadyToBuild(Duration period) { this.period = period; } PeriodicalHealthChecksConfiguration build() { - Preconditions.checkArgument(initialDelay > ZERO, "'initialDelay' must be positive"); - Preconditions.checkArgument(period > ZERO, "'period' must be positive"); + Preconditions.checkArgument(!period.isNegative(), "'period' must be positive"); + Preconditions.checkArgument(!period.isZero(), "'period' must be greater than zero"); - return new PeriodicalHealthChecksConfiguration(initialDelay, period); + return new PeriodicalHealthChecksConfiguration(period); } } } - public static Builder.RequiredInitialDelay builder() { - return initialDelay -> period -> new Builder.ReadyToBuild(initialDelay, period); + public static Builder.RequiredPeriod builder() { + return period -> new Builder.ReadyToBuild(period); } public static PeriodicalHealthChecksConfiguration from(Configuration configuration) { return builder() - .initialDelay(configuration.getLong(HEALTH_CHECK_INITIAL_DELAY, DEFAULT_HEALTH_CHECK_INITIAL_DELAY)) - .period(configuration.getLong(HEALTH_CHECK_PERIOD, DEFAULT_HEALTH_CHECK_PERIOD)) + .period(Duration.parse(configuration.getString(HEALTH_CHECK_PERIOD, DEFAULT_HEALTH_CHECK_PERIOD))) .build(); } - private final long initialDelay; - private final long period; + private final Duration period; @VisibleForTesting - PeriodicalHealthChecksConfiguration(long initialDelay, long period) { - this.initialDelay = initialDelay; + PeriodicalHealthChecksConfiguration(Duration period) { this.period = period; } - public long getInitialDelay() { - return initialDelay; - } - - public long getPeriod() { + public Duration getPeriod() { return period; } @@ -101,14 +84,13 @@ public class PeriodicalHealthChecksConfiguration { if (o instanceof PeriodicalHealthChecksConfiguration) { PeriodicalHealthChecksConfiguration that = (PeriodicalHealthChecksConfiguration) o; - return Objects.equals(this.initialDelay, that.initialDelay) - && Objects.equals(this.period, that.period); + return Objects.equals(this.period, that.period); } return false; } @Override public final int hashCode() { - return Objects.hash(initialDelay, period); + return Objects.hash(period); } } \ No newline at end of file diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksConfigurationTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksConfigurationTest.java index a51945a..d7830cf 100644 --- a/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksConfigurationTest.java +++ b/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksConfigurationTest.java @@ -19,24 +19,24 @@ package org.apache.james; -import static org.apache.james.PeriodicalHealthChecksConfiguration.DEFAULT_HEALTH_CHECK_INITIAL_DELAY; -import static org.apache.james.PeriodicalHealthChecksConfiguration.DEFAULT_HEALTH_CHECK_PERIOD; +import static org.apache.james.PeriodicalHealthChecksConfiguration.DEFAULT_CONFIGURATION; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.time.Duration; +import java.time.format.DateTimeParseException; + import org.apache.commons.configuration2.PropertiesConfiguration; -import org.apache.commons.configuration2.ex.ConversionException; import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; public class PeriodicalHealthChecksConfigurationTest { + private static final String HEALTH_CHECK_PERIOD = "healthcheck.period"; + private static final String PERIOD = "PT5s"; private static final String EMPTY_STRING = ""; private static final String RANDOM_STRING = "abcdsfsfs"; - private static final long NEGATIVE_NUMBER = -1; - private static final long INITIAL_DELAY = 10; - private static final long PERIOD = 5; @Test void shouldMatchBeanContract() { @@ -45,120 +45,90 @@ public class PeriodicalHealthChecksConfigurationTest { } @Test - void fromShouldThrowWhenInitialDelayIsEmpty() { - PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, EMPTY_STRING); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, DEFAULT_HEALTH_CHECK_PERIOD); - - assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration. from(configuration)) - .isInstanceOf(ConversionException.class); - } - - @Test - void fromShouldThrowWhenPeriodIsEmpty() { - PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, DEFAULT_HEALTH_CHECK_INITIAL_DELAY); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, EMPTY_STRING); - - assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.from(configuration)) - .isInstanceOf(ConversionException.class); + void builderShouldThrowWhenPeriodIsNull() { + assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.builder() + .period(null) + .build()) + .isInstanceOf(NullPointerException.class); } @Test - void fromShouldReturnConfigurationWithDefaultValueWhenInitialDelayIsMissing() { - PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, PERIOD); - - assertThat(PeriodicalHealthChecksConfiguration.from(configuration)).isEqualTo(PeriodicalHealthChecksConfiguration.builder() - .initialDelay(DEFAULT_HEALTH_CHECK_INITIAL_DELAY) - .period(PERIOD) - .build()); + void builderShouldThrowWhenPeriodHasIncorrectFormat() { + assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.builder() + .period(Duration.parse(RANDOM_STRING)) + .build()) + .isInstanceOf(DateTimeParseException.class); } @Test - void fromShouldReturnConfigurationWithDefaultValueWhenPeriodIsMissing() { - PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, INITIAL_DELAY); - - assertThat(PeriodicalHealthChecksConfiguration.from(configuration)).isEqualTo(PeriodicalHealthChecksConfiguration.builder() - .initialDelay(INITIAL_DELAY) - .period(DEFAULT_HEALTH_CHECK_PERIOD) - .build()); + void builderShouldThrowWhenPeriodIsNegative() { + assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.builder() + .period(Duration.parse("-" + PERIOD)) + .build()) + .isInstanceOf(IllegalArgumentException.class); } @Test - void fromShouldReturnConfigurationWithDefaultValueWhenInitialDelayIsNull() { - PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, null); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, PERIOD); - - assertThat(PeriodicalHealthChecksConfiguration.from(configuration)).isEqualTo(PeriodicalHealthChecksConfiguration.builder() - .initialDelay(DEFAULT_HEALTH_CHECK_INITIAL_DELAY) - .period(PERIOD) - .build()); + void builderShouldThrowWhenPeriodIsZero() { + assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.builder() + .period(Duration.ZERO) + .build()) + .isInstanceOf(IllegalArgumentException.class); } @Test - void fromShouldReturnConfigurationWithDefaultValueWhenPeriodIsNull() { - PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, INITIAL_DELAY); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, null); + void builderShouldReturnCorrectConfiguration() { + PeriodicalHealthChecksConfiguration configuration = PeriodicalHealthChecksConfiguration.builder() + .period(Duration.parse(PERIOD)) + .build(); - assertThat(PeriodicalHealthChecksConfiguration.from(configuration)).isEqualTo(PeriodicalHealthChecksConfiguration.builder() - .initialDelay(INITIAL_DELAY) - .period(DEFAULT_HEALTH_CHECK_PERIOD) - .build()); + assertThat(configuration.getPeriod()).isEqualTo(Duration.parse(PERIOD)); } @Test - void fromShouldThrowWhenInitialDelayIsNotANumber() { + void fromShouldThrowWhenPeriodIsEmpty() { PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, RANDOM_STRING); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, PERIOD); + configuration.addProperty(HEALTH_CHECK_PERIOD, EMPTY_STRING); assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.from(configuration)) - .isInstanceOf(ConversionException.class); + .isInstanceOf(DateTimeParseException.class); } @Test - void fromShouldThrowWhenInitialDelayIsNegative() { + void fromShouldReturnConfigurationWithDefaultValueWhenPeriodIsMissing() { PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, NEGATIVE_NUMBER); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, PERIOD); - assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.from(configuration)) - .isInstanceOf(IllegalArgumentException.class); + assertThat(PeriodicalHealthChecksConfiguration.from(configuration)).isEqualTo(PeriodicalHealthChecksConfiguration.builder() + .period(DEFAULT_CONFIGURATION.getPeriod()) + .build()); } @Test - void fromShouldThrowWhenPeriodIsNegative() { + void fromShouldReturnConfigurationWithDefaultValueWhenPeriodIsNull() { PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, INITIAL_DELAY); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, NEGATIVE_NUMBER); + configuration.addProperty(HEALTH_CHECK_PERIOD, null); - assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.from(configuration)) - .isInstanceOf(IllegalArgumentException.class); + assertThat(PeriodicalHealthChecksConfiguration.from(configuration)).isEqualTo(PeriodicalHealthChecksConfiguration.builder() + .period(DEFAULT_CONFIGURATION.getPeriod()) + .build()); } @Test - void fromShouldThrowWhenPeriodIsNotANumber() { + void fromShouldThrowWhenPeriodHasIncorrectFormat() { PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, INITIAL_DELAY); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, RANDOM_STRING); + configuration.addProperty(HEALTH_CHECK_PERIOD, RANDOM_STRING); assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.from(configuration)) - .isInstanceOf(ConversionException.class); + .isInstanceOf(DateTimeParseException.class); } @Test void fromShouldReturnProvidedConfiguration() { PropertiesConfiguration configuration = new PropertiesConfiguration(); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_INITIAL_DELAY, INITIAL_DELAY); - configuration.addProperty(PeriodicalHealthChecksConfiguration.HEALTH_CHECK_PERIOD, PERIOD); + configuration.addProperty(HEALTH_CHECK_PERIOD, PERIOD); assertThat(PeriodicalHealthChecksConfiguration.from(configuration)).isEqualTo(PeriodicalHealthChecksConfiguration.builder() - .initialDelay(INITIAL_DELAY) - .period(PERIOD) + .period(Duration.parse(PERIOD)) .build()); } -} +} \ No newline at end of file diff --git a/src/site/xdoc/server/config-healthcheck.xml b/src/site/xdoc/server/config-healthcheck.xml index e7604bd..c53635a 100644 --- a/src/site/xdoc/server/config-healthcheck.xml +++ b/src/site/xdoc/server/config-healthcheck.xml @@ -24,7 +24,6 @@ </properties> <body> - <section name="PeriodicalHealthChecks Configuration"> <p>Consult <a href="https://github.com/apache/james-project/blob/master/dockerfiles/run/guice/cassandra/destination/conf/healthcheck.properties">healthcheck.properties</a> in GIT to get some examples and hints.</p> @@ -34,8 +33,6 @@ </p> <dl> - <dt><strong>healthcheck.initial.delay</strong></dt> - <dd>Define the delay time before first health check starts (default: 60)</dd> <dt><strong>healthcheck.period</strong></dt> <dd>Define the period between two periodical health checks (default: 60)</dd> </dl> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
