public ExpectedException expectedException = ExpectedException.none();
@Rule
- public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(10));
+ public TestRule safeGuard = new DisableOnDebug(Timeout.seconds(20));
private static HazelcastInstance hzCluster;
private static HazelcastClientWrapperImpl hzClient;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.DisableOnDebug;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.sonar.application.cluster.HazelcastTestHelper.closeAllHazelcastClients;
import static org.sonar.application.cluster.HazelcastTestHelper.createHazelcastClient;
import static org.sonar.application.cluster.HazelcastTestHelper.newClusterSettings;
import static org.sonar.process.ProcessProperties.CLUSTER_NAME;
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ @AfterClass
+ public static void closeHazelcastClients() {
+ closeAllHazelcastClients();
+ }
+
@Test
public void test_two_tryToLockWebLeader_must_return_true() {
ClusterProperties clusterProperties = new ClusterProperties(newClusterSettings());
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
import org.sonar.application.config.TestAppSettings;
import org.sonar.process.ProcessProperties;
public class HazelcastTestHelper {
+ // Be careful this test won't work if parallel tests is used
+ private static final List<HazelcastInstance> HAZELCAST_INSTANCES = new ArrayList<>();
+
static HazelcastInstance createHazelcastClient(HazelcastCluster hzCluster) {
ClientConfig clientConfig = new ClientConfig();
InetSocketAddress socketAddress = (InetSocketAddress) hzCluster.hzInstance.getLocalEndpoint().getSocketAddress();
socketAddress.getPort()
));
clientConfig.getGroupConfig().setName(hzCluster.getName());
- return HazelcastClient.newHazelcastClient(clientConfig);
+ HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
+ HAZELCAST_INSTANCES.add(hazelcastInstance);
+ return hazelcastInstance;
+ }
+
+ static void closeAllHazelcastClients() {
+ HAZELCAST_INSTANCES.stream().forEach(
+ hz -> {
+ try {
+ hz.shutdown();
+ } catch (Exception ex) {
+ // Ignore it
+ }
+ }
+ );
}
static HazelcastInstance createHazelcastClient(AppStateClusterImpl appStateCluster) {