use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientConfigLoadBalancerTest method shouldCreateRoundRobinLoadBalancerWhenNoConfigProvided.
@Test
public void shouldCreateRoundRobinLoadBalancerWhenNoConfigProvided() {
hazelcastFactory.newHazelcastInstance();
HazelcastInstance instance = hazelcastFactory.newHazelcastClient(new ClientConfig());
HazelcastClientInstanceImpl client = ClientTestUtil.getHazelcastClientInstanceImpl(instance);
LoadBalancer actual = client.getLoadBalancer();
assertTrue(actual instanceof RoundRobinLB);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientConfigLoadBalancerTest method shouldUseConfigClassLoaderInstanceWhenClassNameNotSpecified.
@Test
public void shouldUseConfigClassLoaderInstanceWhenClassNameNotSpecified() {
hazelcastFactory.newHazelcastInstance();
LoadBalancer loadBalancer = new RandomLB();
ClientConfig config = new ClientConfig();
config.setLoadBalancer(loadBalancer);
HazelcastInstance instance = hazelcastFactory.newHazelcastClient(config);
HazelcastClientInstanceImpl client = ClientTestUtil.getHazelcastClientInstanceImpl(instance);
LoadBalancer actual = client.getLoadBalancer();
assertSame(loadBalancer, actual);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl 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.client.impl.clientside.HazelcastClientInstanceImpl 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);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientInvocationTest method invokeOnMemberRedirectsToRandom_whenMemberIsNotInMemberList.
@Test
public void invokeOnMemberRedirectsToRandom_whenMemberIsNotInMemberList() throws Exception {
hazelcastFactory.newHazelcastInstance();
UUID unavailableTarget = UUID.randomUUID();
HazelcastClientInstanceImpl client = getHazelcastClientInstanceImpl(hazelcastFactory.newHazelcastClient());
ClientMessage request = MapSizeCodec.encodeRequest("test");
ClientInvocation invocation = new ClientInvocation(client, request, "map", unavailableTarget);
assertEquals(0, MapSizeCodec.decodeResponse(invocation.invoke().get()));
}
Aggregations