aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-07-23 15:29:17 -0500
committersonartech <sonartech@sonarsource.com>2021-07-29 20:04:50 +0000
commitf827bdec3dd63f407ccba44fc5a8462528e0717f (patch)
tree53fd1ed5b53fd3e2c2d7a1c3c4cbe1e26893b160 /server/sonar-main/src/test
parent5dd693fb86fb9a0e6335de1c9dbabab7dbd89ce6 (diff)
downloadsonarqube-f827bdec3dd63f407ccba44fc5a8462528e0717f.tar.gz
sonarqube-f827bdec3dd63f407ccba44fc5a8462528e0717f.zip
SONAR-15230 Hazelcast clean up
Diffstat (limited to 'server/sonar-main/src/test')
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java39
1 files changed, 17 insertions, 22 deletions
diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java
index 16dce4d4bc7..8a0deba5315 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java
@@ -25,7 +25,6 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus;
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.sonar.application.AppStateListener;
@@ -39,6 +38,7 @@ import org.sonar.process.cluster.hz.HazelcastMemberBuilder;
import org.sonar.process.cluster.hz.JoinConfigurationType;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
@@ -49,17 +49,14 @@ import static org.sonar.process.cluster.hz.HazelcastObjects.SONARQUBE_VERSION;
public class ClusterAppStateImplTest {
@Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Rule
public TestRule safeguardTimeout = new DisableOnDebug(Timeout.seconds(60));
@Test
public void tryToLockWebLeader_returns_true_only_for_the_first_call() {
try (ClusterAppStateImpl underTest = new ClusterAppStateImpl(new TestAppSettings(), newHzMember(),
mock(EsConnector.class), mock(AppNodesClusterHostsConsistency.class))) {
- assertThat(underTest.tryToLockWebLeader()).isEqualTo(true);
- assertThat(underTest.tryToLockWebLeader()).isEqualTo(false);
+ assertThat(underTest.tryToLockWebLeader()).isTrue();
+ assertThat(underTest.tryToLockWebLeader()).isFalse();
}
}
@@ -72,10 +69,10 @@ public class ClusterAppStateImplTest {
underTest.setOperational(ProcessId.ELASTICSEARCH);
verify(listener, timeout(20_000)).onAppStateOperational(ProcessId.ELASTICSEARCH);
- assertThat(underTest.isOperational(ProcessId.ELASTICSEARCH, true)).isEqualTo(true);
- assertThat(underTest.isOperational(ProcessId.APP, true)).isEqualTo(false);
- assertThat(underTest.isOperational(ProcessId.WEB_SERVER, true)).isEqualTo(false);
- assertThat(underTest.isOperational(ProcessId.COMPUTE_ENGINE, true)).isEqualTo(false);
+ assertThat(underTest.isOperational(ProcessId.ELASTICSEARCH, true)).isTrue();
+ assertThat(underTest.isOperational(ProcessId.APP, true)).isFalse();
+ assertThat(underTest.isOperational(ProcessId.WEB_SERVER, true)).isFalse();
+ assertThat(underTest.isOperational(ProcessId.COMPUTE_ENGINE, true)).isFalse();
}
}
@@ -130,10 +127,9 @@ public class ClusterAppStateImplTest {
@Test
public void reset_always_throws_ISE() {
try (ClusterAppStateImpl underTest = createClusterAppState()) {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("state reset is not supported in cluster mode");
-
- underTest.reset();
+ assertThatThrownBy(underTest::reset)
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessageContaining("state reset is not supported in cluster mode");
}
}
@@ -144,11 +140,10 @@ public class ClusterAppStateImplTest {
// Register first version
underTest.getHazelcastMember().getAtomicReference(SONARQUBE_VERSION).set("6.6.0.1111");
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("The local version 6.7.0.9999 is not the same as the cluster 6.6.0.1111");
-
// Registering a second different version must trigger an exception
- underTest.registerSonarQubeVersion("6.7.0.9999");
+ assertThatThrownBy(() -> underTest.registerSonarQubeVersion("6.7.0.9999"))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessageContaining("The local version 6.7.0.9999 is not the same as the cluster 6.6.0.1111");
}
}
@@ -158,11 +153,10 @@ public class ClusterAppStateImplTest {
// Register first version
underTest.getHazelcastMember().getAtomicReference(CLUSTER_NAME).set("goodClusterName");
- expectedException.expect(MessageException.class);
- expectedException.expectMessage("This node has a cluster name [badClusterName], which does not match [goodClusterName] from the cluster");
-
// Registering a second different cluster name must trigger an exception
- underTest.registerClusterName("badClusterName");
+ assertThatThrownBy(() -> underTest.registerClusterName("badClusterName"))
+ .isInstanceOf(MessageException.class)
+ .hasMessage("This node has a cluster name [badClusterName], which does not match [goodClusterName] from the cluster");
}
}
@@ -199,6 +193,7 @@ public class ClusterAppStateImplTest {
.setProcessId(ProcessId.COMPUTE_ENGINE)
.setNodeName("bar")
.setPort(NetworkUtilsImpl.INSTANCE.getNextLoopbackAvailablePort())
+ .setMembers(loopback.getHostAddress())
.setNetworkInterface(loopback.getHostAddress())
.build();
}