List<String> getRegionsThatUseDataSource(CacheConfig cacheConfig, String dataSourceName) { return cacheConfig.getRegions() .stream() .filter(regionConfig -> hasJdbcMappingThatUsesDataSource(regionConfig, dataSourceName)) .map(RegionConfig::getName) .collect(Collectors.toList()); }
public RegionConfig findRegionConfiguration(String regionPath) { if (regionPath.startsWith(SEPARATOR)) { regionPath = regionPath.substring(1); } return findElement(getRegions(), regionPath); }
private RegionConfig findRegionConfig(CacheConfig cacheConfig, String regionName) { return cacheConfig.getRegions().stream() .filter(region -> region.getName().equals(regionName)).findFirst().orElse(null); }
@Override public boolean exists(RegionConfig config, CacheConfig existing) { return CacheElement.exists(existing.getRegions(), config.getId()); }
private void setupRequiredPreconditions() { ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); }
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 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 updateClusterConfigWithNoRegionsDoesNotThrowException() { when(cacheConfig.getRegions()).thenReturn(Collections.emptyList()); boolean modified = destroyRegionMappingCommand.updateConfigForGroup(null, cacheConfig, regionName); assertThat(modified).isFalse(); }
@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 updateClusterConfigWithOneMatchingRegionAddsMappingToRegion() { List<RegionConfig> list = new ArrayList<>(); List<CacheElement> listCacheElements = new ArrayList<>(); when(matchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); assertThat(listCacheElements.size()).isEqualTo(1); assertThat(listCacheElements).contains(mapping); }
@Test public void updateClusterConfigWithSynchronousAndOneMatchingRegionDoesNotCreateAsyncEventQueue() { arguments[1] = true; List<RegionConfig> list = new ArrayList<>(); List<CacheElement> listCacheElements = new ArrayList<>(); when(matchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); List<CacheConfig.AsyncEventQueue> queueList = new ArrayList<>(); when(cacheConfig.getAsyncEventQueues()).thenReturn(queueList); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); assertThat(queueList).isEmpty(); }
@Test public void updateClusterConfigWithNoRegionsDoesNotThrowException() { when(cacheConfig.getRegions()).thenReturn(Collections.emptyList()); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); }
@Test public void updateClusterConfigWithOneMatchingRegionCallsSetCacheLoader() { List<RegionConfig> list = new ArrayList<>(); List<CacheElement> listCacheElements = new ArrayList<>(); when(matchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); List<CacheConfig.AsyncEventQueue> queueList = new ArrayList<>(); when(cacheConfig.getAsyncEventQueues()).thenReturn(queueList); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); verify(matchingRegionAttributes).setCacheLoader(any()); }
@Test public void updateClusterConfigWithSynchronousSetsTheCacheWriterOnTheMatchingRegion() { arguments[1] = true; List<RegionConfig> list = new ArrayList<>(); List<CacheElement> listCacheElements = new ArrayList<>(); when(matchingRegion.getCustomRegionElements()).thenReturn(listCacheElements); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); createRegionMappingCommand.updateConfigForGroup(null, cacheConfig, arguments); verify(matchingRegionAttributes).setCacheWriter(any()); }
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 checkForJDBCMappingWithNoRegionConfigDoesNotThrowException() { setupJDBCMappingOnRegion("regionName"); doReturn(Collections.emptyList()).when(cacheConfig).getRegions(); command.checkForJDBCMapping("regionName"); }
@Test public void indexType() { String xml = cacheXml + regionXml + "<index name=\"indexName\" expression=\"expression\" key-index=\"true\"/>" + "</region></cache>"; cacheConfig = service.unMarshall(xml); RegionConfig.Index index = cacheConfig.getRegions().get(0).getIndexes().get(0); assertThat(index.isKeyIndex()).isTrue(); assertThat(index.getName()).isEqualTo("indexName"); assertThat(index.getExpression()).isEqualTo("expression"); assertThat(index.getType()).isEqualTo("range"); }
@Test public void elementAlreadyExist() throws Exception { regionConfig.setName("test"); CacheConfig cacheConfig = new CacheConfig(); cacheConfig.getRegions().add(regionConfig); when(persistenceService.getCacheConfig("cluster", true)).thenReturn(cacheConfig); assertThatThrownBy(() -> service.create(regionConfig, "cluster")) .isInstanceOf(EntityExistsException.class) .hasMessageContaining("cache element test already exists"); }
@Test public void updateRegionConfig() { service.updateCacheConfig("cluster", cacheConfig -> { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("regionA"); regionConfig.setType("REPLICATE"); cacheConfig.getRegions().add(regionConfig); return cacheConfig; }); System.out.println(configuration.getCacheXmlContent()); assertThat(configuration.getCacheXmlContent()) .contains("<region name=\"regionA\" refid=\"REPLICATE\">"); }
@Test public void checkDefaultRegionAttributesForShortcuts() { RegionShortcut[] shortcuts = RegionShortcut.values(); for (RegionShortcut shortcut : shortcuts) { RegionConfig config = new RegionConfig(); config.setType(shortcut.name()); config.setName(shortcut.name()); RegionConfig masterRegion = CacheElement.findElement(master.getRegions(), shortcut.name()); assertThat(config).isEqualToComparingFieldByFieldRecursively(masterRegion); } }