use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl 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.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientRegressionWithRealNetworkTest method testListenersAfterClientDisconnected.
private void testListenersAfterClientDisconnected(String memberAddress, String clientAddress) {
Config config = new Config();
int heartBeatSeconds = 6;
config.getNetworkConfig().setPublicAddress(memberAddress);
config.setProperty(ClusterProperty.CLIENT_HEARTBEAT_TIMEOUT_SECONDS.getName(), Integer.toString(heartBeatSeconds));
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
networkConfig.addAddress(clientAddress);
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
IMap<Integer, Integer> map = client.getMap("test");
AtomicInteger eventCount = new AtomicInteger(0);
map.addEntryListener((EntryAddedListener<Object, Object>) event -> eventCount.incrementAndGet(), false);
assertTrueEventually(() -> {
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
int size = clientInstanceImpl.getConnectionManager().getActiveConnections().size();
assertEquals(1, size);
});
hazelcastInstance.shutdown();
sleepAtLeastSeconds(2 * heartBeatSeconds);
Hazelcast.newHazelcastInstance(config);
assertTrueEventually(() -> {
map.remove(1);
map.put(1, 2);
assertNotEquals(0, eventCount.get());
});
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientSplitBrainTest method testClientEngineCleanup_AfterMergeFromSplitBrain.
@Test
public void testClientEngineCleanup_AfterMergeFromSplitBrain() {
Config config = new Config();
config.setProperty(ClusterProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(ClusterProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
config.setProperty(ClusterProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "5");
config.setProperty(ClusterProperty.HEARTBEAT_INTERVAL_SECONDS.getName(), "1");
TestHazelcastFactory hazelcastFactory = new TestHazelcastFactory();
HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
assertSizeEventually(3, clientInstanceImpl.getConnectionManager().getActiveConnections());
blockCommunicationBetween(h1, h2);
blockCommunicationBetween(h1, h3);
// make sure that cluster is split as [ 1 ] , [ 2 , 3 ]
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(2, h2.getCluster().getMembers().size());
assertEquals(2, h3.getCluster().getMembers().size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(1, h1.getCluster().getMembers().size());
}
});
// open communication back for nodes to merge
unblockCommunicationBetween(h1, h2);
unblockCommunicationBetween(h1, h3);
// wait for cluster is merged back
assertClusterSizeEventually(3, h1, h2, h3);
// wait for client to connect back to all nodes
assertSizeEventually(3, clientInstanceImpl.getConnectionManager().getActiveConnections());
// verify endpoints are cleared
ClientEngineImpl clientEngineImpl1 = getClientEngineImpl(h1);
ClientEngineImpl clientEngineImpl2 = getClientEngineImpl(h2);
ClientEngineImpl clientEngineImpl3 = getClientEngineImpl(h3);
assertEquals(1, clientEngineImpl1.getClientEndpointCount());
assertEquals(1, clientEngineImpl2.getClientEndpointCount());
assertEquals(1, clientEngineImpl3.getClientEndpointCount());
hazelcastFactory.shutdownAll();
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientProtocolTest method testUnsupportedClientMessage.
@Test(expected = UnsupportedOperationException.class)
public void testUnsupportedClientMessage() {
hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
ClientMessage s = MapSizeCodec.encodeRequest("mapName");
int undefinedMessageType = -1;
s.setMessageType(undefinedMessageType);
ClientInvocation invocation = new ClientInvocation(clientImpl, s, "mapName");
try {
invocation.invoke().get();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientCacheClearTest method registerInvalidationListener.
private void registerInvalidationListener(EventHandler handler, String nameWithPrefix) {
ListenerMessageCodec listenerCodec = createInvalidationListenerCodec(nameWithPrefix);
HazelcastClientProxy hzClient = (HazelcastClientProxy) client;
final HazelcastClientInstanceImpl clientInstance = hzClient.client;
clientInstance.getListenerService().registerListener(listenerCodec, handler);
}
Aggregations