AMashenkov commented on code in PR #6241: URL: https://github.com/apache/ignite-3/pull/6241#discussion_r2209903906
########## modules/runner/src/test/java/org/apache/ignite/internal/configuration/compatibility/framework/Comp2.java: ########## @@ -0,0 +1,447 @@ +package org.apache.ignite.internal.configuration.compatibility.framework; + +import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.stream.Collectors; +import org.apache.ignite.internal.configuration.compatibility.GenerateConfigurationSnapshot; +import org.apache.ignite.internal.configuration.compatibility.framework.ConfigNode.NodeReference; +import org.apache.ignite.internal.configuration.compatibility.framework.ConfigurationTreeComparator.ComparisonContext; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.util.CollectionUtils; + +public class Comp2 { + + private static final IgniteLogger LOG = Loggers.forClass(GenerateConfigurationSnapshot.class); + + private final ComparisonContext comparisonContext; + + public Comp2() { + this.comparisonContext = new ComparisonContext(); + } + + public Comp2(ComparisonContext comparisonContext) { + this.comparisonContext = comparisonContext; + } + + public void ensureCompatible(List<ConfigNode> previousRoots, List<ConfigNode> currentRoots) { + Map<String, Map<String, ConfigNode>> previousRootsByKind = groupByKind(previousRoots); + Map<String, Map<String, ConfigNode>> currentRootsByKind = groupByKind(currentRoots); + + // Compare configuration kinds + if (!previousRootsByKind.keySet().equals(currentRootsByKind.keySet())) { + String error = format("Configuration kind do not match. Expected: {} but got {}", + previousRootsByKind.keySet(), + currentRootsByKind.keySet() + ); + + throw new IllegalStateException(error); + } + + // Then compare roots one by one + for (Entry<String, Map<String, ConfigNode>> entry : previousRootsByKind.entrySet()) { + Map<String, ConfigNode> prev = entry.getValue(); + Map<String, ConfigNode> current = currentRootsByKind.get(entry.getKey()); + + compareConfigRoots(prev, current); + } + } + + private void compareConfigRoots(Map<String, ConfigNode> previousRoots, Map<String, ConfigNode> currentRoots) { + Set<String> removed = CollectionUtils.difference(previousRoots.keySet(), currentRoots.keySet()); + + // Check config roots + if (!removed.isEmpty()) { + String error = format("Incompatible change. Some of the root keys has been removed.\n" + + "Removed root keys: {}\n" + + "Previous root keys: {}\n" + + "Current root keys: {}\n", + removed, previousRoots.keySet(), currentRoots.keySet()); + + throw new IllegalStateException(error); + } + + for (Map.Entry<String, ConfigNode> e : previousRoots.entrySet()) { + ConfigNode current = currentRoots.get(e.getKey()); + if (current == null) { + // adding a configuration root is a compatible change. + continue; + } Review Comment: ```suggestion ``` We get into this branch when previousRoot wasn't found among current ones (actually, it was removed, not added). However, we already check the case few lines above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org