Search in sources :

Example 21 with FifoEvictionPolicy

use of org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy in project ignite by apache.

the class IgniteCacheTxIteratorSelfTest method cacheConfiguration.

/**
     * @return Cache configuration.
     */
private CacheConfiguration<String, TestClass> cacheConfiguration(CacheMode mode, CacheAtomicityMode atomMode, boolean nearEnabled, boolean useEvictPlc) {
    final CacheConfiguration<String, TestClass> ccfg = new CacheConfiguration<>(CACHE_NAME);
    ccfg.setAtomicityMode(atomMode);
    ccfg.setCacheMode(mode);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    if (nearEnabled)
        ccfg.setNearConfiguration(new NearCacheConfiguration<String, TestClass>());
    if (useEvictPlc) {
        ccfg.setEvictionPolicy(new FifoEvictionPolicy(50));
        ccfg.setOnheapCacheEnabled(true);
    }
    return ccfg;
}
Also used : FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 22 with FifoEvictionPolicy

use of org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy in project ignite by apache.

the class GridCacheEvictionTouchSelfTest method testEvictAll.

/**
     * @throws Exception If failed.
     */
public void testEvictAll() 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);
        Collection<Integer> keys = new ArrayList<>(100);
        for (int i = 0; i < 100; i++) {
            cache.put(i, i);
            keys.add(i);
        }
        assertEquals(100, ((FifoEvictionPolicy) plc).queue().size());
        for (Integer key : keys) cache.localEvict(Collections.singleton(key));
        assertEquals(0, ((FifoEvictionPolicy) plc).queue().size());
        assertEquals(0, cache.size(CachePeekMode.ONHEAP));
    } finally {
        stopAllGrids();
    }
}
Also used : ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)

Example 23 with FifoEvictionPolicy

use of org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy in project ignite by apache.

the class GridCacheEvictionTouchSelfTest method testEvictSingle.

/**
     * @throws Exception If failed.
     */
public void testEvictSingle() 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);
        for (int i = 0; i < 100; i++) cache.put(i, i);
        assertEquals(100, ((FifoEvictionPolicy) plc).queue().size());
        for (int i = 0; i < 100; i++) cache.localEvict(Collections.singleton(i));
        assertEquals(0, ((FifoEvictionPolicy) plc).queue().size());
        assertEquals(0, cache.size(CachePeekMode.ONHEAP));
    } finally {
        stopAllGrids();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)

Example 24 with FifoEvictionPolicy

use of org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy in project ignite by apache.

the class IgniteCachePeekModesAbstractTest method cacheConfiguration.

/** {@inheritDoc} */
@Override
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);
    ccfg.setBackups(1);
    if (hasNearCache())
        ccfg.setNearConfiguration(new NearCacheConfiguration());
    FifoEvictionPolicy plc = new FifoEvictionPolicy();
    plc.setMaxSize(HEAP_ENTRIES);
    ccfg.setEvictionPolicy(plc);
    ccfg.setOnheapCacheEnabled(true);
    return ccfg;
}
Also used : FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 25 with FifoEvictionPolicy

use of org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy 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)

Aggregations

FifoEvictionPolicy (org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)25 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)7 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)7 Ignite (org.apache.ignite.Ignite)5 LruEvictionPolicy (org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 TreeSet (java.util.TreeSet)1 Cache (javax.cache.Cache)1 Factory (javax.cache.configuration.Factory)1 Duration (javax.cache.expiry.Duration)1 IgniteCache (org.apache.ignite.IgniteCache)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 GridCacheAlwaysEvictionPolicy (org.apache.ignite.internal.processors.cache.GridCacheAlwaysEvictionPolicy)1 PA (org.apache.ignite.internal.util.typedef.PA)1 Transaction (org.apache.ignite.transactions.Transaction)1