Search in sources :

Example 6 with MembershipAdapter

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

the class ClientClusterProxyTest method removeMembershipListener.

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

Example 7 with MembershipAdapter

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

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