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;
}
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();
}
}
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();
}
}
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;
}
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());
}
}
Aggregations