/** * @throws IllegalStateException if the data source is used by a jdbc-mapping. The exception * message names the region using this data source */ private void checkIfDataSourceIsInUse(InternalConfigurationPersistenceService service, String dataSourceName) { CacheConfig cacheConfig = service.getCacheConfig(null); for (RegionConfig regionConfig : cacheConfig.getRegions()) { for (CacheElement cacheElement : regionConfig.getCustomRegionElements()) { if (cacheElement instanceof RegionMapping) { RegionMapping regionMapping = (RegionMapping) cacheElement; if (dataSourceName.equals(regionMapping.getDataSourceName())) { throw new IllegalStateException(regionConfig.getName()); } } } } }
private RegionAttributesType getRegionAttribute(RegionConfig config) { if (config.getRegionAttributes() == null) { config.setRegionAttributes(new RegionAttributesType()); } return config.getRegionAttributes(); }
@Test public void subRegionsUnsupported() { regionConfig = new RegionConfig(); assertThatThrownBy(() -> regionConfig.setName("/Parent/Child")) .isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> regionConfig.setName("Parent/Child")) .isInstanceOf(IllegalArgumentException.class); }
/** * 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 boolean removeJdbcMappingFromRegion(RegionConfig regionConfig) { Iterator<CacheElement> iterator = regionConfig.getCustomRegionElements().iterator(); while (iterator.hasNext()) { CacheElement element = iterator.next(); if (element instanceof RegionMapping) { iterator.remove(); return true; } } return false; }
@Test public void createsPartitionedInCache() { RegionConfig config = new RegionConfig(); config.setName("regionName"); config.setType("PARTITION"); RegionConfigRealizer realizer = new RegionConfigRealizer(); realizer.create(config, cache); ArgumentCaptor<DataPolicy> dataPolicyArgumentCaptor = ArgumentCaptor.forClass(DataPolicy.class); verify(regionFactory).setDataPolicy(dataPolicyArgumentCaptor.capture()); assertThat(dataPolicyArgumentCaptor.getValue()).isEqualTo(DataPolicy.PARTITION); verify(regionFactory).create("regionName"); }
private void checkForCacheLoader(String regionName, RegionConfig regionConfig) throws PreconditionException { RegionAttributesType regionAttributes = regionConfig.getRegionAttributes(); if (regionAttributes != null) { DeclarableType loaderDeclarable = regionAttributes.getCacheLoader(); if (loaderDeclarable != null) { throw new PreconditionException("The existing region " + regionName + " must not already have a cache-loader, but it has " + loaderDeclarable.getClassName()); } } }
@Override public String getId() { return getName(); }
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(); }
@Test public void regionConfig() { cacheConfig = new CacheConfig("1.0"); RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("test"); regionConfig.setType("REPLICATE"); RegionAttributesType attributes = new RegionAttributesType(); attributes.setCacheLoader(new DeclarableType("abc.Foo")); regionConfig.setRegionAttributes(attributes); cacheConfig.getRegions().add(regionConfig); // make sure the xml marshed by this config can be validated with xsd String xml = service.marshall(cacheConfig); CacheConfig newCache = service.unMarshall(xml); assertThat(cacheConfig).isEqualToComparingFieldByFieldRecursively(newCache); }
@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\""); } }
RegionConfig deltaConfig = new RegionConfig(); deltaConfig.setName(regionPath); RegionAttributesType regionAttributesType = new RegionAttributesType(); deltaConfig.setRegionAttributes(regionAttributesType); regionAttributesType.setEntryIdleTime(getExpirationAttributes(entryExpirationIdleTime, entryExpirationIdleTimeAction, entryIdleTimeCustomExpiry));
RegionConfig deltaConfig = (RegionConfig) configObject; RegionConfig existingConfig = CacheElement.findElement(cacheConfig.getRegions(), deltaConfig.getId()); RegionAttributesType deltaAttributes = deltaConfig.getRegionAttributes(); RegionAttributesType existingAttributes = existingConfig.getRegionAttributes();
@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 alterRegionWithNullRegionThrowsIllegalArgumentException() { when(cache.getRegion(anyString())).thenReturn(null); config.setName("regionA"); assertThatThrownBy(() -> function.alterRegion(cache, config)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Region does not exist: regionA"); }