Region extends GroupableConfiguration<RuntimeRegionInfo> { public void setName(String value) { if (value == null) { this.name = null; return; } boolean regionPrefixedWithSlash = value.startsWith(SEPARATOR); String[] regionSplit = value.split(SEPARATOR); boolean hasSubRegions = regionPrefixedWithSlash ? regionSplit.length > 2 : regionSplit.length > 1; if (hasSubRegions) { throw new IllegalArgumentException("Sub-regions are unsupported"); } this.name = regionPrefixedWithSlash ? regionSplit[1] : value; } Region(); @Override boolean isGlobalRuntime(); @Override Links getLinks(); @Override @JsonIgnore String getId(); String getName(); void setName(String value); RegionType getType(); void setType(RegionType type); Integer getRedundantCopies(); void setRedundantCopies(Integer redundantCopies); String getKeyConstraint(); void setKeyConstraint(String keyConstraint); String getValueConstraint(); void setValueConstraint(String valueConstraint); String getDiskStoreName(); void setDiskStoreName(String diskStoreName); List<Expiration> getExpirations(); void setExpirations(List<Expiration> expirations); Eviction getEviction(); void setEviction(Eviction eviction); void addExpiry(ExpirationType type, Integer timeout, ExpirationAction action); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final String REGION_CONFIG_ENDPOINT; static final String SEPARATOR; static final char SEPARATOR_CHAR; }
@Test public void subRegionsUnsupported() { regionConfig = new Region(); assertThatThrownBy(() -> regionConfig.setName(SEPARATOR + "Parent" + SEPARATOR + "Child")) .isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> regionConfig.setName("Parent" + SEPARATOR + "Child")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void equality() { Region region1 = new Region(); Region region2 = new Region(); assertThat(region1).as("initial state").isEqualTo(region2); region1.setName("region"); region2.setName("different-region"); assertThat(region1).as("with different names").isNotEqualTo(region2); region1.setName("region"); region2.setName("region"); assertThat(region1).as("with same name and no group").isEqualTo(region2); region1.setName("region"); region2.setName("region"); region1.setGroup("group"); region2.setGroup("group"); assertThat(region1).as("with same name and same group").isEqualTo(region2); region1.setName("region"); region2.setName("region"); region1.setGroup("group"); region2.setGroup("different-group"); assertThat(region1).as("with same name and different group").isNotEqualTo(region2); }