aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2017-06-22 13:43:34 +0200
committerEric Hartmann <hartmann.eric@gmail.com>2017-06-22 13:43:34 +0200
commit8af2f37ed8c0594926adb33f6db91856625157b3 (patch)
tree54cdc8e03a5ecf6aff2c2c181094ba7fa69dc77f /server/sonar-ce
parent68fb6f3f3bcadb460492b6a6ec76dada511eb4ad (diff)
downloadsonarqube-8af2f37ed8c0594926adb33f6db91856625157b3.tar.gz
sonarqube-8af2f37ed8c0594926adb33f6db91856625157b3.zip
Make HazelcastClientWrapperImplTest more robust
Diffstat (limited to 'server/sonar-ce')
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
index 746b31960f6..b86fe768c94 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
@@ -26,6 +26,8 @@ import ch.qos.logback.core.AppenderBase;
import com.google.common.collect.ImmutableSet;
import com.hazelcast.client.impl.HazelcastClientInstanceImpl;
import com.hazelcast.client.impl.HazelcastClientProxy;
+import com.hazelcast.core.Client;
+import com.hazelcast.core.ClientListener;
import com.hazelcast.core.HazelcastInstance;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -36,6 +38,8 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -154,15 +158,18 @@ public class HazelcastClientWrapperImplTest {
}
@Test
- public void client_must_connect_to_hazelcast() {
+ public void client_must_connect_to_hazelcast() throws InterruptedException {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
// Launch a fake Hazelcast instance
HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster("client_must_connect_to_hazelcast", port);
Settings settings = createClusterSettings("client_must_connect_to_hazelcast", "localhost:" + port);
HazelcastClientWrapperImpl hazelcastClientWrapperImpl = new HazelcastClientWrapperImpl(settings);
+ ClientListenerImpl clientListener = new ClientListenerImpl();
+ hzInstance.getClientService().addClientListener(clientListener);
try {
hazelcastClientWrapperImpl.start();
+ clientListener.counter.await(5, TimeUnit.SECONDS);
assertThat(hazelcastClientWrapperImpl.getConnectedClients()).hasSize(1);
assertThat(hazelcastClientWrapperImpl.getClientUUID()).isNotEmpty();
} finally {
@@ -269,6 +276,20 @@ public class HazelcastClientWrapperImplTest {
);
}
+ private class ClientListenerImpl implements ClientListener {
+ CountDownLatch counter = new CountDownLatch(1);
+
+ @Override
+ public void clientConnected(Client client) {
+ counter.countDown();
+ }
+
+ @Override
+ public void clientDisconnected(Client client) {
+
+ }
+ }
+
private static Settings createClusterSettings(String name, String localEndPoint) {
Properties properties = new Properties();
properties.setProperty(ProcessProperties.CLUSTER_NAME, name);