use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class ClientUniSocketTxnTest method testUniSocketClient_shouldNotOpenANewConnection.
@Test
public void testUniSocketClient_shouldNotOpenANewConnection() {
hazelcastFactory.newHazelcastInstance();
ClientConfig config = new ClientConfig();
config.getNetworkConfig().setRedoOperation(true);
config.getNetworkConfig().setSmartRouting(false);
// try to force second member to connect when exist
config.setLoadBalancer(new AbstractLoadBalancer() {
@Override
public Member next() {
Member[] members = getMembers();
if (members == null || members.length == 0) {
return null;
}
if (members.length == 2) {
return members[1];
}
return members[0];
}
@Override
public Member nextDataMember() {
Member[] members = getDataMembers();
if (members == null || members.length == 0) {
return null;
}
if (members.length == 2) {
return members[1];
}
return members[0];
}
@Override
public boolean canGetNextDataMember() {
return true;
}
});
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
hazelcastFactory.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, client.getCluster().getMembers().size());
}
});
ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
TransactionContext context = client.newTransactionContext();
context.beginTransaction();
context.commitTransaction();
assertEquals(1, connectionManager.getActiveConnections().size());
}
use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class ClientTxnUniSocketTest method testUniSocketClient_shouldNotOpenANewConnection.
@Test
public void testUniSocketClient_shouldNotOpenANewConnection() {
hazelcastFactory.newHazelcastInstance();
ClientConfig config = new ClientConfig();
config.getNetworkConfig().setRedoOperation(true);
config.getNetworkConfig().setSmartRouting(false);
// try to force second member to connect when exist
config.setLoadBalancer(new AbstractLoadBalancer() {
@Override
public Member next() {
Member[] members = getMembers();
if (members == null || members.length == 0) {
return null;
}
if (members.length == 2) {
return members[1];
}
return members[0];
}
@Override
public Member nextDataMember() {
Member[] members = getDataMembers();
if (members == null || members.length == 0) {
return null;
}
if (members.length == 2) {
return members[1];
}
return members[0];
}
@Override
public boolean canGetNextDataMember() {
return true;
}
});
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
hazelcastFactory.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, client.getCluster().getMembers().size());
}
});
ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
TransactionContext context = client.newTransactionContext();
context.beginTransaction();
context.commitTransaction();
assertEquals(1, connectionManager.getActiveConnections().size());
}
use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class TcpClientConnectionTest method destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce.
@Test
public void destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce() {
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
final CountingConnectionListener listener = new CountingConnectionListener();
connectionManager.addConnectionListener(listener);
UUID serverUuid = server.getCluster().getLocalMember().getUuid();
final Connection connectionToServer = connectionManager.getConnection(serverUuid);
ReconnectListener reconnectListener = new ReconnectListener();
clientImpl.getLifecycleService().addLifecycleListener(reconnectListener);
connectionToServer.close(null, null);
assertOpenEventually(reconnectListener.reconnectedLatch);
connectionToServer.close(null, null);
assertEqualsEventually(() -> listener.connectionRemovedCount.get(), 1);
sleepMillis(100);
assertEquals("connection removed should be called only once", 1, listener.connectionRemovedCount.get());
}
use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class ClientRegressionWithRealNetworkTest method testConnectionCountAfterClientReconnect.
private void testConnectionCountAfterClientReconnect(String memberAddress, String clientAddress) {
Config config = new Config();
config.getNetworkConfig().setPublicAddress(memberAddress);
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress(clientAddress);
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientInstanceImpl.getConnectionManager();
assertTrueEventually(() -> assertEquals(1, connectionManager.getActiveConnections().size()));
ReconnectListener reconnectListener = new ReconnectListener();
client.getLifecycleService().addLifecycleListener(reconnectListener);
hazelcastInstance.shutdown();
assertOpenEventually(reconnectListener.disconnectedLatch);
Hazelcast.newHazelcastInstance(config);
assertOpenEventually(reconnectListener.reconnectedLatch);
assertEquals(1, connectionManager.getActiveConnections().size());
}
use of com.hazelcast.client.impl.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class TcpClientConnectionTest method testAddingConnectionListenerTwice_shouldCauseEventDeliveredTwice.
@Test
public void testAddingConnectionListenerTwice_shouldCauseEventDeliveredTwice() {
hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
final CountingConnectionListener listener = new CountingConnectionListener();
connectionManager.addConnectionListener(listener);
connectionManager.addConnectionListener(listener);
hazelcastFactory.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(listener.connectionAddedCount.get(), 2);
}
});
}
Aggregations