Search in sources :

Example 26 with HazelcastClientInstanceImpl

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

the class MCTrustedInterfacesTest method testGetSystemPropertiesMessageTask_passing.

@Test
public void testGetSystemPropertiesMessageTask_passing() throws Exception {
    HazelcastInstance client = factory.newHazelcastClient(new ClientConfig(), "222.222.222.222");
    HazelcastClientInstanceImpl clientImpl = ((HazelcastClientProxy) client).client;
    ClientInvocation invocation = new ClientInvocation(clientImpl, MCGetSystemPropertiesCodec.encodeRequest(), null);
    ClientDelegatingFuture<List<Map.Entry<String, String>>> future = new ClientDelegatingFuture<>(invocation.invoke(), clientImpl.getSerializationService(), MCGetSystemPropertiesCodec::decodeResponse);
    assertFalse(future.get(ASSERT_TRUE_EVENTUALLY_TIMEOUT, SECONDS).isEmpty());
}
Also used : MCGetSystemPropertiesCodec(com.hazelcast.client.impl.protocol.codec.MCGetSystemPropertiesCodec) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) List(java.util.List) ArrayList(java.util.ArrayList) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with HazelcastClientInstanceImpl

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

the class TestHazelcastFactory method newHazelcastClient.

public HazelcastInstance newHazelcastClient(ClientConfig config, String sourceIp) {
    if (!mockNetwork) {
        HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
        registerJvmNameAndPidMetric(((HazelcastClientProxy) client).client);
        return client;
    }
    if (config == null) {
        config = new XmlClientConfigBuilder().build();
    }
    Thread currentThread = Thread.currentThread();
    ClassLoader tccl = currentThread.getContextClassLoader();
    try {
        if (tccl == ClassLoader.getSystemClassLoader()) {
            currentThread.setContextClassLoader(HazelcastClient.class.getClassLoader());
        }
        HazelcastClientInstanceImpl client = new HazelcastClientInstanceImpl(getInstanceName(config), config, null, clientRegistry.createClientServiceFactory(sourceIp), createAddressProvider(config));
        registerJvmNameAndPidMetric(client);
        client.start();
        if (clients.putIfAbsent(client.getName(), client) != null) {
            throw new InvalidConfigurationException("HazelcastClientInstance with name '" + client.getName() + "' already exists!");
        }
        OutOfMemoryErrorDispatcher.registerClient(client);
        return new HazelcastClientProxy(client);
    } finally {
        currentThread.setContextClassLoader(tccl);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) HazelcastClient(com.hazelcast.client.HazelcastClient) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 28 with HazelcastClientInstanceImpl

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

the class ClientStatisticsTest method testStatisticsCollectionNonDefaultPeriod.

@Test
public void testStatisticsCollectionNonDefaultPeriod() {
    HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
    final HazelcastClientInstanceImpl client = createHazelcastClient();
    final ClientEngineImpl clientEngine = getClientEngineImpl(hazelcastInstance);
    long clientConnectionTime = System.currentTimeMillis();
    // wait enough time for statistics collection
    waitForFirstStatisticsCollection(client, clientEngine);
    Map<String, String> stats = getStats(client, clientEngine);
    String connStat = stats.get("clusterConnectionTimestamp");
    assertNotNull(format("clusterConnectionTimestamp should not be null (%s)", stats), connStat);
    Long connectionTimeStat = Long.valueOf(connStat);
    assertNotNull(format("connectionTimeStat should not be null (%s)", stats), connStat);
    TcpClientConnection aConnection = (TcpClientConnection) client.getConnectionManager().getActiveConnections().iterator().next();
    String expectedClientAddress = aConnection.getLocalSocketAddress().getAddress().getHostAddress();
    assertEquals(expectedClientAddress, stats.get("clientAddress"));
    assertEquals(BuildInfoProvider.getBuildInfo().getVersion(), stats.get("clientVersion"));
    assertEquals(client.getName(), stats.get("clientName"));
    // time measured by us after client connection should be greater than the connection time reported by the statistics
    assertTrue(format("connectionTimeStat was %d, clientConnectionTime was %d (%s)", connectionTimeStat, clientConnectionTime, stats), clientConnectionTime >= connectionTimeStat);
    String mapHits = stats.get(MAP_HITS_KEY);
    assertNull(format("%s should be null (%s)", MAP_HITS_KEY, stats), mapHits);
    String cacheHits = stats.get(CACHE_HITS_KEY);
    assertNull(format("%s should be null (%s)", CACHE_HITS_KEY, stats), cacheHits);
    String lastStatisticsCollectionTimeString = stats.get("lastStatisticsCollectionTime");
    final long lastCollectionTime = Long.parseLong(lastStatisticsCollectionTimeString);
    // this creates empty map statistics
    client.getMap(MAP_NAME);
    // wait enough time for statistics collection
    waitForNextStatsCollection(client, clientEngine, lastStatisticsCollectionTimeString);
    assertTrueEventually(() -> {
        Map<String, String> stats12 = getStats(client, clientEngine);
        String mapHits12 = stats12.get(MAP_HITS_KEY);
        assertNotNull(format("%s should not be null (%s)", MAP_HITS_KEY, stats12), mapHits12);
        assertEquals(format("Expected 0 map hits (%s)", stats12), "0", mapHits12);
        String cacheHits12 = stats12.get(CACHE_HITS_KEY);
        assertNull(format("%s should be null (%s)", CACHE_HITS_KEY, stats12), cacheHits12);
        // verify that collection is periodic
        verifyThatCollectionIsPeriodic(stats12, lastCollectionTime);
    });
    // produce map and cache stat
    produceSomeStats(hazelcastInstance, client);
    assertTrueEventually(() -> {
        Map<String, String> stats1 = getStats(client, clientEngine);
        String mapHits1 = stats1.get(MAP_HITS_KEY);
        assertNotNull(format("%s should not be null (%s)", MAP_HITS_KEY, stats1), mapHits1);
        assertEquals(format("Expected 1 map hits (%s)", stats1), "1", mapHits1);
        String cacheHits1 = stats1.get(CACHE_HITS_KEY);
        assertNotNull(format("%s should not be null (%s)", CACHE_HITS_KEY, stats1), cacheHits1);
        assertEquals(format("Expected 1 cache hits (%s)", stats1), "1", cacheHits1);
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) Accessors.getClientEngineImpl(com.hazelcast.test.Accessors.getClientEngineImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) TcpClientConnection(com.hazelcast.client.impl.connection.tcp.TcpClientConnection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with HazelcastClientInstanceImpl

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

the class ClientStatisticsTest method testStatisticsClusterReconnect.

@Test
public void testStatisticsClusterReconnect() {
    HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
    HazelcastClientInstanceImpl client = createHazelcastClient();
    ReconnectListener reconnectListener = new ReconnectListener();
    client.getLifecycleService().addLifecycleListener(reconnectListener);
    hazelcastInstance.getLifecycleService().terminate();
    hazelcastInstance = hazelcastFactory.newHazelcastInstance();
    ClientEngineImpl clientEngine = getClientEngineImpl(hazelcastInstance);
    assertOpenEventually(reconnectListener.reconnectedLatch);
    // wait enough time for statistics collection
    waitForFirstStatisticsCollection(client, clientEngine);
    getStats(client, clientEngine);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) Accessors.getClientEngineImpl(com.hazelcast.test.Accessors.getClientEngineImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 30 with HazelcastClientInstanceImpl

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

the class ClientStatisticsTest method testStatisticsPeriod.

@Test
public void testStatisticsPeriod() {
    HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
    HazelcastClientInstanceImpl client = createHazelcastClient();
    ClientEngineImpl clientEngine = getClientEngineImpl(hazelcastInstance);
    // wait enough time for statistics collection
    waitForFirstStatisticsCollection(client, clientEngine);
    Map<String, String> initialStats = getStats(client, clientEngine);
    // produce map and cache stat
    produceSomeStats(hazelcastInstance, client);
    // wait enough time for statistics collection
    waitForNextStatsCollection(client, clientEngine, initialStats.get("lastStatisticsCollectionTime"));
    assertNotEquals("initial statistics should not be the same as current stats", initialStats, getStats(client, clientEngine));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) Accessors.getClientEngineImpl(com.hazelcast.test.Accessors.getClientEngineImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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