@Test public void testDisabledThresholds() throws Exception { final InternalResourceManager irm = this.cache.getResourceManager(); 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()); }
/** * Intelligently merges the given RegionAttributes with the configuration setting of the * RegionFactory. This method is used to merge the RegionAttributes and PartitionAttributes with * the RegionFactory that is created when the user specified a RegionShortcut. This method gets * called by the createRegionFactory method depending upon the value passed to the * Cache.createRegionFactory() method (i.e. whether there was a RegionShortcut specified or not). * * @param <K> the Class type fo the Region key. * @param <V> the Class type of the Region value. * @param regionFactory the GemFire RegionFactory used to configure and create the Region that is * the product of this RegionFactoryBean. * @param regionAttributes the RegionAttributes containing the Region configuration settings to * merge to the RegionFactory. * @return the RegionFactory with the configuration settings of the RegionAttributes merged. * @see #isUserSpecifiedEvictionAttributes(com.gemstone.gemfire.cache.RegionAttributes) * @see #validateRegionAttributes(com.gemstone.gemfire.cache.RegionAttributes) * @see com.gemstone.gemfire.cache.RegionAttributes * @see com.gemstone.gemfire.cache.RegionFactory */ @SuppressWarnings("unchecked") protected <K, V> RegionFactory<K, V> mergeRegionAttributes( final RegionFactory<K, V> regionFactory, final RegionAttributes<K, V> regionAttributes) { if (regionAttributes != null) { // NOTE this validation may not be strictly required depending on how the RegionAttributes // were "created", // but... validateRegionAttributes(regionAttributes); regionFactory.setCloningEnabled(regionAttributes.getCloningEnabled()); regionFactory.setCompressor(regionAttributes.getCompressor()); regionFactory.setConcurrencyChecksEnabled(regionAttributes.getConcurrencyChecksEnabled()); regionFactory.setConcurrencyLevel(regionAttributes.getConcurrencyLevel()); regionFactory.setCustomEntryIdleTimeout(regionAttributes.getCustomEntryIdleTimeout()); regionFactory.setCustomEntryTimeToLive(regionAttributes.getCustomEntryTimeToLive()); regionFactory.setDiskSynchronous(regionAttributes.isDiskSynchronous()); regionFactory.setEnableAsyncConflation(regionAttributes.getEnableAsyncConflation()); regionFactory.setEnableSubscriptionConflation( regionAttributes.getEnableSubscriptionConflation()); regionFactory.setEntryIdleTimeout(regionAttributes.getEntryIdleTimeout()); regionFactory.setEntryTimeToLive(regionAttributes.getEntryTimeToLive()); // NOTE EvictionAttributes are created by certain RegionShortcuts; need the null check! if (isUserSpecifiedEvictionAttributes(regionAttributes)) { regionFactory.setEvictionAttributes(regionAttributes.getEvictionAttributes()); } regionFactory.setIgnoreJTA(regionAttributes.getIgnoreJTA()); regionFactory.setIndexMaintenanceSynchronous( regionAttributes.getIndexMaintenanceSynchronous()); regionFactory.setInitialCapacity(regionAttributes.getInitialCapacity()); regionFactory.setKeyConstraint(regionAttributes.getKeyConstraint()); regionFactory.setLoadFactor(regionAttributes.getLoadFactor()); regionFactory.setLockGrantor(regionAttributes.isLockGrantor()); regionFactory.setMembershipAttributes(regionAttributes.getMembershipAttributes()); regionFactory.setMulticastEnabled(regionAttributes.getMulticastEnabled()); mergePartitionAttributes(regionFactory, regionAttributes); regionFactory.setPoolName(regionAttributes.getPoolName()); regionFactory.setRegionIdleTimeout(regionAttributes.getRegionIdleTimeout()); regionFactory.setRegionTimeToLive(regionAttributes.getRegionTimeToLive()); regionFactory.setStatisticsEnabled(regionAttributes.getStatisticsEnabled()); regionFactory.setSubscriptionAttributes(regionAttributes.getSubscriptionAttributes()); regionFactory.setValueConstraint(regionAttributes.getValueConstraint()); } return regionFactory; }