Search in sources :

Example 6 with GridCacheQueryManager

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager in project ignite by apache.

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedScanQuery.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedScanQuery() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 500;
    final int logMod = 5000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, Integer> c = cache(Integer.class, Integer.class);
    for (int i = 0; i < keyCnt; i++) c.put(i, i);
    final AtomicInteger cnt = new AtomicInteger();
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            int iter = 0;
            while (!done.get() && !Thread.currentThread().isInterrupted()) {
                iter++;
                // Scan query.
                Collection<Cache.Entry<Integer, Integer>> entries = c.query(new ScanQuery<Integer, Integer>()).getAll();
                assert entries != null;
                assertEquals("Entries count is not as expected on iteration: " + iter, keyCnt, entries.size());
                if (cnt.incrementAndGet() % logMod == 0) {
                    GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) g).internalCache(c.getName()).context().queries();
                    assert qryMgr != null;
                    qryMgr.printMemoryStats();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    done.set(true);
    fut.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryManager(org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 7 with GridCacheQueryManager

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager in project ignite by apache.

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSqlFieldsQuery.

/**
     * SqlFieldsQuery paging mechanics stress test
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSqlFieldsQuery() throws Throwable {
    int threadCnt = 16;
    // set resultSet size bigger than page size
    final int keyCnt = 1100;
    final int logMod = 5000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, TestValue> c = cache(Integer.class, TestValue.class);
    for (int i = 0; i < keyCnt; i++) c.put(i, new TestValue(i));
    final AtomicInteger cnt = new AtomicInteger();
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            int iter = 0;
            while (!done.get() && !Thread.currentThread().isInterrupted()) {
                iter++;
                List<List<?>> entries = c.query(new SqlFieldsQuery("SELECT * from TestValue").setPageSize(100)).getAll();
                assert entries != null;
                assertEquals("Entries count is not as expected on iteration: " + iter, keyCnt, entries.size());
                if (cnt.incrementAndGet() % logMod == 0) {
                    GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) g).internalCache(DEFAULT_CACHE_NAME).context().queries();
                    assert qryMgr != null;
                    qryMgr.printMemoryStats();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    done.set(true);
    fut.get();
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryManager(org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager) Ignite(org.apache.ignite.Ignite) List(java.util.List) CAX(org.apache.ignite.internal.util.typedef.CAX)

Aggregations

GridCacheQueryManager (org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Cache (javax.cache.Cache)4 Ignite (org.apache.ignite.Ignite)4 IgniteCache (org.apache.ignite.IgniteCache)4 CAX (org.apache.ignite.internal.util.typedef.CAX)4 Collection (java.util.Collection)3 Map (java.util.Map)2 SqlQuery (org.apache.ignite.cache.query.SqlQuery)2 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IgniteException (org.apache.ignite.IgniteException)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 CacheStore (org.apache.ignite.cache.store.CacheStore)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1