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()));
}
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());
}
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());
}
}
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();
}
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);
}
Aggregations