use of com.hazelcast.cluster.MembershipEvent in project hazelcast by hazelcast.
the class PartitionedCluster method splitFiveMembersThreeAndTwo.
public void splitFiveMembersThreeAndTwo(String... splitBrainProtectionIds) {
final CountDownLatch splitLatch = new CountDownLatch(6);
instance[3].getCluster().addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
splitLatch.countDown();
}
});
instance[4].getCluster().addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
splitLatch.countDown();
}
});
splitCluster();
assertOpenEventually(splitLatch, 60);
assertClusterSizeEventually(3, instance[0], instance[1], instance[2]);
assertClusterSizeEventually(2, instance[3], instance[4]);
verifySplitBrainProtections(SUCCESSFUL_SPLIT_BRAIN_PROTECTION_TEST_NAME);
for (String splitBrainProtectionId : splitBrainProtectionIds) {
verifySplitBrainProtections(splitBrainProtectionId);
}
}
use of com.hazelcast.cluster.MembershipEvent in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method testListenersTerminateRandomNode.
private void testListenersTerminateRandomNode(boolean isSmartClient) {
factory.newInstances(null, 3);
ClientConfig clientConfig = createClientConfig(isSmartClient);
client = factory.newHazelcastClient(clientConfig);
setupListener();
terminateRandomNode();
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final CountDownLatch memberAddedLatch = new CountDownLatch(1);
clientInstanceImpl.getClientClusterService().addMembershipListener(new MembershipListener() {
@Override
public void memberAdded(MembershipEvent membershipEvent) {
memberAddedLatch.countDown();
}
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
}
});
factory.newHazelcastInstance();
assertOpenEventually(memberAddedLatch);
validateRegistrationsAndListenerFunctionality();
}
use of com.hazelcast.cluster.MembershipEvent in project hazelcast by hazelcast.
the class DefaultPublisherContext method handleSubscriberAddRemove.
private void handleSubscriberAddRemove() {
ClusterService clusterService = nodeEngine.getClusterService();
clusterService.addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
Member member = membershipEvent.getMember();
UUID uuid = member.getUuid();
handleDisconnectedSubscriber(uuid);
}
@Override
public void memberAdded(MembershipEvent membershipEvent) {
Member member = membershipEvent.getMember();
UUID uuid = member.getUuid();
handleConnectedSubscriber(uuid);
}
});
}
use of com.hazelcast.cluster.MembershipEvent in project hazelcast by hazelcast.
the class ClientReconnectTest method testReconnectToNewInstanceAtSameAddress.
@Test
public void testReconnectToNewInstanceAtSameAddress() {
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
Address localAddress = instance.getCluster().getLocalMember().getAddress();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final CountDownLatch memberRemovedLatch = new CountDownLatch(1);
client.getCluster().addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
memberRemovedLatch.countDown();
}
});
instance.shutdown();
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(localAddress);
assertOpenEventually(memberRemovedLatch);
assertTrueEventually(() -> {
assertClusterSize(1, client);
Iterator<Member> iterator = client.getCluster().getMembers().iterator();
Member member = iterator.next();
assertEquals(instance2.getCluster().getLocalMember(), member);
});
}
use of com.hazelcast.cluster.MembershipEvent in project hazelcast by hazelcast.
the class MembershipListenerTest method whenMemberRemoved_thenMemberRemovedEvent.
@Test
public void whenMemberRemoved_thenMemberRemovedEvent() throws Exception {
final HazelcastInstance server1 = hazelcastFactory.newHazelcastInstance();
final MemberShipEventLogger listener = new MemberShipEventLogger();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
// start a second server and verify that hazelcastFactory listener receives it.
final HazelcastInstance server2 = hazelcastFactory.newHazelcastInstance();
client.getCluster().addMembershipListener(listener);
final Member server2Member = server2.getCluster().getLocalMember();
server2.shutdown();
// verify that the correct member removed event was received.
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNotEquals("Expecting one or more events", 0, listener.events.size());
MembershipEvent event = (MembershipEvent) listener.events.getLast();
assertEquals("Last event should be member removed", MembershipEvent.MEMBER_REMOVED, event.getEventType());
assertEquals(server2Member, event.getMember());
assertEquals(getMembers(server1), event.getMembers());
}
});
}
Aggregations