Search in sources :

Example 21 with HazelcastClientInstanceImpl

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

the class ListenerTests method testSmartListenerRegister_whenNodeJoined.

@Test
public void testSmartListenerRegister_whenNodeJoined() {
    int nodeCount = 5;
    for (int i = 0; i < nodeCount - 1; i++) {
        factory.newHazelcastInstance();
    }
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Object, Object> map = client.getMap("test");
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            factory.newHazelcastInstance();
        }
    }, 500, TimeUnit.MILLISECONDS);
    EntryAdapter listener = new EntryAdapter();
    LinkedList<UUID> registrationIds = new LinkedList<UUID>();
    HazelcastClientInstanceImpl clientInstance = getHazelcastClientInstanceImpl(client);
    while (clientInstance.getConnectionManager().getActiveConnections().size() < nodeCount) {
        registrationIds.add(map.addEntryListener(listener, false));
    }
    for (UUID registrationId : registrationIds) {
        assertTrue(map.removeEntryListener(registrationId));
    }
    executorService.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryAdapter(com.hazelcast.core.EntryAdapter) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) UUID(java.util.UUID) LinkedList(java.util.LinkedList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with HazelcastClientInstanceImpl

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

the class BackupListenerLeakTest method testBackupListenerIsNotRemoved_afterClientRestart.

@Test
public void testBackupListenerIsNotRemoved_afterClientRestart() throws InterruptedException {
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance hazelcast = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    TcpClientConnectionManager connectionManager = (TcpClientConnectionManager) clientImpl.getConnectionManager();
    connectionManager.reset();
    Map<UUID, Consumer<Long>> backupListeners = ((ClientEngineImpl) getNode(hazelcast).clientEngine).getBackupListeners();
    assertTrueEventually(() -> assertEquals(1, backupListeners.size()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) Consumer(java.util.function.Consumer) TcpClientConnectionManager(com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.ClientTestUtil.getHazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with HazelcastClientInstanceImpl

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

the class ClientInvocationTest method invokeOnMember_redirectDisallowedToRandom_whenMemberIsNotInMemberList.

@Test(expected = OperationTimeoutException.class)
public void invokeOnMember_redirectDisallowedToRandom_whenMemberIsNotInMemberList() {
    hazelcastFactory.newHazelcastInstance();
    UUID unavailableTarget = UUID.randomUUID();
    ClientConfig config = new ClientConfig();
    config.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "1");
    HazelcastClientInstanceImpl client = getHazelcastClientInstanceImpl(hazelcastFactory.newHazelcastClient(config));
    ClientMessage request = MapSizeCodec.encodeRequest("test");
    ClientInvocation invocation = new ClientInvocation(client, request, "map", unavailableTarget);
    invocation.disallowRetryOnRandom();
    invocation.invoke().joinInternal();
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with HazelcastClientInstanceImpl

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

the class ClientInvocationTest method invokeOnPartitionOwner_redirectDisallowedToRandom_WhenPartitionOwnerIsnull.

@Test(expected = OperationTimeoutException.class)
public void invokeOnPartitionOwner_redirectDisallowedToRandom_WhenPartitionOwnerIsnull() {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig config = new ClientConfig();
    config.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "1");
    HazelcastClientInstanceImpl client = getHazelcastClientInstanceImpl(hazelcastFactory.newHazelcastClient(config));
    ClientMessage request = MapSizeCodec.encodeRequest("test");
    int ownerlessPartition = 4000;
    ClientInvocation invocation = new ClientInvocation(client, request, "map", ownerlessPartition);
    invocation.disallowRetryOnRandom();
    invocation.invoke().joinInternal();
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with HazelcastClientInstanceImpl

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

the class ClientResponseHandlerSupplierTest method getResponseHandler.

private Consumer<ClientMessage> getResponseHandler(int threadCount, boolean dynamic) {
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(new ClientConfig().setProperty(RESPONSE_THREAD_COUNT.getName(), "" + threadCount).setProperty(RESPONSE_THREAD_DYNAMIC.getName(), "" + dynamic));
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    ClientInvocationServiceImpl invocationService = (ClientInvocationServiceImpl) clientInstanceImpl.getInvocationService();
    ClientResponseHandlerSupplier responseHandlerSupplier = new ClientResponseHandlerSupplier(invocationService, clientInstanceImpl.getConcurrencyDetection());
    return responseHandlerSupplier.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig)

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