InternalConfigurationPersistenceService implements ConfigurationPersistenceService { void removeInvalidXmlConfigurations(Region<String, Configuration> configRegion) throws IOException { for (Map.Entry<String, Configuration> entry : configRegion.entrySet()) { String group = entry.getKey(); Configuration configuration = entry.getValue(); String configurationXml = configuration.getCacheXmlContent(); if (configurationXml != null && !configurationXml.isEmpty()) { try { Document document = XmlUtils.createDocumentFromXml(configurationXml); boolean removedInvalidReceivers = removeInvalidGatewayReceivers(document); boolean removedDuplicateReceivers = removeDuplicateGatewayReceivers(document); if (removedInvalidReceivers || removedDuplicateReceivers) { configuration.setCacheXmlContent(XmlUtils.prettyXml(document)); configRegion.put(group, configuration); } } catch (SAXException | TransformerException | ParserConfigurationException e) { throw new IOException("Unable to parse existing cluster configuration from disk. ", e); } } } } 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 @Parameters(method = "getXmlAndExpectedElements") public void removeInvalidXmlConfiguration(String xml, int expectedInitialElements, int expectFinalElements) throws Exception { Region<String, Configuration> configurationRegion = mock(Region.class); configuration.setCacheXmlContent(xml); System.out.println( "Initial xml content:" + System.lineSeparator() + configuration.getCacheXmlContent()); Document document = XmlUtils.createDocumentFromXml(configuration.getCacheXmlContent()); assertThat(document.getElementsByTagName("gateway-receiver").getLength()) .isEqualTo(expectedInitialElements); Set<Map.Entry<String, Configuration>> configurationEntries = new HashSet<>(); configurationEntries.add(new AbstractMap.SimpleEntry<>("cluster", configuration)); doReturn(configurationEntries).when(configurationRegion).entrySet(); service.removeInvalidXmlConfigurations(configurationRegion); System.out.println( "Processed xml content:" + System.lineSeparator() + configuration.getCacheXmlContent()); document = XmlUtils.createDocumentFromXml(configuration.getCacheXmlContent()); assertThat(document.getElementsByTagName("gateway-receiver").getLength()) .isEqualTo(expectFinalElements); }