InternalConfigurationPersistenceService implements ConfigurationPersistenceService { @Override public void updateCacheConfig(String group, UnaryOperator<CacheConfig> mutator) { if (group == null) { group = CLUSTER_CONFIG; } lockSharedConfiguration(); try { CacheConfig cacheConfig = getCacheConfig(group, true); cacheConfig = mutator.apply(cacheConfig); if (cacheConfig == null) { return; } Configuration configuration = getConfiguration(group); if (configuration == null) { configuration = new Configuration(group); } configuration.setCacheXmlContent(jaxbService.marshall(cacheConfig)); getConfigurationRegion().put(group, configuration); } finally { unlockSharedConfiguration(); } } InternalConfigurationPersistenceService(InternalCache cache, Path workingDirectory,
      JAXBService jaxbService); @VisibleForTesting  InternalConfigurationPersistenceService(JAXBService jaxbService); @VisibleForTesting  InternalConfigurationPersistenceService(InternalCache cache,
      DistributedLockService sharedConfigLockingService, JAXBService jaxbService,
      Path configDirPath, Path configDiskDirPath); JAXBService getJaxbService(); void addXmlEntity(XmlEntity xmlEntity, String[] groups); void deleteXmlEntity(XmlEntity xmlEntity, String[] groups); void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups); void addJarsToThisLocator(List<String> jarFullPaths, String[] groups); boolean removeJars(String[] jarNames, String[] groups); void downloadJarFromOtherLocators(String groupName, String jarName); void downloadJarFromLocator(String groupName, String jarName,
      DistributedMember sourceLocator); File downloadJar(DistributedMember locator, String groupName, String jarName); ConfigurationResponse createConfigurationResponse(Set<String> groups); void destroySharedConfiguration(); Path getPathToJarOnThisLocator(String groupName, String jarName); Configuration getConfiguration(String groupName); void setConfiguration(String groupName, Configuration configuration); boolean hasXmlConfiguration(); Map<String, Configuration> getEntireConfiguration(); Set<String> getGroups(); Path getClusterConfigDirPath(); SharedConfigurationStatus getStatus(); void loadSharedConfigurationFromDir(File configDir); void writeConfigToFile(Configuration configuration, File rootDir); boolean lockSharedConfiguration(); void unlockSharedConfiguration(); Region<String, Configuration> getConfigurationRegion(); @Override CacheConfig getCacheConfig(String group); @Override CacheConfig getCacheConfig(String group, boolean createNew); @Override void updateCacheConfig(String group, UnaryOperator<CacheConfig> mutator); static final String CLUSTER_CONFIG_ARTIFACTS_DIR_NAME; static final String CLUSTER_CONFIG_DISK_DIR_PREFIX; static final String CONFIG_REGION_NAME; }
@Test public void updateRegionConfig() { service.updateCacheConfig("cluster", cacheConfig -> { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("regionA"); regionConfig.setType(RegionType.REPLICATE); cacheConfig.getRegions().add(regionConfig); return cacheConfig; }); System.out.println(configuration.getCacheXmlContent()); assertThat(configuration.getCacheXmlContent()) .contains("<region name=\"regionA\" refid=\"REPLICATE\""); }
@Test public void jndiBindings() { service.updateCacheConfig("cluster", cacheConfig -> { JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding(); jndiBinding.setJndiName("jndiOne"); jndiBinding.setJdbcDriverClass("com.sun.ABC"); jndiBinding.setType("SimpleDataSource"); jndiBinding.getConfigProperties() .add(new JndiBindingsType.JndiBinding.ConfigProperty("test", "test", "test")); cacheConfig.getJndiBindings().add(jndiBinding); return cacheConfig; }); assertThat(configuration.getCacheXmlContent()).containsOnlyOnce("</jndi-bindings>"); assertThat(configuration.getCacheXmlContent()).contains( "<jndi-binding jdbc-driver-class=\"com.sun.ABC\" jndi-name=\"jndiOne\" type=\"SimpleDataSource\">"); assertThat(configuration.getCacheXmlContent()) .contains("config-property-name>test</config-property-name>"); }
@Test public void addCustomCacheElement() { ElementOne customOne = new ElementOne("testOne"); service.updateCacheConfig("cluster", config -> { config.getCustomCacheElements().add(customOne); return config; }); System.out.println(configuration.getCacheXmlContent()); assertThat(configuration.getCacheXmlContent()).contains("custom-one>"); JAXBServiceTest.ElementTwo customTwo = new ElementTwo("testTwo"); service.updateCacheConfig("cluster", config -> { config.getCustomCacheElements().add(customTwo); return config; }); System.out.println(configuration.getCacheXmlContent()); assertThat(configuration.getCacheXmlContent()).contains("custom-one>"); assertThat(configuration.getCacheXmlContent()).contains("custom-two>"); }
@Test public void updateGatewayReceiverConfig() { service.updateCacheConfig("cluster", cacheConfig -> { GatewayReceiverConfig receiver = new GatewayReceiverConfig(); cacheConfig.setGatewayReceiver(receiver); return cacheConfig; }); System.out.println(configuration.getCacheXmlContent()); assertThat(configuration.getCacheXmlContent()).contains("<gateway-receiver/>"); }