You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/04/17 00:31:57 UTC
[james-project] 05/39: JAMES-3117 Refactor
PeriodicalHealthChecks/Test for using configuration
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 b7fb64afc136471745beec7d814c9ba43f4f4cf4
Author: LanKhuat <kh...@gmail.com>
AuthorDate: Mon Mar 23 10:03:06 2020 +0700
JAMES-3117 Refactor PeriodicalHealthChecks/Test for using configuration
---
.../main/java/org/apache/james/PeriodicalHealthChecks.java | 14 ++++++--------
.../java/org/apache/james/PeriodicalHealthChecksTest.java | 8 +++++---
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecks.java b/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecks.java
index 91d0872..a18998c 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecks.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/PeriodicalHealthChecks.java
@@ -27,8 +27,6 @@ import javax.inject.Inject;
import org.apache.james.core.healthcheck.HealthCheck;
import org.apache.james.lifecycle.api.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
@@ -37,20 +35,20 @@ import reactor.core.scheduler.Schedulers;
public class PeriodicalHealthChecks implements Startable {
- private static final Logger LOGGER = LoggerFactory.getLogger(PeriodicalHealthChecks.class);
- private static final long INITIAL_DELAY = 1;
- private static final long PERIOD = 1;
-
private final Flux<HealthCheck> healthChecks;
+ private final long initialDelay;
+ private final long period;
private Disposable disposable;
@Inject
- PeriodicalHealthChecks(Set<HealthCheck> healthChecks) {
+ PeriodicalHealthChecks(Set<HealthCheck> healthChecks, PeriodicalHealthChecksConfiguration config) {
this.healthChecks = Flux.fromIterable(healthChecks);
+ this.initialDelay = config.getInitialDelay();
+ this.period = config.getPeriod();
}
public void start() {
- disposable = Flux.interval(Duration.ofSeconds(INITIAL_DELAY), Duration.ofSeconds(PERIOD))
+ disposable = Flux.interval(Duration.ofSeconds(initialDelay), Duration.ofSeconds(period))
.flatMap(any ->
healthChecks.flatMap(healthCheck -> Mono.just(healthCheck.check())))
.subscribeOn(Schedulers.elastic())
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksTest.java
index f029333..8253899 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksTest.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/PeriodicalHealthChecksTest.java
@@ -42,6 +42,8 @@ import org.mockito.Mockito;
public class PeriodicalHealthChecksTest {
+ private static final long INITIAL_DELAY = 1;
+ private static final long PERIOD = 1;
private static final ConditionFactory AWAIT = Awaitility.await()
.atMost(Duration.TEN_SECONDS)
.with()
@@ -55,14 +57,14 @@ public class PeriodicalHealthChecksTest {
void setUp() {
mockHealthCheck1 = Mockito.mock(EventDeadLettersHealthCheck.class);
mockHealthCheck2 = Mockito.mock(GuiceLifecycleHealthCheck.class);
- when(mockHealthCheck1.check()).thenReturn(Result.healthy(new ComponentName("mock1")));
- when(mockHealthCheck2.check()).thenReturn(Result.healthy(new ComponentName("mock2")));
+ when(mockHealthCheck1.check()).thenReturn(Result.healthy(new ComponentName("mockHealthCheck1")));
+ when(mockHealthCheck2.check()).thenReturn(Result.healthy(new ComponentName("mockHealthCheck2")));
Set<HealthCheck> healthCheckSet = new HashSet<>();
healthCheckSet.add(mockHealthCheck1);
healthCheckSet.add(mockHealthCheck2);
- testee = new PeriodicalHealthChecks(healthCheckSet);
+ testee = new PeriodicalHealthChecks(healthCheckSet, new PeriodicalHealthChecksConfiguration(INITIAL_DELAY, PERIOD));
testee.start();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org