use of com.hazelcast.client.spi.impl.ConnectionHeartbeatListener in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testHeartbeatStoppedEvent.
@Test
public void testHeartbeatStoppedEvent() throws InterruptedException {
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
final CountDownLatch countDownLatch = new CountDownLatch(1);
connectionManager.addConnectionHeartbeatListener(new ConnectionHeartbeatListener() {
@Override
public void heartbeatResumed(Connection connection) {
}
@Override
public void heartbeatStopped(Connection connection) {
countDownLatch.countDown();
}
});
blockMessagesFromInstance(instance, client);
assertOpenEventually(countDownLatch);
}
use of com.hazelcast.client.spi.impl.ConnectionHeartbeatListener in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testHeartbeatResumedEvent.
@Test
public void testHeartbeatResumedEvent() throws InterruptedException {
hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
// make sure client is connected to instance2
String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
IMap<String, String> map = client.getMap(randomString());
map.put(keyOwnedByInstance2, randomString());
HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
final ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
final CountDownLatch countDownLatch = new CountDownLatch(1);
connectionManager.addConnectionHeartbeatListener(new ConnectionHeartbeatListener() {
@Override
public void heartbeatResumed(Connection connection) {
assertEquals(instance2.getCluster().getLocalMember().getAddress(), connection.getEndPoint());
countDownLatch.countDown();
}
@Override
public void heartbeatStopped(Connection connection) {
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNotNull(connectionManager.getConnection(instance2.getCluster().getLocalMember().getAddress()));
}
});
blockMessagesFromInstance(instance2, client);
sleepMillis(HEARTBEAT_TIMEOUT_MILLIS * 2);
unblockMessagesFromInstance(instance2, client);
assertOpenEventually(countDownLatch);
}
Aggregations