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());
}
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);
}
}
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);
}
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);
}
});
}
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);
});
}
Aggregations