use of com.hazelcast.core.MembershipEvent in project camel by apache.
the class HazelcastInstanceConsumerTest method testRemoveInstance.
@Test
public void testRemoveInstance() throws InterruptedException {
MockEndpoint removed = getMockEndpoint("mock:removed");
removed.setExpectedMessageCount(1);
when(member.getSocketAddress()).thenReturn(new InetSocketAddress("foo.bar", 12345));
MembershipEvent event = new MembershipEvent(cluster, member, MembershipEvent.MEMBER_REMOVED, null);
argument.getValue().memberRemoved(event);
assertMockEndpointsSatisfied(5000, TimeUnit.MILLISECONDS);
// check headers
Exchange ex = removed.getExchanges().get(0);
Map<String, Object> headers = ex.getIn().getHeaders();
this.checkHeaders(headers, HazelcastConstants.REMOVED);
}
use of com.hazelcast.core.MembershipEvent in project camel by apache.
the class HazelcastInstanceConsumerTest method testAddInstance.
@Test
public void testAddInstance() throws InterruptedException {
MockEndpoint added = getMockEndpoint("mock:added");
added.setExpectedMessageCount(1);
when(member.getSocketAddress()).thenReturn(new InetSocketAddress("foo.bar", 12345));
MembershipEvent event = new MembershipEvent(cluster, member, MembershipEvent.MEMBER_ADDED, null);
argument.getValue().memberAdded(event);
assertMockEndpointsSatisfied(5000, TimeUnit.MILLISECONDS);
// check headers
Exchange ex = added.getExchanges().get(0);
Map<String, Object> headers = ex.getIn().getHeaders();
this.checkHeaders(headers, HazelcastConstants.ADDED);
}
use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class ClientMembershipListener method memberRemoved.
private void memberRemoved(Member member) {
members.remove(member);
logger.info(membersString());
final Connection connection = connectionManager.getConnection(member.getAddress());
if (connection != null) {
connection.close(null, newTargetDisconnectedExceptionCausedByMemberLeftEvent(connection));
}
MembershipEvent event = new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_REMOVED, unmodifiableSet(members));
clusterService.handleMembershipEvent(event);
}
use of com.hazelcast.core.MembershipEvent in project hazelcast by hazelcast.
the class MembershipListenerTest method whenMemberAdded_thenMemberAddedEvent.
@Test
public void whenMemberAdded_thenMemberAddedEvent() throws Exception {
final HazelcastInstance server1 = hazelcastFactory.newHazelcastInstance();
final MemberShipEventLogger listener = new MemberShipEventLogger();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
client.getCluster().addMembershipListener(listener);
//start a second server and verify that the listener receives it.
final HazelcastInstance server2 = hazelcastFactory.newHazelcastInstance();
//verify that the listener receives member added event.
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 added", MembershipEvent.MEMBER_ADDED, event.getEventType());
assertEquals(server2.getCluster().getLocalMember(), event.getMember());
assertEquals(getMembers(server1, server2), event.getMembers());
}
});
}
use of com.hazelcast.core.MembershipEvent 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 (Exception e) {
context.rollbackTransaction();
txnRollbackLatch.countDown();
}
assertOpenEventually(txnRollbackLatch);
assertOpenEventually(memberRemovedLatch);
final IQueue<Object> q = client.getQueue(queueName);
assertNull(q.poll());
assertEquals(0, q.size());
}
Aggregations