Search in sources :

Example 16 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class MulticastLoopbackModeTest method testEnabledMode.

@Test
public void testEnabledMode() throws Exception {
    createTestEnvironment(true);
    assertClusterSize(2, hz1, hz2);
    Cluster cluster1 = hz1.getCluster();
    Cluster cluster2 = hz2.getCluster();
    assertTrue("Members list " + cluster1.getMembers() + " should contain " + cluster2.getLocalMember(), cluster1.getMembers().contains(cluster2.getLocalMember()));
    assertTrue("Members list " + cluster2.getMembers() + " should contain " + cluster1.getLocalMember(), cluster2.getMembers().contains(cluster1.getLocalMember()));
}
Also used : Cluster(com.hazelcast.cluster.Cluster) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class PromoteLiteMemberTest method promotion_shouldFail_whenMasterLeaves_duringPromotion.

@Test
public void promotion_shouldFail_whenMasterLeaves_duringPromotion() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz1 = factory.newHazelcastInstance(new Config());
    HazelcastInstance hz2 = factory.newHazelcastInstance(new Config());
    HazelcastInstance hz3 = factory.newHazelcastInstance(new Config().setLiteMember(true));
    assertClusterSizeEventually(3, hz2);
    dropOperationsBetween(hz3, hz1, F_ID, singletonList(PROMOTE_LITE_MEMBER));
    Cluster cluster = hz3.getCluster();
    Future<Exception> future = spawn(() -> {
        try {
            cluster.promoteLocalLiteMember();
        } catch (Exception e) {
            return e;
        }
        return null;
    });
    assertPromotionInvocationStarted(hz3);
    hz1.getLifecycleService().terminate();
    assertClusterSizeEventually(2, hz2, hz3);
    Exception exception = future.get();
    // MemberLeftException is wrapped by HazelcastException
    assertInstanceOf(MemberLeftException.class, exception.getCause());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) Cluster(com.hazelcast.cluster.Cluster) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) CompletionException(java.util.concurrent.CompletionException) ExpectedException(org.junit.rules.ExpectedException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class PromoteLiteMemberTest method promotion_shouldFail_whenMasterIsSuspected_duringPromotion.

@Test
public void promotion_shouldFail_whenMasterIsSuspected_duringPromotion() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz1 = factory.newHazelcastInstance(new Config());
    HazelcastInstance hz2 = factory.newHazelcastInstance(new Config());
    HazelcastInstance hz3 = factory.newHazelcastInstance(new Config().setLiteMember(true));
    assertClusterSizeEventually(3, hz2);
    rejectOperationsBetween(hz3, hz1, F_ID, asList(PROMOTE_LITE_MEMBER, EXPLICIT_SUSPICION));
    dropOperationsFrom(hz2, F_ID, asList(MEMBER_INFO_UPDATE, EXPLICIT_SUSPICION));
    dropOperationsFrom(hz1, F_ID, singletonList(HEARTBEAT));
    Cluster cluster = hz3.getCluster();
    Future future = spawn(cluster::promoteLocalLiteMember);
    assertPromotionInvocationStarted(hz3);
    suspectMember(getNode(hz3), getNode(hz1));
    suspectMember(getNode(hz2), getNode(hz1));
    assertMasterAddressEventually(getAddress(hz2), hz3);
    dropOperationsBetween(hz3, hz1, F_ID, singletonList(EXPLICIT_SUSPICION));
    try {
        future.get();
        fail("Promotion should fail!");
    } catch (ExecutionException e) {
        assertInstanceOf(IllegalStateException.class, e.getCause());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) Cluster(com.hazelcast.cluster.Cluster) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class HazelcastOSGiInstanceTest method getClusterCalledSuccessfullyOverOSGiInstance.

@Test
public void getClusterCalledSuccessfullyOverOSGiInstance() {
    Cluster mockCluster = mock(Cluster.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getCluster()).thenReturn(mockCluster);
    assertEquals(mockCluster, hazelcastOSGiInstance.getCluster());
    verify(mockHazelcastInstance).getCluster();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastOSGiTestUtil.createHazelcastOSGiInstance(com.hazelcast.osgi.impl.HazelcastOSGiTestUtil.createHazelcastOSGiInstance) Cluster(com.hazelcast.cluster.Cluster) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class AbstractSplitBrainProtectionFunctionTest method prepareSplitBrainProtectionFunctionForIcmpFDTest.

protected void prepareSplitBrainProtectionFunctionForIcmpFDTest(SplitBrainProtectionFunction splitBrainProtectionFunction) {
    Cluster mockCluster = mock(Cluster.class);
    when(mockCluster.getLocalMember()).thenReturn(members[0]);
    HazelcastInstance mockInstance = mock(HazelcastInstance.class);
    when(mockInstance.getConfig()).thenReturn(getIcmpFDEnabledConfig());
    when(mockInstance.getCluster()).thenReturn(mockCluster);
    assert splitBrainProtectionFunction instanceof HazelcastInstanceAware;
    ((HazelcastInstanceAware) splitBrainProtectionFunction).setHazelcastInstance(mockInstance);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.cluster.Cluster) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Aggregations

Cluster (com.hazelcast.cluster.Cluster)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Member (com.hazelcast.cluster.Member)12 Test (org.junit.Test)12 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 ClientConfig (com.hazelcast.client.config.ClientConfig)5 Config (com.hazelcast.config.Config)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 MCClusterMetadata (com.hazelcast.client.impl.management.MCClusterMetadata)4 ClientClusterService (com.hazelcast.client.impl.spi.ClientClusterService)4 IPartition (com.hazelcast.internal.partition.IPartition)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3 Partition (com.hazelcast.partition.Partition)3 PartitionService (com.hazelcast.partition.PartitionService)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 ExecutionException (java.util.concurrent.ExecutionException)3 HazelcastCommandLine.getHazelcastClientInstanceImpl (com.hazelcast.client.console.HazelcastCommandLine.getHazelcastClientInstanceImpl)2 RandomLB (com.hazelcast.client.util.RandomLB)2 RoundRobinLB (com.hazelcast.client.util.RoundRobinLB)2