Search in sources :

Example 36 with Cache

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

the class IndexingSpiQuerySelfTest method testNonBinaryIndexingSpi.

/**
 * @throws Exception If failed.
 */
public void testNonBinaryIndexingSpi() throws Exception {
    System.setProperty(IgniteSystemProperties.IGNITE_UNWRAP_BINARY_FOR_INDEXING_SPI, "true");
    IgniteConfiguration cfg = configuration();
    cfg.setIndexingSpi(new MyIndexingSpi());
    Ignite ignite = Ignition.start(cfg);
    CacheConfiguration<PersonKey, Person> ccfg = cacheConfiguration(CACHE_NAME);
    IgniteCache<PersonKey, Person> cache = ignite.createCache(ccfg);
    for (int i = 0; i < 10; i++) {
        PersonKey key = new PersonKey(i);
        cache.put(key, new Person("John Doe " + i));
    }
    QueryCursor<Cache.Entry<PersonKey, Person>> cursor = cache.query(new SpiQuery<PersonKey, Person>().setArgs(new PersonKey(2), new PersonKey(5)));
    for (Cache.Entry<PersonKey, Person> entry : cursor) System.out.println(entry);
    cache.remove(new PersonKey(9));
}
Also used : SpiQuery(org.apache.ignite.cache.query.SpiQuery) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 37 with Cache

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

the class GridCacheEvictionTouchSelfTest method testPolicyConsistency.

/**
 * @throws Exception If failed.
 */
public void testPolicyConsistency() throws Exception {
    FifoEvictionPolicy<Object, Object> plc = new FifoEvictionPolicy<>();
    plc.setMaxSize(500);
    this.plc = plc;
    try {
        Ignite ignite = startGrid(1);
        final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
        final Random rnd = new Random();
        try (Transaction tx = ignite.transactions().txStart()) {
            int iterCnt = 20;
            int keyCnt = 5000;
            for (int i = 0; i < iterCnt; i++) {
                int j = rnd.nextInt(keyCnt);
                // Put or remove?
                if (rnd.nextBoolean())
                    cache.put(j, j);
                else
                    cache.remove(j);
                if (i != 0 && i % 1000 == 0)
                    info("Stats [iterCnt=" + i + ", size=" + cache.size() + ']');
            }
            FifoEvictionPolicy<Integer, Integer> plc0 = (FifoEvictionPolicy<Integer, Integer>) this.plc;
            if (!plc0.queue().isEmpty()) {
                for (Cache.Entry<Integer, Integer> e : plc0.queue()) U.warn(log, "Policy queue item: " + e);
                fail("Test failed, see logs for details.");
            }
            tx.commit();
        }
    } catch (Throwable t) {
        error("Test failed.", t);
        fail("Test failed, see logs for details.");
    } finally {
        stopAllGrids();
    }
}
Also used : Random(java.util.Random) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 38 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 39 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 40 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)139 IgniteCache (org.apache.ignite.IgniteCache)94 Ignite (org.apache.ignite.Ignite)49 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)30 ScanQuery (org.apache.ignite.cache.query.ScanQuery)21 ArrayList (java.util.ArrayList)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 List (java.util.List)18 SqlQuery (org.apache.ignite.cache.query.SqlQuery)18 CacheManager (javax.cache.CacheManager)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 Map (java.util.Map)14 Collection (java.util.Collection)13 IgniteException (org.apache.ignite.IgniteException)12 BinaryObject (org.apache.ignite.binary.BinaryObject)12 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)11 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10