Search in sources :

Example 6 with MembershipEvent

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);
    }
}
Also used : MembershipEvent(com.hazelcast.cluster.MembershipEvent) MembershipAdapter(com.hazelcast.cluster.MembershipAdapter) HazelcastTestSupport.generateRandomString(com.hazelcast.test.HazelcastTestSupport.generateRandomString) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with MembershipEvent

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();
}
Also used : MembershipEvent(com.hazelcast.cluster.MembershipEvent) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.cluster.MembershipListener)

Example 8 with MembershipEvent

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);
        }
    });
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) MembershipEvent(com.hazelcast.cluster.MembershipEvent) MembershipAdapter(com.hazelcast.cluster.MembershipAdapter) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member)

Example 9 with MembershipEvent

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);
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) MembershipEvent(com.hazelcast.cluster.MembershipEvent) MembershipAdapter(com.hazelcast.cluster.MembershipAdapter) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with MembershipEvent

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());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InitialMembershipEvent(com.hazelcast.cluster.InitialMembershipEvent) MembershipEvent(com.hazelcast.cluster.MembershipEvent) AssertTask(com.hazelcast.test.AssertTask) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MembershipEvent (com.hazelcast.cluster.MembershipEvent)15 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 Member (com.hazelcast.cluster.Member)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 MembershipListener (com.hazelcast.cluster.MembershipListener)6 MembershipAdapter (com.hazelcast.cluster.MembershipAdapter)5 ClientConfig (com.hazelcast.client.config.ClientConfig)3 InitialMembershipEvent (com.hazelcast.cluster.InitialMembershipEvent)3 Address (com.hazelcast.cluster.Address)2 Config (com.hazelcast.config.Config)2 AssertTask (com.hazelcast.test.AssertTask)2 TransactionContext (com.hazelcast.transaction.TransactionContext)2 TransactionException (com.hazelcast.transaction.TransactionException)2 TransactionalQueue (com.hazelcast.transaction.TransactionalQueue)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 TcpClientConnection (com.hazelcast.client.impl.connection.tcp.TcpClientConnection)1