Search in sources :

Example 1 with EvictableEntry

use of org.apache.ignite.cache.eviction.EvictableEntry in project ignite by apache.

the class EvictionAbstractTest method checkPolicies.

/**
 * Performs after-test policy check.
 */
protected void checkPolicies() {
    for (int i = 0; i < gridCnt; i++) {
        if (plcMaxMemSize > 0) {
            int size = 0;
            for (EvictableEntry entry : proxy(policy(i)).queue()) size += entry.size();
            assertEquals(size, proxy(policy(i)).getCurrentMemorySize());
        } else
            assertTrue(proxy(policy(i)).queue().size() <= plcMax + plcBatchSize);
    }
}
Also used : EvictableEntry(org.apache.ignite.cache.eviction.EvictableEntry)

Example 2 with EvictableEntry

use of org.apache.ignite.cache.eviction.EvictableEntry in project ignite by apache.

the class EvictionPolicyFactoryAbstractTest method checkPolicies.

/**
 * Performs after-test policy check.
 */
protected void checkPolicies() {
    for (int i = 0; i < gridCnt; i++) {
        if (plcMaxMemSize > 0) {
            int size = 0;
            for (EvictableEntry entry : proxy(policy(i)).queue()) size += entry.size();
            assertEquals(size, proxy(policy(i)).getCurrentMemorySize());
        } else
            assertTrue(proxy(policy(i)).queue().size() <= plcMax + plcBatchSize);
    }
}
Also used : EvictableEntry(org.apache.ignite.cache.eviction.EvictableEntry)

Example 3 with EvictableEntry

use of org.apache.ignite.cache.eviction.EvictableEntry in project ignite by apache.

the class GridCacheConcurrentEvictionConsistencySelfTest method checkPolicyConsistency.

/**
 * @throws Exception If failed.
 */
private void checkPolicyConsistency() throws Exception {
    try {
        final Ignite ignite = startGrid(1);
        final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
        long start = System.currentTimeMillis();
        IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                final Random rnd = new Random();
                for (int i = 0; i < ITERATION_CNT; i++) {
                    int j = rnd.nextInt(keyCnt);
                    while (true) {
                        try (Transaction tx = ignite.transactions().txStart()) {
                            // Put or remove?
                            if (rnd.nextBoolean())
                                cache.put(j, j);
                            else
                                cache.remove(j);
                            tx.commit();
                            break;
                        } catch (Exception e) {
                            MvccFeatureChecker.assertMvccWriteConflict(e);
                        }
                    }
                    if (i != 0 && i % 5000 == 0)
                        info("Stats [iterCnt=" + i + ", size=" + cache.size() + ']');
                }
                return null;
            }
        }, threadCnt);
        fut.get();
        Collection<EvictableEntry<Integer, Integer>> queue = internalQueue(plc);
        info("Test results [threadCnt=" + threadCnt + ", iterCnt=" + ITERATION_CNT + ", cacheSize=" + cache.size() + ", internalQueueSize" + queue.size() + ", duration=" + (System.currentTimeMillis() - start) + ']');
        boolean detached = false;
        for (Cache.Entry<Integer, Integer> e : queue) {
            Integer rmv = cache.getAndRemove(e.getKey());
            CacheEvictableEntryImpl unwrapped = e.unwrap(CacheEvictableEntryImpl.class);
            if (rmv == null && (unwrapped.meta() != null || unwrapped.isCached())) {
                U.warn(log, "Detached entry: " + e);
                detached = true;
            } else
                info("Entry removed: " + rmv);
        }
        if (detached)
            fail("Eviction policy contains keys that are not present in cache");
        if (!(cache.localSize(CachePeekMode.ONHEAP) == 0)) {
            boolean zombies = false;
            for (Cache.Entry<Integer, Integer> e : cache.localEntries(CachePeekMode.ONHEAP)) {
                U.warn(log, "Zombie entry: " + e);
                zombies = true;
            }
            if (zombies)
                fail("Cache contained zombie entries.");
        } else
            info("Cache is empty after test.");
    } finally {
        stopAllGrids();
    }
}
Also used : EvictableEntry(org.apache.ignite.cache.eviction.EvictableEntry) Random(java.util.Random) Transaction(org.apache.ignite.transactions.Transaction) CacheEvictableEntryImpl(org.apache.ignite.internal.processors.cache.CacheEvictableEntryImpl) Ignite(org.apache.ignite.Ignite) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Aggregations

EvictableEntry (org.apache.ignite.cache.eviction.EvictableEntry)3 Random (java.util.Random)1 Cache (javax.cache.Cache)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 CacheEvictableEntryImpl (org.apache.ignite.internal.processors.cache.CacheEvictableEntryImpl)1 Transaction (org.apache.ignite.transactions.Transaction)1