Search in sources :

Example 1 with MembershipAdapter

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

the class ClientTxnTest method testTxnRollbackOnServerCrash.

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

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            memberRemovedLatch.countDown();
        }
    });
    server.getLifecycleService().terminate();
    try {
        context.commitTransaction();
        fail("commit should throw exception !");
    } catch (TransactionException 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.transaction.TransactionalQueue) TransactionException(com.hazelcast.transaction.TransactionException) TransactionContext(com.hazelcast.transaction.TransactionContext) MembershipEvent(com.hazelcast.cluster.MembershipEvent) MembershipAdapter(com.hazelcast.cluster.MembershipAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with MembershipAdapter

use of com.hazelcast.cluster.MembershipAdapter 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 3 with MembershipAdapter

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

the class ClientClusterProxyTest method addMembershipListener.

@Test
public void addMembershipListener() throws Exception {
    UUID regId = client().getCluster().addMembershipListener(new MembershipAdapter());
    assertNotNull(regId);
}
Also used : MembershipAdapter(com.hazelcast.cluster.MembershipAdapter) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MembershipAdapter

use of com.hazelcast.cluster.MembershipAdapter 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 5 with MembershipAdapter

use of com.hazelcast.cluster.MembershipAdapter 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)

Aggregations

MembershipAdapter (com.hazelcast.cluster.MembershipAdapter)7 MembershipEvent (com.hazelcast.cluster.MembershipEvent)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 UUID (java.util.UUID)3 Member (com.hazelcast.cluster.Member)2 TransactionContext (com.hazelcast.transaction.TransactionContext)2 TransactionException (com.hazelcast.transaction.TransactionException)2 TransactionalQueue (com.hazelcast.transaction.TransactionalQueue)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 Address (com.hazelcast.cluster.Address)1 Cluster (com.hazelcast.cluster.Cluster)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 HazelcastTestSupport.generateRandomString (com.hazelcast.test.HazelcastTestSupport.generateRandomString)1