lowka commented on code in PR #6257:
URL: https://github.com/apache/ignite-3/pull/6257#discussion_r2209915120
##
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 previousRoots,
List currentRoots) {
+Map> previousRootsByKind =
groupByKind(previousRoots);
+Map> 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> entry :
previousRootsByKind.entrySet()) {
+Map prev = entry.getValue();
+Map current =
currentRootsByKind.get(entry.getKey());
+
+compareConfigRoots(prev, current);
+}
+}
+
+private void compareConfigRoots(Map previousRoots,
Map currentRoots) {
+Set 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 e : previousRoots.entrySet()) {
+ConfigNode current = currentRoots.get(e.getKey());
+if (current == null) {
Review Comment:
I should check new roots like:
```
List errors = new ArrayList<>();
for (String key : CollectionUtils.diff(currentRoots, prevousRoot)) {
ConfigNode current = currentRoots.get(key);
Map> paths = buildPaths(current);
validateAdded(paths, paths.keySet(), errors);
}
reportErrors(errors);
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]