lowka commented on code in PR #6305: URL: https://github.com/apache/ignite-3/pull/6305#discussion_r2228239516
########## modules/runner/src/test/java/org/apache/ignite/internal/configuration/compatibility/framework/ConfigurationTreeComparator.java: ########## @@ -232,12 +149,182 @@ public static ComparisonContext create(Set<ConfigurationModule> configurationMod private final KeyIgnorer deletedItems; + private final List<String> errors = new ArrayList<>(); + ComparisonContext(Collection<String> deletedPrefixes) { this.deletedItems = KeyIgnorer.fromDeletedPrefixes(deletedPrefixes); } boolean shouldIgnore(String path) { return deletedItems.shouldIgnore(path); } + + void reset() { + errors.clear(); + } + + void addError(Node node, String error) { + reportError(node.path(), error); + } + + void addError(ConfigNode node, String error) { + reportError(node.path(), error); + } + + private void reportError(String path, String error) { + String message = format("Node: {}: {}", path, error); + errors.add(message); + } + + private void throwIfNotEmpty() { + if (errors.isEmpty()) { + return; + } + + StringBuilder message = new StringBuilder("There are incompatible changes:").append(System.lineSeparator()); + for (String error : errors) { + message.append('\t').append(error).append(System.lineSeparator()); + } + + throw new IllegalStateException(message.toString()); + } + } + + + private static void compareRoots(List<ConfigNode> roots1, List<ConfigNode> roots2, ComparisonContext context) { + List<ConfigNode> removed = new ArrayList<>(); + List<ConfigNode> added = new ArrayList<>(); + List<ConfigNode> copy2 = new ArrayList<>(roots2); + + for (ConfigNode root1 : roots1) { + boolean matchFound = false; + + for (ConfigNode root2 : new ArrayList<>(copy2)) { + if (rootsMatch(root1, root2)) { + copy2.remove(root2); + validate(root1, root2, context); + matchFound = true; + break; + } + } + + if (!matchFound) { + removed.add(root1); + } + } + + added.addAll(copy2); + + // Validate new roots + validateNew(added, context); + // Reject removed roots. + validateRemoved(removed, context); + } + + private static boolean rootsMatch(ConfigNode a, ConfigNode b) { + boolean nameMatches = Objects.equals(a.name(), b.name()); + boolean kindMatches = Objects.equals(a.kind(), b.kind()); + return nameMatches && kindMatches; + } + + private static void validate(Node a, Node b, ComparisonContext context) { + compareNodes(a.node(), b.node(), context); + } + + private static void validate(ConfigNode candidate, ConfigNode current, ComparisonContext context) { + if (!context.errors.isEmpty()) { + return; + } + compareNodes(candidate, current, context); Review Comment: Thanks, fixed. -- 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