Search in sources :

Example 1 with ConnectionListener

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));
}
Also used : Connection(com.hazelcast.internal.nio.Connection) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ConnectionListener

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());
}
Also used : ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ConnectionListener

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));
}
Also used : Connection(com.hazelcast.internal.nio.Connection) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ConnectionListener

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Connection(com.hazelcast.internal.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ConnectionListener

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);
}
Also used : ClientListenerService(com.hazelcast.client.impl.spi.ClientListenerService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Connection(com.hazelcast.internal.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) EventHandler(com.hazelcast.client.impl.spi.EventHandler) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ConnectionListener (com.hazelcast.internal.nio.ConnectionListener)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 Connection (com.hazelcast.internal.nio.Connection)4 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)1 ClientListenerService (com.hazelcast.client.impl.spi.ClientListenerService)1 EventHandler (com.hazelcast.client.impl.spi.EventHandler)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1