Search in sources :

Example 46 with HazelcastClientInstanceImpl

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

the class ClientInvocationTest method invokeOnPartitionOwnerRedirectsToRandom_WhenPartitionOwnerIsnull.

@Test
public void invokeOnPartitionOwnerRedirectsToRandom_WhenPartitionOwnerIsnull() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    HazelcastClientInstanceImpl client = getHazelcastClientInstanceImpl(hazelcastFactory.newHazelcastClient());
    ClientMessage request = MapSizeCodec.encodeRequest("test");
    int ownerlessPartition = 4000;
    ClientInvocation invocation = new ClientInvocation(client, request, "map", ownerlessPartition);
    assertEquals(0, MapSizeCodec.decodeResponse(invocation.invoke().get()));
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with HazelcastClientInstanceImpl

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

the class ListenerLeakTest method getClientEventRegistrations.

private Collection<ClientConnectionRegistration> getClientEventRegistrations(HazelcastInstance client, UUID id) {
    HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ClientListenerServiceImpl listenerService = (ClientListenerServiceImpl) clientImpl.getListenerService();
    return listenerService.getActiveRegistrations(id).values();
}
Also used : ClientListenerServiceImpl(com.hazelcast.client.impl.spi.impl.listener.ClientListenerServiceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)

Example 48 with HazelcastClientInstanceImpl

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

the class ClientExecutorServiceTest method testExecutionCallback_whenExecutionRejected.

@Ignore("Behaviour needs a better test, due to switching from user executor to ForkJoinPool.commonPool")
@Test
public void testExecutionCallback_whenExecutionRejected() {
    final AtomicReference<Throwable> exceptionThrown = new AtomicReference<>();
    final CountDownLatch waitForShutdown = new CountDownLatch(1);
    final CountDownLatch didShutdown = new CountDownLatch(1);
    final HazelcastClientInstanceImpl hzClient = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ExecutionRejectedRunnable.waitForShutdown = waitForShutdown;
    ExecutionRejectedRunnable.didShutdown = didShutdown;
    IExecutorService executorService = hzClient.getExecutorService("executor");
    Thread t = new Thread(() -> {
        try {
            waitForShutdown.await(30, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            ignore(e);
        }
        ForkJoinPool.commonPool().shutdown();
        didShutdown.countDown();
    });
    t.start();
    executorService.submit(new ExecutionRejectedRunnable(), new ExecutionCallback<Object>() {

        @Override
        public void onResponse(Object response) {
        }

        @Override
        public void onFailure(Throwable t) {
            exceptionThrown.set(t);
        }
    });
    // assert a RejectedExecutionException is thrown from already shutdown user executor
    // it is not wrapped in a HazelcastClientNotActiveException because the client is still running
    assertTrueEventually(() -> assertTrue(exceptionThrown.get() instanceof RejectedExecutionException));
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) Ignore(org.junit.Ignore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with HazelcastClientInstanceImpl

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

the class AbstractListenersOnReconnectTest method testListenersTemporaryNetworkBlockage.

private void testListenersTemporaryNetworkBlockage(boolean isSmart, int clusterSize) {
    factory.newInstances(null, clusterSize);
    ClientConfig clientConfig = createClientConfig(isSmart);
    client = factory.newHazelcastClient(clientConfig);
    setupListener();
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    long timeout = clientInstanceImpl.getProperties().getMillis(HEARTBEAT_TIMEOUT);
    long waitTime = timeout / 2;
    for (HazelcastInstance instance : factory.getAllHazelcastInstances()) {
        blockMessagesFromInstance(instance, client);
    }
    sleepMillis((int) waitTime);
    for (HazelcastInstance instance : factory.getAllHazelcastInstances()) {
        unblockMessagesFromInstance(instance, client);
    }
    validateRegistrationsAndListenerFunctionality();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 50 with HazelcastClientInstanceImpl

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

the class AbstractListenersOnReconnectTest method getClientEventRegistrations.

private Map<Connection, ClientConnectionRegistration> getClientEventRegistrations(HazelcastInstance client, UUID id) {
    HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ClientListenerServiceImpl listenerService = (ClientListenerServiceImpl) clientImpl.getListenerService();
    return listenerService.getActiveRegistrations(id);
}
Also used : ClientListenerServiceImpl(com.hazelcast.client.impl.spi.impl.listener.ClientListenerServiceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)

Aggregations

HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)59 Test (org.junit.Test)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)19 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)15 UUID (java.util.UUID)14 ClientConfig (com.hazelcast.client.config.ClientConfig)11 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)9 HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)7 ClientEngineImpl (com.hazelcast.client.impl.ClientEngineImpl)6 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 TcpClientConnectionManager (com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager)4 Address (com.hazelcast.cluster.Address)4 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)4 Accessors.getClientEngineImpl (com.hazelcast.test.Accessors.getClientEngineImpl)4 LoadBalancer (com.hazelcast.client.LoadBalancer)3 MCClusterMetadata (com.hazelcast.client.impl.management.MCClusterMetadata)3