use of org.apache.geode.internal.cache.EvictionAttributesImpl in project geode by apache.
the class MemoryMonitorOffHeapJUnitTest method testDisabledThresholds.
@Test
public void testDisabledThresholds() throws Exception {
final InternalResourceManager irm = this.cache.getInternalResourceManager();
final OffHeapMemoryMonitor monitor = irm.getOffHeapMonitor();
final RegionFactory regionFactory = this.cache.createRegionFactory(RegionShortcut.LOCAL);
regionFactory.setOffHeap(true);
final EvictionAttributesImpl evictionAttrs = new EvictionAttributesImpl();
evictionAttrs.setAlgorithm(EvictionAlgorithm.NONE);
regionFactory.setEvictionAttributes(evictionAttrs);
final Region region = regionFactory.create("testDefaultThresholdsRegion");
TestMemoryThresholdListener listener = new TestMemoryThresholdListener();
irm.addResourceListener(ResourceType.OFFHEAP_MEMORY, listener);
region.put("1", new Byte[550000]);
region.put("2", new Byte[200000]);
assertEquals(0, irm.getStats().getOffHeapEvictionStartEvents());
assertEquals(0, irm.getStats().getOffHeapEvictionStopEvents());
assertEquals(0, irm.getStats().getOffHeapCriticalEvents());
assertEquals(0, irm.getStats().getOffHeapSafeEvents());
assertEquals(0, listener.getEvictionThresholdCalls());
assertEquals(0, listener.getCriticalThresholdCalls());
// Enable eviction threshold and make sure event is generated
monitor.setEvictionThreshold(50f);
assertEquals(1, irm.getStats().getOffHeapEvictionStartEvents());
assertEquals(0, irm.getStats().getOffHeapCriticalEvents());
assertEquals(1, listener.getEvictionThresholdCalls());
assertEquals(0, listener.getCriticalThresholdCalls());
// Enable critical threshold and make sure event is generated
region.put("3", new Byte[200000]);
monitor.setCriticalThreshold(70f);
assertEquals(1, irm.getStats().getOffHeapEvictionStartEvents());
assertEquals(1, irm.getStats().getOffHeapCriticalEvents());
assertEquals(2, listener.getEvictionThresholdCalls());
assertEquals(1, listener.getCriticalThresholdCalls());
// Disable thresholds and verify events
monitor.setEvictionThreshold(0f);
monitor.setCriticalThreshold(0f);
assertEquals(1, irm.getStats().getOffHeapEvictionStartEvents());
assertEquals(1, irm.getStats().getOffHeapEvictionStopEvents());
assertEquals(1, irm.getStats().getOffHeapCriticalEvents());
assertEquals(1, irm.getStats().getOffHeapSafeEvents());
assertEquals(2, listener.getEvictionThresholdCalls());
assertEquals(2, listener.getCriticalThresholdCalls());
assertEquals(0, listener.getNormalCalls());
assertEquals(2, listener.getEvictionDisabledCalls());
assertEquals(2, listener.getCriticalDisabledCalls());
}
use of org.apache.geode.internal.cache.EvictionAttributesImpl in project geode by apache.
the class LuceneQueriesPersistenceIntegrationTest method shouldReturnCorrectResultsWithEntriesOverflowedToDisk.
@Test
public void shouldReturnCorrectResultsWithEntriesOverflowedToDisk() throws Exception {
String aeqId = LuceneServiceImpl.getUniqueIndexName(INDEX_NAME, REGION_NAME);
LuceneService service = LuceneServiceProvider.get(cache);
service.createIndexFactory().setFields(Type1.fields).create(INDEX_NAME, REGION_NAME);
RegionFactory<String, Type1> regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
EvictionAttributesImpl evicAttr = new EvictionAttributesImpl().setAction(EvictionAction.OVERFLOW_TO_DISK);
evicAttr.setAlgorithm(EvictionAlgorithm.LRU_ENTRY).setMaximum(1);
regionFactory.setEvictionAttributes(evicAttr);
PartitionedRegion userRegion = (PartitionedRegion) regionFactory.create(REGION_NAME);
final LuceneIndex index = service.getIndex(INDEX_NAME, REGION_NAME);
Assert.assertEquals(0, userRegion.getDiskRegionStats().getNumOverflowOnDisk());
Type1 value = new Type1("hello world", 1, 2L, 3.0, 4.0f);
userRegion.put("value1", value);
value = new Type1("test world", 1, 2L, 3.0, 4.0f);
userRegion.put("value2", value);
value = new Type1("lucene world", 1, 2L, 3.0, 4.0f);
userRegion.put("value3", value);
service.waitUntilFlushed(INDEX_NAME, REGION_NAME, 60000, TimeUnit.MILLISECONDS);
PartitionedRegion fileRegion = (PartitionedRegion) cache.getRegion(aeqId + ".files");
assertNotNull(fileRegion);
Assert.assertTrue(0 < userRegion.getDiskRegionStats().getNumOverflowOnDisk());
LuceneQuery<Integer, Type1> query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "s:world", DEFAULT_FIELD);
PageableLuceneQueryResults<Integer, Type1> results = query.findPages();
Assert.assertEquals(3, results.size());
}
Aggregations