@Override public String getId() { return getName(); }
private RegionConfig findRegionConfig(CacheConfig cacheConfig, String regionName) { return cacheConfig.getRegions().stream() .filter(region -> region.getName().equals(regionName)).findFirst().orElse(null); }
private RegionConfig findRegionConfig(CacheConfig cacheConfig, String regionName) { return cacheConfig.getRegions().stream() .filter(region -> region.getName().equals(regionName)).findFirst().orElse(null); }
@Override public void validate(RegionConfig config) throws IllegalArgumentException { if (config.getName() == null) { throw new IllegalArgumentException("Name of the region has to be specified."); } if (config.getType() == null) { config.setType(DEFAULT_REGION_TYPE); } } }
/** * this is used to create only root regions. * * @param regionConfig the name in the regionConfig can not contain sub-regions. */ @Override public void create(RegionConfig regionConfig, Cache cache) { RegionFactory factory = getRegionFactory(cache, regionConfig.getRegionAttributes()); factory.create(regionConfig.getName()); }
private void setupRegionConfigToUseDataSource(String dataSourceName) { RegionConfig regionConfig = mock(RegionConfig.class); when(regionConfig.getName()).thenReturn("regionUsingDataSource"); List<RegionConfig> regionConfigList = new ArrayList<>(); regionConfigList.add(regionConfig); when(cacheConfig.getRegions()).thenReturn(regionConfigList); RegionMapping regionMapping = mock(RegionMapping.class); when(regionMapping.getDataSourceName()).thenReturn(dataSourceName); List<CacheElement> cacheElementList = new ArrayList<>(); cacheElementList.add(regionMapping); when(regionConfig.getCustomRegionElements()).thenReturn(cacheElementList); }
@Test public void updateClusterConfigWithOneNonMatchingRegionDoesNotAddMapping() { List<RegionConfig> list = new ArrayList<>(); RegionConfig nonMatchingRegion = mock(RegionConfig.class); when(nonMatchingRegion.getName()).thenReturn("nonMatchingRegion"); List<CacheElement> listCacheElements = new ArrayList<>(); when(nonMatchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(nonMatchingRegion); when(cacheConfig.getRegions()).thenReturn(list); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); assertThat(listCacheElements).isEmpty(); }
@Test public void regionNameSwallowsSlash() { regionConfig.setName("/regionA"); assertThat(regionConfig.getName()).isEqualTo("regionA"); }
@Test public void isDataSourceUsedByRegionGivenRegionConfigWithRegionMappingForDataSourceReturnsTrue() { RegionConfig regionConfig = mock(RegionConfig.class); when(regionConfig.getName()).thenReturn("regionName"); RegionMapping regionMapping = mock(RegionMapping.class); when(regionMapping.getDataSourceName()).thenReturn("dataSourceName"); when(regionConfig.getCustomRegionElements()) .thenReturn(Collections.singletonList(regionMapping)); regionConfigs.add(regionConfig); boolean result = command.isDataSourceUsedByRegion(cacheConfig, "dataSourceName"); assertThat(result).isTrue(); }
@Test public void unmarshallPartialElement() { String xml = "<region name=\"one\">\n" + " <region-attributes scope=\"distributed-ack\" data-policy=\"replicate\"/>\n" + " </region>"; RegionConfig config = service2.unMarshall(xml, RegionConfig.class); assertThat(config.getName()).isEqualTo("one"); }
@Test public void generatesConfigForRegion() { generate(); assertThat(config.getName()).isEqualTo("region-name"); }
@Test public void generatesConfigForSubRegion() { regionPath = "region-name/subregion"; generate(); assertThat(config.getName()).isEqualTo("subregion"); }
@Test public void getRegionsThatUseDataSourceGivenRegionConfigWithRegionMappingForDataSourceReturnsRegionName() { RegionConfig regionConfig = mock(RegionConfig.class); when(regionConfig.getName()).thenReturn("regionName"); RegionMapping regionMapping = mock(RegionMapping.class); when(regionMapping.getDataSourceName()).thenReturn("dataSourceName"); when(regionConfig.getCustomRegionElements()) .thenReturn(Collections.singletonList(regionMapping)); regionConfigs.add(regionConfig); List<String> result = command.getRegionsThatUseDataSource(cacheConfig, "dataSourceName"); assertThat(result).isEqualTo(Collections.singletonList("regionName")); }
private void setupJDBCMappingOnRegion(String regionName) { doReturn(cacheConfig).when(ccService).getCacheConfig(null); doReturn(regionConfigList).when(cacheConfig).getRegions(); doReturn(regionName).when(regionConfig).getName(); doReturn(regionName).when(regionConfig).getId(); doReturn(cacheElementList).when(regionConfig).getCustomRegionElements(); doReturn("jdbc-mapping").when(cacheElement).getId(); }
@Override public CliFunctionResult executeFunction(FunctionContext<RegionConfig> context) { Cache cache = ((InternalCache) context.getCache()).getCacheForProcessingClientRequests(); RegionConfig deltaConfig = context.getArguments(); alterRegion(cache, deltaConfig); return new CliFunctionResult(context.getMemberName(), Result.Status.OK, String.format("Region %s altered", deltaConfig.getName())); }
@Test public void unmarshallAnyElement() { String xml = "<region name=\"one\">\n" + " <region-attributes scope=\"distributed-ack\" data-policy=\"replicate\"/>\n" + " <custom:any xmlns:custom=\"http://geode.apache.org/schema/custom\" id=\"any\"/>" + " </region>"; RegionConfig config = service2.unMarshall(xml, RegionConfig.class); assertThat(config.getName()).isEqualTo("one"); assertThat(config.getCustomRegionElements()).hasSize(1); }
@Test public void updateClusterConfigWithOneNonMatchingRegionDoesNotRemoveMapping() { List<RegionConfig> list = new ArrayList<>(); RegionConfig nonMatchingRegion = mock(RegionConfig.class); when(nonMatchingRegion.getName()).thenReturn("nonMatchingRegion"); List<CacheElement> listCacheElements = new ArrayList<>(); RegionMapping nonMatchingMapping = mock(RegionMapping.class); listCacheElements.add(nonMatchingMapping); when(nonMatchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(nonMatchingRegion); when(cacheConfig.getRegions()).thenReturn(list); boolean modified = destroyRegionMappingCommand.updateConfigForGroup(null, cacheConfig, regionName); assertThat(listCacheElements).isEqualTo(Arrays.asList(nonMatchingMapping)); assertThat(modified).isFalse(); }
@Test public void marshallNoNameSpace() { String xml = "<cache version=\"1.0\">\n" + " <region name=\"one\">\n" + " <region-attributes scope=\"distributed-ack\" data-policy=\"replicate\"/>\n" + " </region>\n" + "</cache>"; CacheConfig cacheConfig = service2.unMarshall(xml); assertThat(cacheConfig.getRegions()).hasSize(1); assertThat(cacheConfig.getRegions().get(0).getName()).isEqualTo("one"); }
@Test public void marshalOlderNameSpace() { String xml = "<cache xsi:schemaLocation=\"http://schema.pivotal.io/gemfire/cache http://schema.pivotal.io/gemfire/cache/cache-8.1.xsd\"\n" + " version=\"8.1\"\n" + " xmlns=\"http://schema.pivotal.io/gemfire/cache\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + " <region name=\"one\">\n" + " <region-attributes scope=\"distributed-ack\" data-policy=\"replicate\"/>\n" + " </region>\n" + "</cache>"; CacheConfig cacheConfig = service2.unMarshall(xml); assertThat(cacheConfig.getRegions()).hasSize(1); assertThat(cacheConfig.getRegions().get(0).getName()).isEqualTo("one"); }
@Test public void correctJsonAndXml() throws Exception { String json = "{\"name\":\"test\", \"type\":\"REPLICATE\"}"; ObjectMapper mapper = new ObjectMapper(); regionConfig = mapper.readValue(json, RegionConfig.class); assertThat(regionConfig.getName()).isEqualTo("test"); assertThat(regionConfig.getType()).isEqualTo("REPLICATE"); String json2 = mapper.writeValueAsString(regionConfig); assertThat(json2).contains("\"type\":\"REPLICATE\""); assertThat(json2).contains("\"id\":\"test\""); CacheConfig cacheConfig = new CacheConfig(); cacheConfig.getRegions().add(regionConfig); String xml = service.marshall(cacheConfig); assertThat(xml).contains("<region name=\"test\" refid=\"REPLICATE\""); } }