Search in sources :

Example 6 with CountingDownCPMembershipListener

use of com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener in project hazelcast by hazelcast.

the class ClientCPMembershipListenerTest method whenMemberTerminated_thenReceiveMemberRemovedEvent.

@Test
public void whenMemberTerminated_thenReceiveMemberRemovedEvent() {
    Config config = createConfig(3, 3);
    config.getCPSubsystemConfig().setSessionTimeToLiveSeconds(2).setSessionHeartbeatIntervalSeconds(1).setMissingCPMemberAutoRemovalSeconds(3);
    HazelcastInstance[] instances = factory.newInstances(config, 3);
    waitUntilCPDiscoveryCompleted(instances);
    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.getLifecycleService().terminate();
    assertOpenEventually(listener.removedLatch);
    assertEquals(member, listener.removedMembers.get(0));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ListenerConfig(com.hazelcast.config.ListenerConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) CountingDownCPMembershipListener(com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 CountingDownCPMembershipListener (com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 CPMember (com.hazelcast.cp.CPMember)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ListenerConfig (com.hazelcast.config.ListenerConfig)2 Config (com.hazelcast.config.Config)1 UUID (java.util.UUID)1