You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/02/17 01:46:47 UTC

[james-project] 09/13: JAMES-3500 Fasten PeriodicalHealthChecksTest

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 40c019a96c1a2b50154acc2b7a2e5eb622c9137e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sun Feb 14 18:47:09 2021 +0700

    JAMES-3500 Fasten PeriodicalHealthChecksTest
    
     - Takes 5 minutes on the CI
     - Takes 7 minutes on my laptop
    
    A quick investigation led to:
    
     - Static import refactoring
     - Remove noise NPE errors flooding logs
     - Avoid performing 10.000 checks due to 1ms period and 10
       seconds advance.
    
    Now `mvn clean install` takes 23 seconds which sounds more
    reasonable.
---
 .../org/apache/james/PeriodicalHealthChecksTest.java    | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

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 500be7a..8a18d43 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
@@ -20,6 +20,7 @@
 package org.apache.james;
 
 
+import static org.apache.james.PeriodicalHealthChecksTest.TestingHealthCheck.COMPONENT_NAME;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.mockito.Mockito.atLeast;
@@ -86,6 +87,8 @@ public class PeriodicalHealthChecksTest {
     void setUp() {
         mockHealthCheck1 = Mockito.mock(EventDeadLettersHealthCheck.class);
         mockHealthCheck2 = Mockito.mock(GuiceLifecycleHealthCheck.class);
+        when(mockHealthCheck1.componentName()).thenReturn(new ComponentName("mockHealthCheck1"));
+        when(mockHealthCheck2.componentName()).thenReturn(new ComponentName("mockHealthCheck2"));
         when(mockHealthCheck1.check()).thenReturn(Mono.just(Result.healthy(new ComponentName("mockHealthCheck1"))));
         when(mockHealthCheck2.check()).thenReturn(Mono.just(Result.healthy(new ComponentName("mockHealthCheck2"))));
 
@@ -111,7 +114,7 @@ public class PeriodicalHealthChecksTest {
 
         testee.start();
 
-        assertThatCode(() -> scheduler.advanceTimeBy(PERIOD))
+        assertThatCode(() -> scheduler.advanceTimeBy(Duration.ofMillis(5)))
             .doesNotThrowAnyException();
     }
 
@@ -127,7 +130,7 @@ public class PeriodicalHealthChecksTest {
     void startShouldLogPeriodicallyWhenUnhealthy() {
         ListAppender<ILoggingEvent> loggingEvents = getListAppenderForClass(PeriodicalHealthChecks.class);
 
-        TestingHealthCheck unhealthy = () -> Mono.just(Result.unhealthy(TestingHealthCheck.COMPONENT_NAME, "cause"));
+        TestingHealthCheck unhealthy = () -> Mono.just(Result.unhealthy(COMPONENT_NAME, "cause"));
         testee = new PeriodicalHealthChecks(ImmutableSet.of(unhealthy),
             scheduler,
             new PeriodicalHealthChecksConfiguration(PERIOD));
@@ -145,7 +148,7 @@ public class PeriodicalHealthChecksTest {
     void startShouldLogPeriodicallyWhenDegraded() {
         ListAppender<ILoggingEvent> loggingEvents = getListAppenderForClass(PeriodicalHealthChecks.class);
 
-        TestingHealthCheck degraded = () -> Mono.just(Result.degraded(TestingHealthCheck.COMPONENT_NAME, "cause"));
+        TestingHealthCheck degraded = () -> Mono.just(Result.degraded(COMPONENT_NAME, "cause"));
         testee = new PeriodicalHealthChecks(ImmutableSet.of(degraded),
             scheduler,
             new PeriodicalHealthChecksConfiguration(PERIOD));
@@ -163,7 +166,7 @@ public class PeriodicalHealthChecksTest {
     void startShouldNotLogWhenHealthy() {
         ListAppender<ILoggingEvent> loggingEvents = getListAppenderForClass(PeriodicalHealthChecks.class);
 
-        TestingHealthCheck healthy = () -> Mono.just(Result.healthy(TestingHealthCheck.COMPONENT_NAME));
+        TestingHealthCheck healthy = () -> Mono.just(Result.healthy(COMPONENT_NAME));
         testee = new PeriodicalHealthChecks(ImmutableSet.of(healthy),
             scheduler,
             new PeriodicalHealthChecksConfiguration(PERIOD));
@@ -177,9 +180,9 @@ public class PeriodicalHealthChecksTest {
     void startShouldLogWhenMultipleHealthChecks() {
         ListAppender<ILoggingEvent> loggingEvents = getListAppenderForClass(PeriodicalHealthChecks.class);
 
-        TestingHealthCheck unhealthy = () -> Mono.just(Result.unhealthy(TestingHealthCheck.COMPONENT_NAME, "cause"));
-        TestingHealthCheck degraded = () -> Mono.just(Result.degraded(TestingHealthCheck.COMPONENT_NAME, "cause"));
-        TestingHealthCheck healthy = () -> Mono.just(Result.healthy(TestingHealthCheck.COMPONENT_NAME));
+        TestingHealthCheck unhealthy = () -> Mono.just(Result.unhealthy(COMPONENT_NAME, "cause"));
+        TestingHealthCheck degraded = () -> Mono.just(Result.degraded(COMPONENT_NAME, "cause"));
+        TestingHealthCheck healthy = () -> Mono.just(Result.healthy(COMPONENT_NAME));
 
         testee = new PeriodicalHealthChecks(ImmutableSet.of(unhealthy, degraded, healthy),
             scheduler,


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org