public RegionAttributesType.EvictionAttributes convertToConfigEvictionAttributes() { RegionAttributesType.EvictionAttributes configAttributes = new RegionAttributesType.EvictionAttributes(); EnumActionDestroyOverflow action = EnumActionDestroyOverflow.fromValue(this.getAction() .toString());
@Test public void alterWithEvictionMaxWithExistingLruMemory() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --eviction-max=20"); // we are saving the eviction-max as a lruEntryCount's maximum value RegionAttributesType.EvictionAttributes.LruEntryCount lruEntryCount = deltaConfig.getRegionAttributes().getEvictionAttributes().getLruEntryCount(); assertThat(lruEntryCount.getMaximum()).isEqualTo("20"); // when there is no eviction attributes at all RegionAttributesType existingAttributes = new RegionAttributesType(); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); assertThat(existingAttributes.getEvictionAttributes()).isNull(); // when there is lruHeapPercentage eviction RegionAttributesType.EvictionAttributes evictionAttributes = new RegionAttributesType.EvictionAttributes(); existingAttributes.setEvictionAttributes(evictionAttributes); RegionAttributesType.EvictionAttributes.LruMemorySize existingMemorySize = new RegionAttributesType.EvictionAttributes.LruMemorySize(); existingMemorySize.setMaximum("100"); existingMemorySize.setAction(EnumActionDestroyOverflow.LOCAL_DESTROY); evictionAttributes.setLruMemorySize(existingMemorySize); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); assertThat(evictionAttributes.getLruMemorySize().getMaximum()).isEqualTo("20"); assertThat(evictionAttributes.getLruMemorySize().getAction()) .isEqualTo(EnumActionDestroyOverflow.LOCAL_DESTROY); }
@Test public void alterWithEvictionMaxWithExistingLruEntryCount() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --eviction-max=20"); // we are saving the eviction-max as a lruEntryCount's maximum value RegionAttributesType.EvictionAttributes.LruEntryCount lruEntryCount = deltaConfig.getRegionAttributes().getEvictionAttributes().getLruEntryCount(); assertThat(lruEntryCount.getMaximum()).isEqualTo("20"); // when there is no eviction attributes at all RegionAttributesType existingAttributes = new RegionAttributesType(); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); assertThat(existingAttributes.getEvictionAttributes()).isNull(); // when there is lruHeapPercentage eviction RegionAttributesType.EvictionAttributes evictionAttributes = new RegionAttributesType.EvictionAttributes(); existingAttributes.setEvictionAttributes(evictionAttributes); RegionAttributesType.EvictionAttributes.LruEntryCount existingEntryCount = new RegionAttributesType.EvictionAttributes.LruEntryCount(); existingEntryCount.setMaximum("100"); existingEntryCount.setAction(EnumActionDestroyOverflow.LOCAL_DESTROY); evictionAttributes.setLruEntryCount(existingEntryCount); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); assertThat(evictionAttributes.getLruEntryCount().getMaximum()).isEqualTo("20"); assertThat(evictionAttributes.getLruEntryCount().getAction()) .isEqualTo(EnumActionDestroyOverflow.LOCAL_DESTROY); }
new EvictionAttributes(); EvictionAttributes.LruEntryCount lruEntryCount = new EvictionAttributes.LruEntryCount();
private RegionAttributesType.EvictionAttributes generateEvictionAttributes(String evictionAction, Integer maxMemory, Integer maxEntryCount, String objectSizer) { RegionAttributesType.EvictionAttributes configAttributes = new RegionAttributesType.EvictionAttributes(); EnumActionDestroyOverflow action = EnumActionDestroyOverflow.fromValue(evictionAction); if (maxMemory == null && maxEntryCount == null) { RegionAttributesType.EvictionAttributes.LruHeapPercentage heapPercentage = new RegionAttributesType.EvictionAttributes.LruHeapPercentage(); heapPercentage.setAction(action); heapPercentage.setClassName(objectSizer); configAttributes.setLruHeapPercentage(heapPercentage); } else if (maxMemory != null) { RegionAttributesType.EvictionAttributes.LruMemorySize memorySize = new RegionAttributesType.EvictionAttributes.LruMemorySize(); memorySize.setAction(action); memorySize.setClassName(objectSizer); memorySize.setMaximum(maxMemory.toString()); configAttributes.setLruMemorySize(memorySize); } else { RegionAttributesType.EvictionAttributes.LruEntryCount entryCount = new RegionAttributesType.EvictionAttributes.LruEntryCount(); entryCount.setAction(action); entryCount.setMaximum(maxEntryCount.toString()); configAttributes.setLruEntryCount(entryCount); } return configAttributes; }
@Test public void alterWithEvictionMaxWithExistingLruHeapPercentage() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --eviction-max=20"); // we are saving the eviction-max as a lruEntryCount's maximum value RegionAttributesType.EvictionAttributes.LruEntryCount lruEntryCount = deltaConfig.getRegionAttributes().getEvictionAttributes().getLruEntryCount(); assertThat(lruEntryCount.getMaximum()).isEqualTo("20"); // when there is no eviction attributes at all RegionAttributesType existingAttributes = new RegionAttributesType(); existingRegionConfig.setRegionAttributes(existingAttributes); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); assertThat(existingAttributes.getEvictionAttributes()).isNull(); // when there is lruHeapPercentage eviction RegionAttributesType.EvictionAttributes evictionAttributes = new RegionAttributesType.EvictionAttributes(); evictionAttributes .setLruHeapPercentage(new RegionAttributesType.EvictionAttributes.LruHeapPercentage()); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); assertThat(evictionAttributes.getLruEntryCount()).isNull(); assertThat(evictionAttributes.getLruMemorySize()).isNull(); }
@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); }
public void setLruHeapPercentage(EnumActionDestroyOverflow action) { if (evictionAttributes == null) { evictionAttributes = new EvictionAttributes(); } EvictionAttributes.LruHeapPercentage lruHeapPercentage = new EvictionAttributes.LruHeapPercentage(); lruHeapPercentage.setAction(action); evictionAttributes.setLruHeapPercentage(lruHeapPercentage); }