Search in sources :

Example 11 with SqlQuery

use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapLong.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSwapUnswapLong() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 2000;
    final int valCnt = 10000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, Long> c = cache(Integer.class, Long.class);
    assertEquals(0, g.cache(DEFAULT_CACHE_NAME).localSize());
    assertEquals(0, c.query(new SqlQuery(Long.class, "1 = 1")).getAll().size());
    Random rnd = new Random();
    for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
        c.put(i, (long) rnd.nextInt(valCnt));
        if (evictsEnabled() && rnd.nextBoolean())
            c.localEvict(Arrays.asList(i));
    }
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            Random rnd = new Random();
            while (!done.get()) {
                int key = rnd.nextInt(keyCnt);
                switch(rnd.nextInt(5)) {
                    case 0:
                        c.put(key, (long) rnd.nextInt(valCnt));
                        break;
                    case 1:
                        if (evictsEnabled())
                            c.localEvict(Arrays.asList(key));
                        break;
                    case 2:
                        c.remove(key);
                        break;
                    case 3:
                        c.get(key);
                        break;
                    case 4:
                        int from = rnd.nextInt(valCnt);
                        c.query(new SqlQuery(Long.class, "_val between ? and ?").setArgs(from, from + 250)).getAll();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    done.set(true);
    fut.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SqlQuery(org.apache.ignite.cache.query.SqlQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX)

Example 12 with SqlQuery

use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapString.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSwapUnswapString() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 2000;
    final int valCnt = 10000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, String> c = cache(Integer.class, String.class);
    assertEquals(0, g.cache(DEFAULT_CACHE_NAME).localSize());
    assertEquals(0, c.query(new SqlQuery(String.class, "1 = 1")).getAll().size());
    Random rnd = new Random();
    for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
        c.put(i, String.valueOf(rnd.nextInt(valCnt)));
        if (evictsEnabled() && rnd.nextBoolean())
            c.localEvict(Arrays.asList(i));
    }
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            Random rnd = new Random();
            while (!done.get()) {
                switch(rnd.nextInt(5)) {
                    case 0:
                        c.put(rnd.nextInt(keyCnt), String.valueOf(rnd.nextInt(valCnt)));
                        break;
                    case 1:
                        if (evictsEnabled())
                            c.localEvict(Arrays.asList(rnd.nextInt(keyCnt)));
                        break;
                    case 2:
                        c.remove(rnd.nextInt(keyCnt));
                        break;
                    case 3:
                        c.get(rnd.nextInt(keyCnt));
                        break;
                    case 4:
                        int from = rnd.nextInt(valCnt);
                        c.query(new SqlQuery(String.class, "_val between ? and ?").setArgs(String.valueOf(from), String.valueOf(from + 250))).getAll();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    done.set(true);
    fut.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SqlQuery(org.apache.ignite.cache.query.SqlQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX)

Example 13 with SqlQuery

use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSameQuery.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSameQuery() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 10;
    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);
        c.localEvict(Arrays.asList(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++;
                Collection<Cache.Entry<Integer, Integer>> entries = c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
                assert entries != null;
                assertEquals("Query results [entries=" + entries + ", aff=" + affinityNodes(entries, g) + ", 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);
    info("Finishing test...");
    done.set(true);
    fut.get();
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) 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 14 with SqlQuery

use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedNewQueries.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedNewQueries() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 10;
    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);
        c.localEvict(Arrays.asList(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++;
                Collection<Cache.Entry<Integer, Integer>> entries = c.query(new SqlQuery(Integer.class, "_val >= 0")).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 : SqlQuery(org.apache.ignite.cache.query.SqlQuery) 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 15 with SqlQuery

use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.

the class IgniteCacheQueryMultiThreadedSelfTest method _testMultiThreadedSwapUnswapLongString.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void _testMultiThreadedSwapUnswapLongString() throws Exception {
    fail("http://atlassian.gridgain.com/jira/browse/GG-11216");
    int threadCnt = 50;
    final int keyCnt = 2000;
    final int valCnt = 10000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, Object> c = cache(Integer.class, Object.class);
    assertEquals(0, g.cache(DEFAULT_CACHE_NAME).size());
    assertEquals(0, c.query(new SqlQuery(Object.class, "1 = 1")).getAll().size());
    Random rnd = new Random();
    for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
        c.put(i, rnd.nextBoolean() ? (long) rnd.nextInt(valCnt) : String.valueOf(rnd.nextInt(valCnt)));
        if (evictsEnabled() && rnd.nextBoolean())
            c.localEvict(Arrays.asList(i));
    }
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            Random rnd = new Random();
            while (!done.get()) {
                int key = rnd.nextInt(keyCnt);
                switch(rnd.nextInt(5)) {
                    case 0:
                        c.put(key, rnd.nextBoolean() ? (long) rnd.nextInt(valCnt) : String.valueOf(rnd.nextInt(valCnt)));
                        break;
                    case 1:
                        if (evictsEnabled())
                            c.localEvict(Arrays.asList(key));
                        break;
                    case 2:
                        c.remove(key);
                        break;
                    case 3:
                        c.get(key);
                        break;
                    case 4:
                        int from = rnd.nextInt(valCnt);
                        c.query(new SqlQuery(Object.class, "_val between ? and ?").setArgs(from, from + 250)).getAll();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    done.set(true);
    fut.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SqlQuery(org.apache.ignite.cache.query.SqlQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX)

Aggregations

SqlQuery (org.apache.ignite.cache.query.SqlQuery)57 Cache (javax.cache.Cache)20 IgniteCache (org.apache.ignite.IgniteCache)20 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)18 Ignite (org.apache.ignite.Ignite)17 List (java.util.List)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 CAX (org.apache.ignite.internal.util.typedef.CAX)9 ArrayList (java.util.ArrayList)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 BinaryObject (org.apache.ignite.binary.BinaryObject)7 CacheException (javax.cache.CacheException)6 Collection (java.util.Collection)4 Random (java.util.Random)4 QueryCursor (org.apache.ignite.cache.query.QueryCursor)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 UUID (java.util.UUID)3