Search in sources :

Example 26 with HazelcastClientInstanceImpl

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleEvent(com.hazelcast.core.LifecycleEvent) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 27 with HazelcastClientInstanceImpl

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);
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

Example 28 with HazelcastClientInstanceImpl

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);
}
Also used : TestEventCollectingMapPartitionLostListener(com.hazelcast.map.TestEventCollectingMapPartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) MapService(com.hazelcast.map.impl.MapService) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with HazelcastClientInstanceImpl

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());
        }
    });
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) EntryAdapter(com.hazelcast.core.EntryAdapter) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) AssertTask(com.hazelcast.test.AssertTask) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager) UnknownHostException(java.net.UnknownHostException) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with HazelcastClientInstanceImpl

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);
    }
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) CancellationException(java.util.concurrent.CancellationException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)40 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 Address (com.hazelcast.nio.Address)14 Test (org.junit.Test)12 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)10 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)7 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)7 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)6 Connection (com.hazelcast.nio.Connection)6 ClientConfig (com.hazelcast.client.config.ClientConfig)5 ClientTestUtil.getHazelcastClientInstanceImpl (com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl)5 LifecycleEvent (com.hazelcast.core.LifecycleEvent)5 LifecycleListener (com.hazelcast.core.LifecycleListener)5 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)4 AssertTask (com.hazelcast.test.AssertTask)4 CacheException (javax.cache.CacheException)4