use of com.hazelcast.internal.nio.ConnectionListener in project hazelcast by hazelcast.
the class TcpServerConnectionManager_ConnectionListenerTest method whenConnectionAdded.
@Test
public void whenConnectionAdded() {
startAllTcpServers();
ConnectionListener listener = mock(ConnectionListener.class);
tcpServerA.getConnectionManager(MEMBER).addConnectionListener(listener);
Connection c = connect(tcpServerA, addressB);
assertTrueEventually(() -> listener.connectionAdded(c));
}
use of com.hazelcast.internal.nio.ConnectionListener in project hazelcast by hazelcast.
the class TcpServerConnectionManager_ConnectionListenerTest method whenConnectionManagerShutdown_thenListenersRemoved.
@Test
public void whenConnectionManagerShutdown_thenListenersRemoved() {
startAllTcpServers();
ConnectionListener listener = mock(ConnectionListener.class);
tcpServerA.getConnectionManager(MEMBER).addConnectionListener(listener);
tcpServerA.shutdown();
TcpServerConnectionManager connectionManager = tcpServerA.getConnectionManager(EndpointQualifier.MEMBER);
assertEquals(0, connectionManager.connectionListeners.size());
}
use of com.hazelcast.internal.nio.ConnectionListener in project hazelcast by hazelcast.
the class TcpServerConnectionManager_ConnectionListenerTest method whenConnectionDestroyed.
@Test
public void whenConnectionDestroyed() {
startAllTcpServers();
ConnectionListener listener = mock(ConnectionListener.class);
tcpServerA.getConnectionManager(MEMBER).addConnectionListener(listener);
Connection c = connect(tcpServerA, addressB);
c.close(null, null);
assertTrueEventually(() -> listener.connectionRemoved(c));
}
use of com.hazelcast.internal.nio.ConnectionListener in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testConnectionClosed_whenHeartbeatStopped.
@Test
public void testConnectionClosed_whenHeartbeatStopped() {
hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
final ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
makeSureConnectedToServers(client, 2);
final CountDownLatch countDownLatch = new CountDownLatch(1);
connectionManager.addConnectionListener(new ConnectionListener() {
@Override
public void connectionAdded(Connection connection) {
}
@Override
public void connectionRemoved(Connection connection) {
countDownLatch.countDown();
}
});
blockMessagesFromInstance(instance, client);
assertOpenEventually(countDownLatch);
}
use of com.hazelcast.internal.nio.ConnectionListener in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testAddingListenerToNewConnectionFailedBecauseOfHeartbeat.
@Test
public void testAddingListenerToNewConnectionFailedBecauseOfHeartbeat() throws Exception {
hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final ClientListenerService clientListenerService = clientInstanceImpl.getListenerService();
final CountDownLatch blockIncoming = new CountDownLatch(1);
final CountDownLatch heartbeatStopped = new CountDownLatch(1);
final CountDownLatch onListenerRegister = new CountDownLatch(2);
clientInstanceImpl.getConnectionManager().addConnectionListener(new ConnectionListener() {
@Override
public void connectionAdded(Connection connection) {
}
@Override
public void connectionRemoved(Connection connection) {
heartbeatStopped.countDown();
}
});
clientListenerService.registerListener(createPartitionLostListenerCodec(), new EventHandler() {
AtomicInteger count = new AtomicInteger(0);
@Override
public void handle(Object event) {
}
@Override
public void beforeListenerRegister(Connection connection) {
if (count.incrementAndGet() == 2) {
try {
blockIncoming.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void onListenerRegister(Connection connection) {
onListenerRegister.countDown();
}
});
HazelcastInstance hazelcastInstance2 = hazelcastFactory.newHazelcastInstance();
assertSizeEventually(2, clientInstanceImpl.getConnectionManager().getActiveConnections());
blockMessagesFromInstance(hazelcastInstance2, client);
assertOpenEventually(heartbeatStopped);
blockIncoming.countDown();
unblockMessagesFromInstance(hazelcastInstance2, client);
assertOpenEventually(onListenerRegister);
}
Aggregations