Search in sources :

Example 46 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class IgniteCacheReadThroughEvictionSelfTest method testReadThroughEvictionPolicy.

/**
     * @throws Exception if failed.
     */
public void testReadThroughEvictionPolicy() throws Exception {
    Ignite ig = testedGrid();
    CacheConfiguration<Object, Object> cc = variationConfig("eviction");
    cc.setEvictionPolicy(new FifoEvictionPolicy(1));
    cc.setOnheapCacheEnabled(true);
    final IgniteCache<Object, Object> cache = ig.createCache(cc);
    try {
        for (int i = 0; i < KEYS; i++) cache.put(key(i), value(i));
        assertTrue(GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                int size = cache.size(CachePeekMode.ONHEAP);
                int offheapSize = cache.size(CachePeekMode.OFFHEAP);
                System.out.println("Cache [onHeap=" + size + ", offHeap=" + offheapSize + ']');
                return size <= testsCfg.gridCount();
            }
        }, 30_000));
        for (int i = 0; i < KEYS; i++) assertEquals(value(i), cache.get(key(i)));
    } finally {
        destroyCacheSafe(ig, cc.getName());
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) Ignite(org.apache.ignite.Ignite) FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)

Example 47 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class IgniteCacheReadThroughEvictionSelfTest method waitEmpty.

/**
     * @throws Exception if failed.
     */
private void waitEmpty(final String name) throws Exception {
    boolean success = GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            for (Ignite g : G.allGrids()) {
                GridCacheAdapter<Object, Object> cache = ((IgniteEx) g).context().cache().internalCache(name);
                if (cache == null)
                    return true;
                if (!cache.isEmpty())
                    return false;
            }
            return true;
        }
    }, getTestTimeout());
    assertTrue("Failed to wait for the cache to be empty", success);
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) Ignite(org.apache.ignite.Ignite)

Example 48 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridCacheRebalancingSyncSelfTest method checkSupplyContextMapIsEmpty.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
protected void checkSupplyContextMapIsEmpty() throws Exception {
    for (Ignite g : G.allGrids()) {
        for (GridCacheAdapter c : ((IgniteEx) g).context().cache().internalCaches()) {
            Object supplier = U.field(c.preloader(), "supplier");
            final Map map = U.field(supplier, "scMap");
            GridTestUtils.waitForCondition(new PA() {

                @Override
                public boolean apply() {
                    synchronized (map) {
                        return map.isEmpty();
                    }
                }
            }, 15_000);
            synchronized (map) {
                assertTrue("Map is not empty [cache=" + c.name() + ", node=" + g.name() + ", map=" + map + ']', map.isEmpty());
            }
        }
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Aggregations

PA (org.apache.ignite.internal.util.typedef.PA)48 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 Ignite (org.apache.ignite.Ignite)17 ArrayList (java.util.ArrayList)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 UUID (java.util.UUID)9 CacheEntryEvent (javax.cache.event.CacheEntryEvent)9 IgniteException (org.apache.ignite.IgniteException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IgniteCache (org.apache.ignite.IgniteCache)5 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 T2 (org.apache.ignite.internal.util.typedef.T2)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Transaction (org.apache.ignite.transactions.Transaction)4