@Before public void setUp() throws Exception { function = spy(RegionAlterFunction.class); config = new RegionConfig(); regionAttributes = new RegionAttributesType(); config.setRegionAttributes(regionAttributes); internalCache = mock(InternalCache.class); cache = mock(InternalCacheForClientAccess.class); mutator = mock(AttributesMutator.class); evictionMutator = mock(EvictionAttributesMutator.class); when(mutator.getEvictionAttributesMutator()).thenReturn(evictionMutator); region = mock(AbstractRegion.class); context = mock(FunctionContext.class); when(context.getCache()).thenReturn(internalCache); when(internalCache.getCacheForProcessingClientRequests()).thenReturn(cache); when(context.getArguments()).thenReturn(config); when(context.getMemberName()).thenReturn("member"); when(cache.getRegion(any())).thenReturn(region); when(region.getAttributesMutator()).thenReturn(mutator); }
@Test public void updateWithEvictionAttributes() { RegionAttributesType.EvictionAttributes evictionAttributes = new RegionAttributesType.EvictionAttributes(); RegionAttributesType.EvictionAttributes.LruEntryCount lruEntryCount = new RegionAttributesType.EvictionAttributes.LruEntryCount(); lruEntryCount.setMaximum("10"); evictionAttributes.setLruEntryCount(lruEntryCount); regionAttributes.setEvictionAttributes(evictionAttributes); function.alterRegion(cache, config); verify(mutator).getEvictionAttributesMutator(); verify(evictionMutator).setMaximum(10); }
mutator.getEvictionAttributesMutator().setMaximum(Integer .parseInt(regionAttributes.getEvictionAttributes().getLruEntryCount().getMaximum())); if (logger.isDebugEnabled()) {
Optional.ofNullable(attributesMutator.getEvictionAttributesMutator()) .ifPresent(evictionAttributesMutator -> Optional.ofNullable(this.evictionMaximum) .ifPresent(evictionAttributesMutator::setMaximum));
Optional.ofNullable(attributesMutator.getEvictionAttributesMutator()) .ifPresent(evictionAttributesMutator -> Optional.ofNullable(this.evictionMaximum) .ifPresent(evictionAttributesMutator::setMaximum));
when(mockAttributesMutator.getEvictionAttributesMutator()).thenReturn(mockEvictionAttributesMutator); when(mockAttributesMutator.getRegion()).thenReturn(mockRegion);