Search in sources :

Example 6 with MembershipAdapter

use of com.hazelcast.core.MembershipAdapter in project hazelcast by hazelcast.

the class SplitBrainHandlerTest method testClusterMerge_when_split_not_detected_by_slave.

@Test
public // https://github.com/hazelcast/hazelcast/issues/8137
void testClusterMerge_when_split_not_detected_by_slave() throws InterruptedException {
    Config config = new Config();
    String groupName = generateRandomString(10);
    config.getGroupConfig().setName(groupName);
    config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
    config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
    config.setProperty(GroupProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "15");
    config.setProperty(GroupProperty.MAX_JOIN_SECONDS.getName(), "10");
    config.setProperty(GroupProperty.MAX_JOIN_MERGE_TARGET_SECONDS.getName(), "10");
    NetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.getJoin().getMulticastConfig().setEnabled(false);
    networkConfig.getJoin().getTcpIpConfig().setEnabled(true).addMember("127.0.0.1");
    HazelcastInstance hz1 = newHazelcastInstance(config, "test-node1", new FirewallingNodeContext());
    HazelcastInstance hz2 = newHazelcastInstance(config, "test-node2", new FirewallingNodeContext());
    HazelcastInstance hz3 = newHazelcastInstance(config, "test-node3", new FirewallingNodeContext());
    Node n1 = TestUtil.getNode(hz1);
    Node n2 = TestUtil.getNode(hz2);
    final Node n3 = TestUtil.getNode(hz3);
    final CountDownLatch splitLatch = new CountDownLatch(2);
    MembershipAdapter membershipAdapter = new MembershipAdapter() {

        @Override
        public void memberRemoved(MembershipEvent event) {
            if (n3.getLocalMember().equals(event.getMember())) {
                splitLatch.countDown();
            }
        }
    };
    hz1.getCluster().addMembershipListener(membershipAdapter);
    hz2.getCluster().addMembershipListener(membershipAdapter);
    final CountDownLatch mergeLatch = new CountDownLatch(1);
    hz3.getLifecycleService().addLifecycleListener(new MergedEventLifeCycleListener(mergeLatch));
    FirewallingTcpIpConnectionManager cm1 = getFireWalledConnectionManager(hz1);
    FirewallingTcpIpConnectionManager cm2 = getFireWalledConnectionManager(hz2);
    FirewallingTcpIpConnectionManager cm3 = getFireWalledConnectionManager(hz3);
    cm3.block(n1.address);
    cm3.block(n2.address);
    n1.clusterService.removeAddress(n3.address, null);
    n2.clusterService.removeAddress(n3.address, null);
    cm1.block(n3.address);
    cm2.block(n3.address);
    assertTrue(splitLatch.await(30, TimeUnit.SECONDS));
    assertEquals(2, hz1.getCluster().getMembers().size());
    assertEquals(2, hz2.getCluster().getMembers().size());
    assertEquals(3, hz3.getCluster().getMembers().size());
    cm3.unblock(n1.address);
    cm1.unblock(n3.address);
    cm2.unblock(n3.address);
    assertTrue(mergeLatch.await(120, TimeUnit.SECONDS));
    assertEquals(3, hz1.getCluster().getMembers().size());
    assertEquals(3, hz2.getCluster().getMembers().size());
    assertEquals(3, hz3.getCluster().getMembers().size());
    assertEquals(n1.getThisAddress(), n1.getMasterAddress());
    assertEquals(n1.getThisAddress(), n2.getMasterAddress());
    assertEquals(n1.getThisAddress(), n3.getMasterAddress());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) MembershipEvent(com.hazelcast.core.MembershipEvent) Node(com.hazelcast.instance.Node) NetworkConfig(com.hazelcast.config.NetworkConfig) MembershipAdapter(com.hazelcast.core.MembershipAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) FirewallingTcpIpConnectionManager(com.hazelcast.nio.tcp.FirewallingTcpIpConnectionManager) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 7 with MembershipAdapter

use of com.hazelcast.core.MembershipAdapter in project hazelcast by hazelcast.

the class PartitionedCluster method splitFiveMembersThreeAndTwo.

