use of com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener in project hazelcast by hazelcast.
the class ClientCPMembershipListenerTest method whenMultipleListenersRegistered_thenAllReceiveEvents.
@Test
public void whenMultipleListenersRegistered_thenAllReceiveEvents() {
HazelcastInstance[] instances = newInstances(3);
HazelcastInstance client = factory.newHazelcastClient();
CountingDownCPMembershipListener listener1 = new CountingDownCPMembershipListener(0, 1);
CountingDownCPMembershipListener listener2 = new CountingDownCPMembershipListener(0, 1);
client.getCPSubsystem().addMembershipListener(listener1);
client.getCPSubsystem().addMembershipListener(listener2);
HazelcastInstance instance = instances[instances.length - 1];
CPMember member = instance.getCPSubsystem().getLocalCPMember();
instance.shutdown();
assertOpenEventually(listener1.removedLatch);
assertOpenEventually(listener2.removedLatch);
assertEquals(member, listener1.removedMembers.get(0));
assertEquals(member, listener2.removedMembers.get(0));
}
use of com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener in project hazelcast by hazelcast.
the class ClientCPMembershipListenerTest method whenMemberShutdown_thenReceiveMemberRemovedEvent.
@Test
public void whenMemberShutdown_thenReceiveMemberRemovedEvent() {
HazelcastInstance[] instances = newInstances(3);
HazelcastInstance client = factory.newHazelcastClient();
CountingDownCPMembershipListener listener = new CountingDownCPMembershipListener(0, 1);
client.getCPSubsystem().addMembershipListener(listener);
HazelcastInstance instance = instances[instances.length - 1];
CPMember member = instance.getCPSubsystem().getLocalCPMember();
instance.shutdown();
assertOpenEventually(listener.removedLatch);
assertEquals(member, listener.removedMembers.get(0));
}
use of com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener in project hazelcast by hazelcast.
the class ClientCPMembershipListenerTest method whenListenerDeregistered_thenNoEventsReceived.
@Test
public void whenListenerDeregistered_thenNoEventsReceived() {
CountingDownCPMembershipListener listener = new CountingDownCPMembershipListener(1, 1);
HazelcastInstance[] instances = newInstances(5);
HazelcastInstance client = factory.newHazelcastClient();
UUID id = client.getCPSubsystem().addMembershipListener(listener);
instances[0].shutdown();
assertTrueEventually(() -> assertEquals(1, listener.removedMembers.size()));
assertTrue(client.getCPSubsystem().removeMembershipListener(id));
instances[2].shutdown();
assertTrueAllTheTime(() -> assertEquals(1, listener.removedMembers.size()), 3);
}
use of com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener in project hazelcast by hazelcast.
the class ClientCPMembershipListenerTest method whenMemberPromoted_thenReceiveMemberAddedEvent.
@Test
public void whenMemberPromoted_thenReceiveMemberAddedEvent() {
HazelcastInstance[] instances = newInstances(3, 3, 1);
HazelcastInstance client = factory.newHazelcastClient();
CountingDownCPMembershipListener listener = new CountingDownCPMembershipListener(1, 0);
client.getCPSubsystem().addMembershipListener(listener);
HazelcastInstance instance = instances[instances.length - 1];
instance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().join();
assertOpenEventually(listener.addedLatch);
assertEquals(instance.getCPSubsystem().getLocalCPMember(), listener.addedMembers.get(0));
}
use of com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener in project hazelcast by hazelcast.
the class ClientCPMembershipListenerTest method whenRegisteredInConfig_thenReceiveEvents.
@Test
public void whenRegisteredInConfig_thenReceiveEvents() {
HazelcastInstance[] instances = newInstances(3);
CountingDownCPMembershipListener listener = new CountingDownCPMembershipListener(0, 1);
ClientConfig config = new ClientConfig();
config.addListenerConfig(new ListenerConfig().setImplementation(listener));
factory.newHazelcastClient(config);
instances[2].shutdown();
assertOpenEventually(listener.removedLatch);
}
Aggregations