aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process/src
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2018-06-13 10:38:49 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-14 11:50:35 +0200
commit964114c0da7b0f0ad0024072d14a74d7b7b98001 (patch)
tree355f84ac2746e61aba881c649503d2ed80eb48ba /server/sonar-process/src
parent10103e78bcbd9ae940e543633136dc777201e4ac (diff)
downloadsonarqube-964114c0da7b0f0ad0024072d14a74d7b7b98001.tar.gz
sonarqube-964114c0da7b0f0ad0024072d14a74d7b7b98001.zip
SONAR-10850 Log HazelcastInstanceNotActiveException exception as DEBUG during shutdown
Diffstat (limited to 'server/sonar-process/src')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/cluster/health/HealthStateRefresher.java3
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/cluster/health/HealthStateRefresherTest.java25
2 files changed, 28 insertions, 0 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/health/HealthStateRefresher.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/health/HealthStateRefresher.java
index c275784c4e5..0204237d072 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/health/HealthStateRefresher.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/health/HealthStateRefresher.java
@@ -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);
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/HealthStateRefresherTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/HealthStateRefresherTest.java
index 0d4428265f1..b5bd4b90ad5 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/HealthStateRefresherTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/HealthStateRefresherTest.java
@@ -19,23 +19,32 @@
*/
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();
+ }
}