diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-04-18 12:45:52 +0200 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.Com> | 2017-04-27 09:23:18 +0200 |
commit | e4d3426880a5c50d6e9cf9736c786a564e5ca777 (patch) | |
tree | db624546b7db1c1729de2eb81af0b14977e21f80 /server/sonar-process-monitor/src/test | |
parent | 36becb8f4ca1a931fe350dc34a5a4fefd0dfd81b (diff) | |
download | sonarqube-e4d3426880a5c50d6e9cf9736c786a564e5ca777.tar.gz sonarqube-e4d3426880a5c50d6e9cf9736c786a564e5ca777.zip |
SONAR-8986 add CeDistributedInformation
Diffstat (limited to 'server/sonar-process-monitor/src/test')
3 files changed, 84 insertions, 9 deletions
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java index fe2bc98336e..8c89e6593e1 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java @@ -39,9 +39,9 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import static org.sonar.application.cluster.HazelcastCluster.SONARQUBE_VERSION; import static org.sonar.application.cluster.HazelcastTestHelper.createHazelcastClient; import static org.sonar.application.cluster.HazelcastTestHelper.newClusterSettings; +import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; public class AppStateClusterImplTest { diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java index c418c07bac8..d8b8295127d 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java @@ -19,34 +19,45 @@ */ package org.sonar.application.cluster; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.ItemEvent; +import com.hazelcast.core.ItemListener; import com.hazelcast.core.ReplicatedMap; import java.net.InetAddress; import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.junit.Rule; import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.ExpectedException; import org.junit.rules.TestRule; import org.junit.rules.Timeout; +import org.slf4j.LoggerFactory; import org.sonar.application.AppStateListener; import org.sonar.application.config.TestAppSettings; import org.sonar.process.NetworkUtils; import org.sonar.process.ProcessId; import org.sonar.process.ProcessProperties; +import org.sonar.process.cluster.ClusterObjectKeys; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.sonar.application.cluster.HazelcastCluster.LEADER; -import static org.sonar.application.cluster.HazelcastCluster.OPERATIONAL_PROCESSES; -import static org.sonar.application.cluster.HazelcastCluster.SONARQUBE_VERSION; import static org.sonar.application.cluster.HazelcastTestHelper.createHazelcastClient; import static org.sonar.application.cluster.HazelcastTestHelper.newClusterSettings; import static org.sonar.process.ProcessProperties.CLUSTER_NAME; +import static org.sonar.process.cluster.ClusterObjectKeys.LEADER; +import static org.sonar.process.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; +import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; public class HazelcastClusterTest { @Rule @@ -114,7 +125,7 @@ public class HazelcastClusterTest { HazelcastInstance hzInstance = createHazelcastClient(hzCluster); ReplicatedMap<ClusterProcess, Boolean> operationalProcesses = hzInstance.getReplicatedMap(OPERATIONAL_PROCESSES); assertThat(operationalProcesses) - .containsExactly(new AbstractMap.SimpleEntry<>(new ClusterProcess(hzCluster.getLocalUuid(), ProcessId.ELASTICSEARCH), Boolean.TRUE)); + .containsExactly(new AbstractMap.SimpleEntry<>(new ClusterProcess(hzCluster.getLocalUUID(), ProcessId.ELASTICSEARCH), Boolean.TRUE)); } } @@ -129,10 +140,39 @@ public class HazelcastClusterTest { } @Test + public void cluster_must_keep_a_list_of_clients() throws InterruptedException { + TestAppSettings testAppSettings = newClusterSettings(); + testAppSettings.set(CLUSTER_NAME, "a_cluster_"); + ClusterProperties clusterProperties = new ClusterProperties(testAppSettings); + try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { + assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS)).isEmpty(); + HazelcastInstance hzClient = HazelcastTestHelper.createHazelcastClient(hzCluster); + assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS)).containsExactly(hzClient.getLocalEndpoint().getUuid()); + + CountDownLatch latch = new CountDownLatch(1); + hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS).addItemListener(new ItemListener<Object>() { + @Override + public void itemAdded(ItemEvent<Object> item) { + } + + @Override + public void itemRemoved(ItemEvent<Object> item) { + latch.countDown(); + } + }, false); + + hzClient.shutdown(); + latch.await(1, TimeUnit.SECONDS); + + assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS)).isEmpty(); + } + } + + @Test public void localUUID_must_not_be_empty() { ClusterProperties clusterProperties = new ClusterProperties(newClusterSettings()); try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { - assertThat(hzCluster.getLocalUuid()).isNotEmpty(); + assertThat(hzCluster.getLocalUUID()).isNotEmpty(); } } @@ -170,7 +210,6 @@ public class HazelcastClusterTest { } } - @Test public void registerSonarQubeVersion_throws_ISE_if_initial_version_is_different() throws Exception { ClusterProperties clusterProperties = new ClusterProperties(newClusterSettings()); @@ -215,4 +254,42 @@ public class HazelcastClusterTest { hzInstance.shutdown(); } } + + @Test + public void hazelcast_must_log_through_sl4fj() { + MemoryAppender<ILoggingEvent> memoryAppender = new MemoryAppender<>(); + LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + lc.reset(); + memoryAppender.setContext(lc); + memoryAppender.start(); + lc.getLogger("com.hazelcast").addAppender(memoryAppender); + + try (AppStateClusterImpl appStateCluster = new AppStateClusterImpl(newClusterSettings())) { + } + + assertThat(memoryAppender.events).isNotEmpty(); + memoryAppender.events.stream().forEach( + e -> assertThat(e.getLoggerName()).startsWith("com.hazelcast") + ); + } + + private class MemoryAppender<E> extends AppenderBase<E> { + private final List<E> events = new ArrayList(); + + @Override + protected void append(E eventObject) { + events.add(eventObject); + } + } + + + @Test + public void configuration_tweaks_of_hazelcast_must_be_present() { + try (HazelcastCluster hzCluster = HazelcastCluster.create(new ClusterProperties(newClusterSettings()))) { + assertThat(hzCluster.hzInstance.getConfig().getProperty("hazelcast.tcp.join.port.try.count")).isEqualTo("10"); + assertThat(hzCluster.hzInstance.getConfig().getProperty("hazelcast.phone.home.enabled")).isEqualTo("false"); + assertThat(hzCluster.hzInstance.getConfig().getProperty("hazelcast.logging.type")).isEqualTo("slf4j"); + assertThat(hzCluster.hzInstance.getConfig().getProperty("hazelcast.socket.bind.any")).isEqualTo("false"); + } + } } diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java index 81033eb34f5..c284cc869ff 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java @@ -46,12 +46,10 @@ public class HazelcastTestHelper { return createHazelcastClient(appStateCluster.getHazelcastCluster()); } - static TestAppSettings newClusterSettings() { TestAppSettings settings = new TestAppSettings(); settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); settings.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); return settings; } - } |