RegionConverter extends ConfigurationConverter<Region, RegionConfig> { private RegionAttributesType.EvictionAttributes convertFrom(Region.Eviction eviction) { return RegionAttributesType.EvictionAttributes.generate(getEvictionActionString(eviction), eviction.getMemorySizeMb(), eviction.getEntryCount(), eviction.getObjectSizer()); }  RegionType getRegionType(String refid, RegionAttributesType regionAttributes); RegionAttributesType createRegionAttributesByType(String type);  }
@Test public void convertExpirationFromConfig() { Region.Expiration expiration = new Region.Expiration(); expiration.setTimeInSeconds(2); RegionAttributesType.ExpirationAttributesType expirationAttributes = converter.convertFrom(expiration); assertThat(expirationAttributes.getCustomExpiry()).isNull(); assertThat(expirationAttributes.getAction()).isEqualTo("destroy"); assertThat(expirationAttributes.getTimeout()).isEqualTo("2"); expiration.setTimeInSeconds(20); expiration.setAction(Region.ExpirationAction.INVALIDATE); expirationAttributes = converter.convertFrom(expiration); assertThat(expirationAttributes.getCustomExpiry()).isNull(); assertThat(expirationAttributes.getAction()).isEqualTo("invalidate"); assertThat(expirationAttributes.getTimeout()).isEqualTo("20"); }
@Test public void convertExpirationFromXml() { RegionAttributesType.ExpirationAttributesType xmlConfig = new RegionAttributesType.ExpirationAttributesType(); Region.Expiration expiration = converter.convertFrom(Region.ExpirationType.ENTRY_IDLE_TIME, xmlConfig); assertThat(expiration.getType()).isEqualTo(Region.ExpirationType.ENTRY_IDLE_TIME); assertThat(expiration.getAction()).isEqualTo(Region.ExpirationAction.INVALIDATE); assertThat(expiration.getTimeInSeconds()).isEqualTo(0); xmlConfig.setTimeout("1000"); xmlConfig.setAction("destroy"); expiration = converter.convertFrom(Region.ExpirationType.ENTRY_IDLE_TIME, xmlConfig); assertThat(expiration.getType()).isEqualTo(Region.ExpirationType.ENTRY_IDLE_TIME); assertThat(expiration.getAction()).isEqualTo(Region.ExpirationAction.DESTROY); assertThat(expiration.getTimeInSeconds()).isEqualTo(1000); xmlConfig.setAction("local-destroy"); expiration = converter.convertFrom(Region.ExpirationType.ENTRY_IDLE_TIME, xmlConfig); assertThat(expiration.getType()).isEqualTo(Region.ExpirationType.ENTRY_IDLE_TIME); assertThat(expiration.getAction()).isEqualTo(Region.ExpirationAction.LEGACY); assertThat(expiration.getTimeInSeconds()).isEqualTo(1000); }
@Test public void convertRegionEvictionFromXMLMemorySize() { config.setType("REPLICATE"); config.setName("test"); RegionAttributesType attributes = new RegionAttributesType(); RegionAttributesType.EvictionAttributes.LruMemorySize evictionXmlConfig = new RegionAttributesType.EvictionAttributes.LruMemorySize(); evictionXmlConfig.setMaximum("100"); evictionXmlConfig.setAction(EnumActionDestroyOverflow.OVERFLOW_TO_DISK); evictionXmlConfig.setClassName("ObjectSizer"); Properties properties = new Properties(); properties.setProperty("key", "value"); evictionXmlConfig.setParameters(properties); RegionAttributesType.EvictionAttributes evictionAttributes = new RegionAttributesType.EvictionAttributes(); evictionAttributes.setLruMemorySize(evictionXmlConfig); attributes.setEvictionAttributes(evictionAttributes); config.setRegionAttributes(attributes); Region region = converter.fromXmlObject(config); Region.Eviction eviction = region.getEviction(); assertThat(eviction.getType()).isEqualTo(Region.EvictionType.MEMORY_SIZE); assertThat(eviction.getAction()).isEqualTo(Region.EvictionAction.OVERFLOW_TO_DISK); assertThat(eviction.getMemorySizeMb()).isEqualTo(100); assertThat(eviction.getObjectSizer().getClassName()).isEqualTo("ObjectSizer"); assertThat(eviction.getObjectSizer().getInitProperties()).containsEntry("key", "value"); assertThat(eviction.getEntryCount()).isNull(); evictionXmlConfig.setAction(EnumActionDestroyOverflow.LOCAL_DESTROY); eviction = converter.convertFrom(evictionXmlConfig); assertThat(eviction.getAction()).isEqualTo(Region.EvictionAction.LOCAL_DESTROY); }
@Test public void convertRegionEvicionFromXMLEntrySize() { config.setType("REPLICATE"); config.setName("test"); RegionAttributesType attributes = new RegionAttributesType(); RegionAttributesType.EvictionAttributes.LruEntryCount evictionXmlConfig = new RegionAttributesType.EvictionAttributes.LruEntryCount(); evictionXmlConfig.setMaximum("100"); evictionXmlConfig.setAction(EnumActionDestroyOverflow.OVERFLOW_TO_DISK); RegionAttributesType.EvictionAttributes evictionAttributes = new RegionAttributesType.EvictionAttributes(); evictionAttributes.setLruEntryCount(evictionXmlConfig); attributes.setEvictionAttributes(evictionAttributes); config.setRegionAttributes(attributes); Region region = converter.fromXmlObject(config); Region.Eviction eviction = region.getEviction(); assertThat(eviction.getType()).isEqualTo(Region.EvictionType.ENTRY_COUNT); assertThat(eviction.getAction()).isEqualTo(Region.EvictionAction.OVERFLOW_TO_DISK); assertThat(eviction.getEntryCount()).isEqualTo(100); assertThat(eviction.getMemorySizeMb()).isNull(); evictionXmlConfig.setAction(EnumActionDestroyOverflow.LOCAL_DESTROY); eviction = converter.convertFrom(evictionXmlConfig); assertThat(eviction.getAction()).isEqualTo(Region.EvictionAction.LOCAL_DESTROY); }
@Test public void convertRegionEvictionFromXMLHeapSize() { config.setType("REPLICATE"); config.setName("test"); RegionAttributesType attributes = new RegionAttributesType(); RegionAttributesType.EvictionAttributes.LruHeapPercentage evictionXmlConfig = new RegionAttributesType.EvictionAttributes.LruHeapPercentage(); evictionXmlConfig.setAction(EnumActionDestroyOverflow.OVERFLOW_TO_DISK); RegionAttributesType.EvictionAttributes evictionAttributes = new RegionAttributesType.EvictionAttributes(); evictionAttributes.setLruHeapPercentage(evictionXmlConfig); attributes.setEvictionAttributes(evictionAttributes); config.setRegionAttributes(attributes); Region region = converter.fromXmlObject(config); Region.Eviction eviction = region.getEviction(); assertThat(eviction.getType()).isEqualTo(Region.EvictionType.HEAP_PERCENTAGE); assertThat(eviction.getAction()).isEqualTo(Region.EvictionAction.OVERFLOW_TO_DISK); assertThat(eviction.getMemorySizeMb()).isNull(); assertThat(eviction.getEntryCount()).isNull(); evictionXmlConfig.setAction(EnumActionDestroyOverflow.LOCAL_DESTROY); eviction = converter.convertFrom(evictionXmlConfig); assertThat(eviction.getAction()).isEqualTo(Region.EvictionAction.LOCAL_DESTROY); }