Search in sources :

Example 71 with SqlQuery

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

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapObject.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSwapUnswapObject() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 4000;
    final int valCnt = 10000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, TestValue> c = cache(Integer.class, TestValue.class);
    assertEquals(0, g.cache(DEFAULT_CACHE_NAME).localSize());
    assertEquals(0, c.query(new SqlQuery(TestValue.class, "1 = 1")).getAll().size());
    Random rnd = new Random();
    for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
        c.put(i, new TestValue(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, new TestValue(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(TestValue.class, "TestValue.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)71 Cache (javax.cache.Cache)21 IgniteCache (org.apache.ignite.IgniteCache)21 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)20 Ignite (org.apache.ignite.Ignite)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ArrayList (java.util.ArrayList)13 List (java.util.List)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 CAX (org.apache.ignite.internal.util.typedef.CAX)9 BinaryObject (org.apache.ignite.binary.BinaryObject)8 CacheException (javax.cache.CacheException)7 Entry (javax.cache.Cache.Entry)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 IOException (java.io.IOException)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 Random (java.util.Random)4