Search in sources :

Example 31 with Cache

use of javax.cache.Cache 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 32 with Cache

use of javax.cache.Cache in project ignite by apache.

the class IgniteDbPutGetAbstractTest method checkScan.

/**
     * @param total Expected total entries.
     */
private void checkScan(int total) {
    for (int i = 0; i < gridCount(); i++) {
        Set<DbKey> allKeys = new HashSet<>();
        Ignite ignite0 = grid(i);
        IgniteCache<DbKey, DbValue> cache0 = ignite0.cache("non-primitive");
        ScanQuery<DbKey, DbValue> qry = new ScanQuery<>();
        QueryCursor<Cache.Entry<DbKey, DbValue>> cur = cache0.query(qry);
        for (Cache.Entry<DbKey, DbValue> e : cur) {
            allKeys.add(e.getKey());
            assertEquals(e.getKey().val, e.getValue().iVal);
        }
        assertEquals(total, allKeys.size());
    }
}
Also used : ScanQuery(org.apache.ignite.cache.query.ScanQuery) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 33 with Cache

use of javax.cache.Cache in project ignite by apache.

the class IgniteDbPutGetAbstractTest method testPutGetLarge.

/**
     * @throws Exception if failed.
     */
public void testPutGetLarge() throws Exception {
    IgniteEx ig = grid(0);
    IgniteCache<Integer, byte[]> cache = ig.cache(DEFAULT_CACHE_NAME);
    final byte[] val = new byte[2048];
    ThreadLocalRandom.current().nextBytes(val);
    cache.put(0, val);
    Assert.assertArrayEquals(val, cache.get(0));
    final IgniteCache<Integer, LargeDbValue> cache1 = ig.cache("large");
    final LargeDbValue large = new LargeDbValue("str1", "str2", randomInts(1024));
    cache1.put(1, large);
    assertEquals(large, cache1.get(1));
    if (indexingEnabled()) {
        final List<Cache.Entry<Integer, LargeDbValue>> all = cache1.query(new SqlQuery<Integer, LargeDbValue>(LargeDbValue.class, "str1='str1'")).getAll();
        assertEquals(1, all.size());
        final Cache.Entry<Integer, LargeDbValue> entry = all.get(0);
        assertEquals(1, entry.getKey().intValue());
        assertEquals(large, entry.getValue());
    }
    cache.remove(0);
    cache1.remove(1);
    assertNull(cache.get(0));
    assertNull(cache1.get(1));
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 34 with Cache

use of javax.cache.Cache in project ignite by apache.

the class IgniteDbPutGetAbstractTest method checkLocalEntries.

/**
     * @param total Expected total entries.
     * @param cntrs Expected per-node entries count.
     */
private void checkLocalEntries(int total, Map<UUID, Integer> cntrs) {
    Set<DbKey> allKeys = new HashSet<>();
    for (int i = 0; i < gridCount(); i++) {
        Ignite ignite0 = grid(i);
        IgniteCache<DbKey, DbValue> cache0 = ignite0.cache("non-primitive");
        int cnt = 0;
        for (Cache.Entry<DbKey, DbValue> e : cache0.localEntries()) {
            cnt++;
            allKeys.add(e.getKey());
            assertEquals(e.getKey().val, e.getValue().iVal);
        }
        assertEquals(cntrs.get(ignite0.cluster().localNode().id()), (Integer) cnt);
    }
    assertEquals(total, allKeys.size());
}
Also used : Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 35 with Cache

use of javax.cache.Cache in project ignite by apache.

the class IgniteDbPutGetAbstractTest method checkLocalScan.

/**
     * @param total Expected total entries.
     * @param cntrs Expected per-node entries count.
     */
private void checkLocalScan(int total, Map<UUID, Integer> cntrs) {
    Set<DbKey> allKeys = new HashSet<>();
    for (int i = 0; i < gridCount(); i++) {
        Ignite ignite0 = grid(i);
        IgniteCache<DbKey, DbValue> cache0 = ignite0.cache("non-primitive");
        int cnt = 0;
        ScanQuery<DbKey, DbValue> qry = new ScanQuery<>();
        qry.setLocal(true);
        QueryCursor<Cache.Entry<DbKey, DbValue>> cur = cache0.query(qry);
        Map<Integer, Integer> partCntrs = new HashMap<>();
        Affinity<Object> aff = ignite0.affinity(cache0.getName());
        for (Cache.Entry<DbKey, DbValue> e : cur) {
            cnt++;
            allKeys.add(e.getKey());
            assertEquals(e.getKey().val, e.getValue().iVal);
            int part = aff.partition(e.getKey());
            Integer partCntr = partCntrs.get(part);
            if (partCntr == null)
                partCntr = 1;
            else
                partCntr += 1;
            partCntrs.put(part, partCntr);
        }
        assertEquals(cntrs.get(ignite0.cluster().localNode().id()), (Integer) cnt);
        checkScanPartition(ignite0, cache0, partCntrs, true);
    }
    assertEquals(total, allKeys.size());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ScanQuery(org.apache.ignite.cache.query.ScanQuery) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Aggregations

Cache (javax.cache.Cache)107 IgniteCache (org.apache.ignite.IgniteCache)71 Ignite (org.apache.ignite.Ignite)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 SqlQuery (org.apache.ignite.cache.query.SqlQuery)17 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 CacheManager (javax.cache.CacheManager)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14 ScanQuery (org.apache.ignite.cache.query.ScanQuery)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)11 Test (org.junit.Test)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 CacheException (javax.cache.CacheException)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 Collection (java.util.Collection)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 CachingProvider (javax.cache.spi.CachingProvider)8