Search in sources :

Example 31 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 32 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)

Example 33 with HazelcastClientInstanceImpl

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

the class ProxyManagerTest method testNextAddressToSendCreateRequestOnMultipleDataMembers.

@Test
public void testNextAddressToSendCreateRequestOnMultipleDataMembers() {
    final List<HazelcastInstance> instances = createNodes(3, 3);
    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(3, addresses.size());
    for (HazelcastInstance lite : instances.subList(3, 6)) {
        assertContains(addresses, getAddress(lite));
    }
}
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 34 with HazelcastClientInstanceImpl

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

the class ProxyManagerTest method testNextAddressToSendCreateRequestOnSingleDataMember.

@Test
public void testNextAddressToSendCreateRequestOnSingleDataMember() {
    final List<HazelcastInstance> instances = createNodes(3, 1);
    final Address dataInstanceAddress = getAddress(instances.get(3));
    final HazelcastInstance client = factory.newHazelcastClient();
    final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final ProxyManager proxyManager = clientInstanceImpl.getProxyManager();
    for (int i = 0; i < instances.size(); i++) {
        assertEquals(dataInstanceAddress, proxyManager.findNextAddressToSendCreateRequest());
    }
}
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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 35 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)

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