Search in sources :

Example 1 with THIN_CLIENT

use of org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.THIN_CLIENT in project ignite by apache.

the class PerformanceStatisticsQueryTest method runQueryAndCheck.

/**
 * Runs query and checks statistics.
 */
private void runQueryAndCheck(GridCacheQueryType expType, Query<?> qry, String expText, boolean hasLogicalReads, boolean hasPhysicalReads) throws Exception {
    long startTime = U.currentTimeMillis();
    cleanPerformanceStatisticsDir();
    startCollectStatistics();
    Collection<UUID> expNodeIds = new ArrayList<>();
    if (clientType == SERVER) {
        srv.cache(DEFAULT_CACHE_NAME).query(qry).getAll();
        expNodeIds.add(srv.localNode().id());
    } else if (clientType == CLIENT) {
        client.cache(DEFAULT_CACHE_NAME).query(qry).getAll();
        expNodeIds.add(client.localNode().id());
    } else if (clientType == THIN_CLIENT) {
        thinClient.cache(DEFAULT_CACHE_NAME).query(qry).getAll();
        expNodeIds.addAll(F.nodeIds(client.cluster().forServers().nodes()));
    }
    Set<UUID> readsNodes = new HashSet<>();
    if (hasLogicalReads)
        srv.cluster().forServers().nodes().forEach(node -> readsNodes.add(node.id()));
    AtomicInteger queryCnt = new AtomicInteger();
    AtomicInteger readsCnt = new AtomicInteger();
    HashSet<Long> qryIds = new HashSet<>();
    stopCollectStatisticsAndRead(new TestHandler() {

        @Override
        public void query(UUID nodeId, GridCacheQueryType type, String text, long id, long queryStartTime, long duration, boolean success) {
            queryCnt.incrementAndGet();
            qryIds.add(id);
            assertTrue(expNodeIds.contains(nodeId));
            assertEquals(expType, type);
            assertEquals(expText, text);
            assertTrue(queryStartTime >= startTime);
            assertTrue(duration >= 0);
            assertTrue(success);
        }

        @Override
        public void queryReads(UUID nodeId, GridCacheQueryType type, UUID queryNodeId, long id, long logicalReads, long physicalReads) {
            readsCnt.incrementAndGet();
            qryIds.add(id);
            readsNodes.remove(nodeId);
            assertTrue(expNodeIds.contains(queryNodeId));
            assertEquals(expType, type);
            assertTrue(logicalReads > 0);
            assertTrue(hasPhysicalReads ? physicalReads > 0 : physicalReads == 0);
        }
    });
    assertEquals(1, queryCnt.get());
    assertTrue("Query reads expected on nodes: " + readsNodes, readsNodes.isEmpty());
    assertEquals(1, qryIds.size());
}
Also used : CLIENT(org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.CLIENT) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Assume.assumeFalse(org.junit.Assume.assumeFalse) RunWith(org.junit.runner.RunWith) U(org.apache.ignite.internal.util.typedef.internal.U) SERVER(org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.SERVER) IgniteEx(org.apache.ignite.internal.IgniteEx) THIN_CLIENT(org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.THIN_CLIENT) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Config(org.apache.ignite.client.Config) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteClient(org.apache.ignite.client.IgniteClient) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedList(java.util.LinkedList) Parameterized(org.junit.runners.Parameterized) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) Query(org.apache.ignite.cache.query.Query) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) SCAN(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SCAN) IgniteCache(org.apache.ignite.IgniteCache) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) GridCacheQueryType(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) DFLT_SCHEMA(org.apache.ignite.internal.processors.query.QueryUtils.DFLT_SCHEMA) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SQL_FIELDS(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SQL_FIELDS) Collections(java.util.Collections) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) ScanQuery(org.apache.ignite.cache.query.ScanQuery) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ArrayList(java.util.ArrayList) GridCacheQueryType(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteCache (org.apache.ignite.IgniteCache)1 Ignition (org.apache.ignite.Ignition)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)1 Query (org.apache.ignite.cache.query.Query)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 Config (org.apache.ignite.client.Config)1 IgniteClient (org.apache.ignite.client.IgniteClient)1 ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)1 INACTIVE (org.apache.ignite.cluster.ClusterState.INACTIVE)1