use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class SplitBrainHandlerTest method testClusterMerge_when_split_not_detected_by_slave_and_restart_during_merge.
@Test
public // https://github.com/hazelcast/hazelcast/issues/8137
void testClusterMerge_when_split_not_detected_by_slave_and_restart_during_merge() throws InterruptedException {
Config config = new Config();
String groupName = generateRandomString(10);
config.getGroupConfig().setName(groupName);
config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "15");
config.setProperty(GroupProperty.MAX_JOIN_SECONDS.getName(), "40");
config.setProperty(GroupProperty.MAX_JOIN_MERGE_TARGET_SECONDS.getName(), "10");
NetworkConfig networkConfig = config.getNetworkConfig();
networkConfig.getJoin().getMulticastConfig().setEnabled(false);
networkConfig.getJoin().getTcpIpConfig().setEnabled(true).addMember("127.0.0.1:5701").addMember("127.0.0.1:5702").addMember("127.0.0.1:5703");
networkConfig.setPort(5702);
HazelcastInstance hz2 = newHazelcastInstance(config, "test-node2", new FirewallingNodeContext());
networkConfig.setPort(5703);
HazelcastInstance hz3 = newHazelcastInstance(config, "test-node3", new FirewallingNodeContext());
networkConfig.setPort(5701);
HazelcastInstance hz1 = newHazelcastInstance(config, "test-node1", new FirewallingNodeContext());
final Node n1 = TestUtil.getNode(hz1);
Node n2 = TestUtil.getNode(hz2);
Node n3 = TestUtil.getNode(hz3);
final CountDownLatch splitLatch = new CountDownLatch(2);
MembershipAdapter membershipAdapter = new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent event) {
if (n1.getLocalMember().equals(event.getMember())) {
splitLatch.countDown();
}
}
};
hz2.getCluster().addMembershipListener(membershipAdapter);
hz3.getCluster().addMembershipListener(membershipAdapter);
final CountDownLatch mergingLatch = new CountDownLatch(1);
final CountDownLatch mergeLatch = new CountDownLatch(1);
LifecycleListener lifecycleListener = new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleState.MERGING) {
mergingLatch.countDown();
}
if (event.getState() == LifecycleState.MERGED) {
mergeLatch.countDown();
}
}
};
hz1.getLifecycleService().addLifecycleListener(lifecycleListener);
FirewallingTcpIpConnectionManager cm1 = getFireWalledConnectionManager(hz1);
FirewallingTcpIpConnectionManager cm2 = getFireWalledConnectionManager(hz2);
FirewallingTcpIpConnectionManager cm3 = getFireWalledConnectionManager(hz3);
cm1.block(n2.address);
cm1.block(n3.address);
n2.clusterService.removeAddress(n1.address, null);
n3.clusterService.removeAddress(n1.address, null);
cm2.block(n1.address);
cm3.block(n1.address);
assertTrue(splitLatch.await(20, TimeUnit.SECONDS));
assertEquals(2, hz2.getCluster().getMembers().size());
assertEquals(2, hz3.getCluster().getMembers().size());
assertEquals(3, hz1.getCluster().getMembers().size());
cm1.unblock(n2.address);
cm1.unblock(n3.address);
cm2.unblock(n1.address);
cm3.unblock(n1.address);
assertTrue(mergingLatch.await(60, TimeUnit.SECONDS));
hz2.getLifecycleService().terminate();
hz2 = newHazelcastInstance(config, "test-node2", new FirewallingNodeContext());
n2 = TestUtil.getNode(hz2);
assertTrue(mergeLatch.await(120, TimeUnit.SECONDS));
assertEquals(3, hz1.getCluster().getMembers().size());
assertEquals(3, hz2.getCluster().getMembers().size());
assertEquals(3, hz3.getCluster().getMembers().size());
assertEquals(n3.getThisAddress(), n1.getMasterAddress());
assertEquals(n3.getThisAddress(), n2.getMasterAddress());
assertEquals(n3.getThisAddress(), n3.getMasterAddress());
}
use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class SplitBrainHandlerTest method testClusterMerge_when_split_not_detected_by_slave.
@Test
public // https://github.com/hazelcast/hazelcast/issues/8137
void testClusterMerge_when_split_not_detected_by_slave() throws InterruptedException {
Config config = new Config();
String groupName = generateRandomString(10);
config.getGroupConfig().setName(groupName);
config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "15");
config.setProperty(GroupProperty.MAX_JOIN_SECONDS.getName(), "10");
config.setProperty(GroupProperty.MAX_JOIN_MERGE_TARGET_SECONDS.getName(), "10");
NetworkConfig networkConfig = config.getNetworkConfig();
networkConfig.getJoin().getMulticastConfig().setEnabled(false);
networkConfig.getJoin().getTcpIpConfig().setEnabled(true).addMember("127.0.0.1");
HazelcastInstance hz1 = newHazelcastInstance(config, "test-node1", new FirewallingNodeContext());
HazelcastInstance hz2 = newHazelcastInstance(config, "test-node2", new FirewallingNodeContext());
HazelcastInstance hz3 = newHazelcastInstance(config, "test-node3", new FirewallingNodeContext());
Node n1 = TestUtil.getNode(hz1);
Node n2 = TestUtil.getNode(hz2);
final Node n3 = TestUtil.getNode(hz3);
final CountDownLatch splitLatch = new CountDownLatch(2);
MembershipAdapter membershipAdapter = new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent event) {
if (n3.getLocalMember().equals(event.getMember())) {
splitLatch.countDown();
}
}
};
hz1.getCluster().addMembershipListener(membershipAdapter);
hz2.getCluster().addMembershipListener(membershipAdapter);
final CountDownLatch mergeLatch = new CountDownLatch(1);
hz3.getLifecycleService().addLifecycleListener(new MergedEventLifeCycleListener(mergeLatch));
FirewallingTcpIpConnectionManager cm1 = getFireWalledConnectionManager(hz1);
FirewallingTcpIpConnectionManager cm2 = getFireWalledConnectionManager(hz2);
FirewallingTcpIpConnectionManager cm3 = getFireWalledConnectionManager(hz3);
cm3.block(n1.address);
cm3.block(n2.address);
n1.clusterService.removeAddress(n3.address, null);
n2.clusterService.removeAddress(n3.address, null);
cm1.block(n3.address);
cm2.block(n3.address);
assertTrue(splitLatch.await(30, TimeUnit.SECONDS));
assertEquals(2, hz1.getCluster().getMembers().size());
assertEquals(2, hz2.getCluster().getMembers().size());
assertEquals(3, hz3.getCluster().getMembers().size());
cm3.unblock(n1.address);
cm1.unblock(n3.address);
cm2.unblock(n3.address);
assertTrue(mergeLatch.await(120, TimeUnit.SECONDS));
assertEquals(3, hz1.getCluster().getMembers().size());
assertEquals(3, hz2.getCluster().getMembers().size());
assertEquals(3, hz3.getCluster().getMembers().size());
assertEquals(n1.getThisAddress(), n1.getMasterAddress());
assertEquals(n1.getThisAddress(), n2.getMasterAddress());
assertEquals(n1.getThisAddress(), n3.getMasterAddress());
}
use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class ClusterMembershipTest method assertMembershipEvent.
public void assertMembershipEvent(EventObject e, int type, Member changedMember, Member... expectedMembers) {
assertTrue(e instanceof MembershipEvent);
MembershipEvent membershipEvent = (MembershipEvent) e;
Set<Member> foundMembers = membershipEvent.getMembers();
assertEquals(type, membershipEvent.getEventType());
assertEquals(changedMember, membershipEvent.getMember());
assertEquals(new HashSet<Member>(Arrays.asList(expectedMembers)), foundMembers);
}
use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class PartitionedCluster method splitFiveMembersThreeAndTwo.
public PartitionedCluster splitFiveMembersThreeAndTwo() throws Exception {
final CountDownLatch splitLatch = new CountDownLatch(6);
h4.getCluster().addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
splitLatch.countDown();
}
});
h5.getCluster().addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
splitLatch.countDown();
}
});
splitCluster();
assertTrue(splitLatch.await(30, TimeUnit.SECONDS));
assertEquals(3, h1.getCluster().getMembers().size());
assertEquals(3, h2.getCluster().getMembers().size());
assertEquals(3, h3.getCluster().getMembers().size());
assertEquals(2, h4.getCluster().getMembers().size());
assertEquals(2, h5.getCluster().getMembers().size());
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertFalse(h4.getQuorumService().getQuorum(SUCCESSFUL_SPLIT_TEST_QUORUM_NAME).isPresent());
assertFalse(h5.getQuorumService().getQuorum(SUCCESSFUL_SPLIT_TEST_QUORUM_NAME).isPresent());
}
});
return this;
}
use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class ClusterServiceImpl method sendMembershipEventNotifications.
private void sendMembershipEventNotifications(MemberImpl member, Set<Member> members, final boolean added) {
int eventType = added ? MembershipEvent.MEMBER_ADDED : MembershipEvent.MEMBER_REMOVED;
MembershipEvent membershipEvent = new MembershipEvent(this, member, eventType, members);
Collection<MembershipAwareService> membershipAwareServices = nodeEngine.getServices(MembershipAwareService.class);
if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) {
final MembershipServiceEvent event = new MembershipServiceEvent(membershipEvent);
for (final MembershipAwareService service : membershipAwareServices) {
nodeEngine.getExecutionService().execute(MEMBERSHIP_EVENT_EXECUTOR_NAME, new Runnable() {
public void run() {
if (added) {
service.memberAdded(event);
} else {
service.memberRemoved(event);
}
}
});
}
}
EventService eventService = nodeEngine.getEventService();
Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
for (EventRegistration reg : registrations) {
eventService.publishEvent(SERVICE_NAME, reg, membershipEvent, reg.getId().hashCode());
}
}
Aggregations