]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10850 Log HazelcastInstanceNotActiveException exception as DEBUG during shutdown
authorEric Hartmann <hartmann.eric@gmail.com>
Wed, 13 Jun 2018 08:38:49 +0000 (10:38 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 14 Jun 2018 09:50:35 +0000 (11:50 +0200)
server/sonar-process/src/main/java/org/sonar/process/cluster/health/HealthStateRefresher.java
server/sonar-process/src/test/java/org/sonar/process/cluster/health/HealthStateRefresherTest.java

index c275784c4e59d0610e75356b372afeeeae91a5a0..0204237d0725c3c575ece2a22dd1ed118b24cfa3 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.process.cluster.health;
 
+import com.hazelcast.core.HazelcastInstanceNotActiveException;
 import java.util.concurrent.TimeUnit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,6 +48,8 @@ public class HealthStateRefresher {
     try {
       NodeHealth nodeHealth = nodeHealthProvider.get();
       sharedHealthState.writeMine(nodeHealth);
+    } catch (HazelcastInstanceNotActiveException e) {
+      LOG.debug("Hazelcast is no more active", e);
     } catch (Throwable t) {
       LOG.error("An error occurred while attempting to refresh HealthState of the current node in the shared state:", t);
     }
index 0d4428265f172c5f3f4948939aaacc61b05a379e..b5bd4b90ad5b80eb6beb95f4e7705adb4a41a42e 100644 (file)
  */
 package org.sonar.process.cluster.health;
 
+import com.hazelcast.core.HazelcastInstanceNotActiveException;
 import java.util.Random;
 import java.util.concurrent.TimeUnit;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
+import org.sonar.process.LoggingRule;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
+import static org.slf4j.event.Level.DEBUG;
+import static org.slf4j.event.Level.ERROR;
 
 public class HealthStateRefresherTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
+  @Rule
+  public LoggingRule logging = new LoggingRule(HealthStateRefresher.class);
 
   private Random random = new Random();
   private NodeDetailsTestSupport testSupport = new NodeDetailsTestSupport(random);
@@ -87,4 +96,20 @@ public class HealthStateRefresherTest {
     verify(sharedHealthState).clearMine();
     verifyZeroInteractions(executorService, nodeHealthProvider);
   }
+
+  @Test
+  public void do_not_log_errors_when_hazelcast_is_not_active() {
+    logging.setLevel(DEBUG);
+    doThrow(new HazelcastInstanceNotActiveException()).when(sharedHealthState).writeMine(any());
+
+    ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
+    underTest.start();
+
+    verify(executorService).scheduleWithFixedDelay(runnableCaptor.capture(), eq(1L), eq(10L), eq(TimeUnit.SECONDS));
+    Runnable runnable = runnableCaptor.getValue();
+    runnable.run();
+
+    assertThat(logging.getLogs(ERROR)).isEmpty();
+    assertThat(logging.hasLog(DEBUG, "Hazelcast is no more active")).isTrue();
+  }
 }