public PartitionedCluster splitFiveMembersThreeAndTwo() throws Exception {
    final CountDownLatch splitLatch = new CountDownLatch(6);
    h4.getCluster().addMembershipListener(new MembershipAdapter() {

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            splitLatch.countDown();
        }
    });
    h5.getCluster().addMembershipListener(new MembershipAdapter() {

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            splitLatch.countDown();
        }
    });
    splitCluster();
    assertTrue(splitLatch.await(30, TimeUnit.SECONDS));
    assertEquals(3, h1.getCluster().getMembers().size());
    assertEquals(3, h2.getCluster().getMembers().size());
    assertEquals(3, h3.getCluster().getMembers().size());
    assertEquals(2, h4.getCluster().getMembers().size());
    assertEquals(2, h5.getCluster().getMembers().size());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse(h4.getQuorumService().getQuorum(SUCCESSFUL_SPLIT_TEST_QUORUM_NAME).isPresent());
            assertFalse(h5.getQuorumService().getQuorum(SUCCESSFUL_SPLIT_TEST_QUORUM_NAME).isPresent());
        }
    });
    return this;
}
Also used : MembershipEvent(com.hazelcast.core.MembershipEvent) MembershipAdapter(com.hazelcast.core.MembershipAdapter) AssertTask(com.hazelcast.test.AssertTask) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 8 with MembershipAdapter

use of com.hazelcast.core.MembershipAdapter in project hazelcast by hazelcast.

the class ClientReconnectTest method testReconnectToNewInstanceAtSameAddress.

@Test
public void testReconnectToNewInstanceAtSameAddress() throws InterruptedException {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    Address localAddress = instance.getCluster().getLocalMember().getAddress();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    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(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, client.getCluster().getMembers().size());
            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.nio.Address) MembershipEvent(com.hazelcast.core.MembershipEvent) MembershipAdapter(com.hazelcast.core.MembershipAdapter) Iterator(java.util.Iterator) AssertTask(com.hazelcast.test.AssertTask) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with MembershipAdapter

use of com.hazelcast.core.MembershipAdapter in project hazelcast by hazelcast.

the class ClientTxnTest method testTxnRollback.

@Test
public void testTxnRollback() throws Exception {
    final String queueName = randomString();
    final TransactionContext context = client.newTransactionContext();
    CountDownLatch txnRollbackLatch = new CountDownLatch(1);
    final CountDownLatch memberRemovedLatch = new CountDownLatch(1);
    client.getCluster().addMembershipListener(new MembershipAdapter() {

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            memberRemovedLatch.countDown();
        }
    });
    try {
        context.beginTransaction();
        assertNotNull(context.getTxnId());
        final TransactionalQueue queue = context.getQueue(queueName);
        queue.offer(randomString());
        server.shutdown();
        context.commitTransaction();
        fail("commit should throw exception!!!");
    } catch (Exception e) {
        context.rollbackTransaction();
        txnRollbackLatch.countDown();
    }
    assertOpenEventually(txnRollbackLatch);
    assertOpenEventually(memberRemovedLatch);
    final IQueue<Object> q = client.getQueue(queueName);
    assertNull(q.poll());
    assertEquals(0, q.size());
}
Also used : TransactionalQueue(com.hazelcast.core.TransactionalQueue) TransactionContext(com.hazelcast.transaction.TransactionContext) MembershipEvent(com.hazelcast.core.MembershipEvent) MembershipAdapter(com.hazelcast.core.MembershipAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with MembershipAdapter

use of com.hazelcast.core.MembershipAdapter in project hazelcast by hazelcast.

the class DefaultPublisherContext method handleSubscriberAddRemove.

private void handleSubscriberAddRemove() {
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
    clusterService.addMembershipListener(new MembershipAdapter() {

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            Member member = membershipEvent.getMember();
            String uuid = member.getUuid();
            handleDisconnectedSubscriber(uuid);
        }

        @Override
        public void memberAdded(MembershipEvent membershipEvent) {
            Member member = membershipEvent.getMember();
            String uuid = member.getUuid();
            handleConnectedSubscriber(uuid);
        }
    });
}
Also used : MembershipEvent(com.hazelcast.core.MembershipEvent) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) MembershipAdapter(com.hazelcast.core.MembershipAdapter) Member(com.hazelcast.core.Member)

Aggregations

MembershipAdapter (com.hazelcast.core.MembershipAdapter)11 MembershipEvent (com.hazelcast.core.MembershipEvent)9 CountDownLatch (java.util.concurrent.CountDownLatch)7 Test (org.junit.Test)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Config (com.hazelcast.config.Config)3 JoinConfig (com.hazelcast.config.JoinConfig)3 ListenerConfig (com.hazelcast.config.ListenerConfig)3 NetworkConfig (com.hazelcast.config.NetworkConfig)3 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance)3 Node (com.hazelcast.instance.Node)3 FirewallingTcpIpConnectionManager (com.hazelcast.nio.tcp.FirewallingTcpIpConnectionManager)3 Member (com.hazelcast.core.Member)2 TransactionalQueue (com.hazelcast.core.TransactionalQueue)2 AssertTask (com.hazelcast.test.AssertTask)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 TransactionContext (com.hazelcast.transaction.TransactionContext)2 Cluster (com.hazelcast.core.Cluster)1