use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method testListenersTerminateOwnerNode.
private void testListenersTerminateOwnerNode() {
setupListener();
final CountDownLatch disconnectedLatch = new CountDownLatch(1);
final CountDownLatch connectedLatch = new CountDownLatch(1);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (LifecycleEvent.LifecycleState.CLIENT_DISCONNECTED == event.getState()) {
disconnectedLatch.countDown();
}
if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
connectedLatch.countDown();
}
}
});
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
HazelcastInstance server = getOwnerServer(factory, clientInstanceImpl);
server.getLifecycleService().terminate();
factory.newHazelcastInstance();
assertClusterSizeEventually(clusterSize, client);
assertOpenEventually(disconnectedLatch);
assertOpenEventually(connectedLatch);
validateRegistrationsAndListenerFunctionality();
}
use of com.hazelcast.client.impl.HazelcastClientInstanceImpl 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.MockClientConnectionManager) connectionManager).blockTo(address);
}
use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked_fromOtherNode.
@Test
public void test_mapPartitionLostListener_invoked_fromOtherNode() {
final String mapName = randomMapName();
final Config config = new Config();
config.getMapConfig(mapName).setBackupCount(0);
final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
final ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setSmartRouting(false);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final Address clientOwnerAddress = clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress();
final HazelcastInstance other = getAddress(instance1).equals(clientOwnerAddress) ? instance2 : instance1;
final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
client.getMap(mapName).addPartitionLostListener(listener);
assertRegistrationEventually(instance1, mapName, true);
assertRegistrationEventually(instance2, mapName, true);
assertProxyExistsEventually(instance1, mapName);
assertProxyExistsEventually(instance2, mapName);
final MapService mapService = getNode(other).getNodeEngine().getService(SERVICE_NAME);
final int partitionId = 5;
mapService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertMapPartitionLostEventEventually(listener, partitionId);
}
use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientServiceTest method testPendingEventPacketsWithEvents.
@Test(timeout = 120000)
public void testPendingEventPacketsWithEvents() throws InterruptedException, UnknownHostException {
HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
IMap map = client.getMap(randomName());
map.addEntryListener(new EntryAdapter(), false);
for (int i = 0; i < 10; i++) {
map.put(randomString(), randomString());
}
HazelcastClientInstanceImpl clientInstanceImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
InetSocketAddress socketAddress = hazelcastInstance.getCluster().getLocalMember().getSocketAddress();
Address address = new Address(socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
ClientConnectionManager connectionManager = clientInstanceImpl.getConnectionManager();
final ClientConnection connection = (ClientConnection) connectionManager.getConnection(address);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, connection.getPendingPacketCount());
}
});
}
use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientPartitionCancellableDelegatingFuture method invokeCancelRequest.
private boolean invokeCancelRequest(boolean mayInterruptIfRunning) throws InterruptedException {
waitForRequestToBeSend();
ClientInvocation clientInvocation;
final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
ClientMessage request = ExecutorServiceCancelOnPartitionCodec.encodeRequest(uuid, partitionId, mayInterruptIfRunning);
clientInvocation = new ClientInvocation(client, request, partitionId);
try {
ClientInvocationFuture f = clientInvocation.invoke();
return ExecutorServiceCancelOnPartitionCodec.decodeResponse(f.get()).response;
} catch (Exception e) {
throw rethrow(e);
}
}
Aggregations