Search in sources :

Example 16 with ClientEngineImpl

use of com.hazelcast.client.impl.ClientEngineImpl 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 17 with ClientEngineImpl

use of com.hazelcast.client.impl.ClientEngineImpl 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 18 with ClientEngineImpl

use of com.hazelcast.client.impl.ClientEngineImpl 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)

Example 19 with ClientEngineImpl

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

the class ClientStatisticsTest method testStatisticsTwoClients.

@Test
public void testStatisticsTwoClients() {
    HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
    final HazelcastClientInstanceImpl client1 = createHazelcastClient();
    final HazelcastClientInstanceImpl client2 = createHazelcastClient();
    final ClientEngineImpl clientEngine = getClientEngineImpl(hazelcastInstance);
    assertTrueEventually(() -> {
        Map<UUID, ClientStatistics> clientStatistics = clientEngine.getClientStatistics();
        assertNotNull(clientStatistics);
        assertEquals(2, clientStatistics.size());
        List<UUID> expectedUUIDs = new ArrayList<>(2);
        expectedUUIDs.add(client1.getClientClusterService().getLocalClient().getUuid());
        expectedUUIDs.add(client2.getClientClusterService().getLocalClient().getUuid());
        for (Map.Entry<UUID, ClientStatistics> clientEntry : clientStatistics.entrySet()) {
            assertTrue(expectedUUIDs.contains(clientEntry.getKey()));
            String clientAttributes = clientEntry.getValue().clientAttributes();
            assertNotNull(clientAttributes);
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) Accessors.getClientEngineImpl(com.hazelcast.test.Accessors.getClientEngineImpl) ClientStatistics(com.hazelcast.client.impl.statistics.ClientStatistics) ArrayList(java.util.ArrayList) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with ClientEngineImpl

use of com.hazelcast.client.impl.ClientEngineImpl in project hazelcast-jet by hazelcast.

the class JetService method init.

// ManagedService
@Override
public void init(NodeEngine engine, Properties properties) {
    if (config == null) {
        throw new IllegalStateException("JetConfig is not initialized");
    }
    jetInstance = new JetInstanceImpl((HazelcastInstanceImpl) engine.getHazelcastInstance(), config);
    taskletExecutionService = new TaskletExecutionService(nodeEngine.getHazelcastInstance(), config.getInstanceConfig().getCooperativeThreadCount());
    snapshotRepository = new SnapshotRepository(jetInstance);
    jobRepository = new JobRepository(jetInstance, snapshotRepository);
    jobExecutionService = new JobExecutionService(nodeEngine, taskletExecutionService);
    jobCoordinationService = new JobCoordinationService(nodeEngine, config, jobRepository, jobExecutionService, snapshotRepository);
    networking = new Networking(engine, jobExecutionService, config.getInstanceConfig().getFlowControlPeriodMs());
    ClientEngineImpl clientEngine = engine.getService(ClientEngineImpl.SERVICE_NAME);
    ExceptionUtil.registerJetExceptions(clientEngine.getClientExceptionFactory());
    jobCoordinationService.init();
    JetBuildInfo jetBuildInfo = BuildInfoProvider.getBuildInfo().getJetBuildInfo();
    logger.info(String.format("Starting Jet %s (%s - %s)", jetBuildInfo.getVersion(), jetBuildInfo.getBuild(), jetBuildInfo.getRevision()));
    logger.info("Setting number of cooperative threads and default parallelism to " + config.getInstanceConfig().getCooperativeThreadCount());
    logger.info('\n' + "\to   o   o   o---o o---o o     o---o   o   o---o o-o-o        o o---o o-o-o\n" + "\t|   |  / \\     /  |     |     |      / \\  |       |          | |       |  \n" + "\to---o o---o   o   o-o   |     o     o---o o---o   |          | o-o     |  \n" + "\t|   | |   |  /    |     |     |     |   |     |   |      \\   | |       |  \n" + "\to   o o   o o---o o---o o---o o---o o   o o---o   o       o--o o---o   o   ");
    logger.info("Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.");
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) JetBuildInfo(com.hazelcast.instance.JetBuildInfo) TaskletExecutionService(com.hazelcast.jet.impl.execution.TaskletExecutionService)

Aggregations

ClientEngineImpl (com.hazelcast.client.impl.ClientEngineImpl)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 Test (org.junit.Test)16 QuickTest (com.hazelcast.test.annotation.QuickTest)15 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 Accessors.getClientEngineImpl (com.hazelcast.test.Accessors.getClientEngineImpl)8 ClientConfig (com.hazelcast.client.config.ClientConfig)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)6 AssertTask (com.hazelcast.test.AssertTask)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 UUID (java.util.UUID)4 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 ClientEndpoint (com.hazelcast.client.impl.ClientEndpoint)2 ClientStatistics (com.hazelcast.client.impl.statistics.ClientStatistics)2 Consumer (java.util.function.Consumer)2 AuthenticationException (com.hazelcast.client.AuthenticationException)1 ClientEndpointManagerImpl (com.hazelcast.client.impl.ClientEndpointManagerImpl)1 ClientEndpointStatisticsManagerImpl (com.hazelcast.client.impl.ClientEndpointStatisticsManagerImpl)1 ClientPrincipal (com.hazelcast.client.impl.client.ClientPrincipal)1 ClientTestUtil.getHazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.ClientTestUtil.getHazelcastClientInstanceImpl)1