Search in sources :

Example 1 with CountingDownCPMembershipListener

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)

Example 2 with CountingDownCPMembershipListener

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)

Example 3 with CountingDownCPMembershipListener

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountingDownCPMembershipListener(com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with CountingDownCPMembershipListener

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountingDownCPMembershipListener(com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with CountingDownCPMembershipListener

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);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountingDownCPMembershipListener(com.hazelcast.cp.CPMembershipListenerTest.CountingDownCPMembershipListener) ClientConfig(com.hazelcast.client.config.ClientConfig) 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