Search in sources :

Example 16 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class AbstractListenersOnReconnectTest method testListenersHeartbeatTimeoutToOwner.

private void testListenersHeartbeatTimeoutToOwner() {
    setupListener();
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    HazelcastInstance server = getOwnerServer(factory, clientInstanceImpl);
    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();
            }
        }
    });
    blockMessagesFromInstance(server, client);
    assertOpenEventually(disconnectedLatch);
    unblockMessagesFromInstance(server, client);
    assertOpenEventually(connectedLatch);
    validateRegistrationsAndListenerFunctionality();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 17 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientPartitionLostListenerTest method test_partitionLostListener_invoked_fromOtherNode.

@Test
public void test_partitionLostListener_invoked_fromOtherNode() {
    final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setSmartRouting(false);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    warmUpPartitions(instance1, instance2, client);
    final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final Address clientOwnerAddress = clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress();
    final HazelcastInstance other = getAddress(instance1).equals(clientOwnerAddress) ? instance2 : instance1;
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    client.getPartitionService().addPartitionLostListener(listener);
    assertRegistrationsSizeEventually(instance1, 1);
    assertRegistrationsSizeEventually(instance2, 1);
    final InternalPartitionServiceImpl partitionService = getNode(other).getNodeEngine().getService(SERVICE_NAME);
    final int partitionId = 5;
    partitionService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
    assertPartitionLostEventEventually(listener, partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ProxyManagerTest method testNextAddressToSendCreateRequestOnMultipleLiteMembers.

@Test
public void testNextAddressToSendCreateRequestOnMultipleLiteMembers() {
    final List<HazelcastInstance> instances = createNodes(3, 0);
    final HazelcastInstance client = factory.newHazelcastClient();
    final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    Set<Address> addresses = new HashSet<Address>();
    final ProxyManager proxyManager = clientInstanceImpl.getProxyManager();
    for (int i = 0; i < instances.size() * 100; i++) {
        addresses.add(proxyManager.findNextAddressToSendCreateRequest());
    }
    assertEquals(1, addresses.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) ProxyManager(com.hazelcast.client.spi.ProxyManager) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientTestSupport method unblockMessagesToInstance.

/**
     * Unblocks outgoing messages from client to given instance
     */
protected void unblockMessagesToInstance(HazelcastInstance instance, HazelcastInstance client) {
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    Address address = instance.getCluster().getLocalMember().getAddress();
    ((TestClientRegistry.MockClientConnectionManager) connectionManager).unblockTo(address);
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

Example 20 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientTestSupport method unblockMessagesFromInstance.

/**
     * Unblocks incoming messages to client from given instance
     */
protected void unblockMessagesFromInstance(HazelcastInstance instance, HazelcastInstance client) {
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    Address address = instance.getCluster().getLocalMember().getAddress();
    ((TestClientRegistry.MockClientConnectionManager) connectionManager).unblockFrom(address);
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

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