Search in sources :

Example 11 with ClientConnectionManager

use of com.hazelcast.client.impl.connection.ClientConnectionManager 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 12 with ClientConnectionManager

use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.

the class ClientClusterServiceImpl method getLocalClient.

@Override
public Client getLocalClient() {
    final ClientConnectionManager cm = client.getConnectionManager();
    final TcpClientConnection connection = (TcpClientConnection) cm.getRandomConnection();
    InetSocketAddress inetSocketAddress = connection != null ? connection.getLocalSocketAddress() : null;
    UUID clientUuid = cm.getClientUuid();
    return new ClientImpl(clientUuid, inetSocketAddress, client.getName(), labels);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ClientImpl(com.hazelcast.client.impl.ClientImpl) UUID(java.util.UUID) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) TcpClientConnection(com.hazelcast.client.impl.connection.tcp.TcpClientConnection)

Example 13 with ClientConnectionManager

use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.

the class ClientTestSupport method blockMessagesToInstance.

/**
 * Blocks outgoing messages from client to given instance
 */
protected void blockMessagesToInstance(HazelcastInstance instance, HazelcastInstance client) {
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    Address address = instance.getCluster().getLocalMember().getAddress();
    ((TestClientRegistry.MockTcpClientConnectionManager) connectionManager).blockTo(address);
}
Also used : Address(com.hazelcast.cluster.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager)

Example 14 with ClientConnectionManager

use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.

the class ClientTestSupport method makeSureConnectedToServers.

protected void makeSureConnectedToServers(final HazelcastInstance client, final int numberOfServers) {
    assertTrueEventually(() -> {
        ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
        assertEquals(numberOfServers, connectionManager.getActiveConnections().size());
    });
}
Also used : ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager)

Aggregations

ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)14 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 Address (com.hazelcast.cluster.Address)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 Connection (com.hazelcast.internal.nio.Connection)3 AssertTask (com.hazelcast.test.AssertTask)3 AbstractLoadBalancer (com.hazelcast.client.util.AbstractLoadBalancer)2 Member (com.hazelcast.cluster.Member)2 TransactionContext (com.hazelcast.transaction.TransactionContext)2 UUID (java.util.UUID)2 ClientConnectionStrategyConfig (com.hazelcast.client.config.ClientConnectionStrategyConfig)1 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)1 ClientImpl (com.hazelcast.client.impl.ClientImpl)1 ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)1 TcpClientConnection (com.hazelcast.client.impl.connection.tcp.TcpClientConnection)1 TcpClientConnectionManager (com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager)1