diff options
author | Harald Musum <musum@yahooinc.com> | 2022-08-18 09:41:36 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-08-18 09:41:36 +0200 |
commit | 675463f4e421d074e84abedd91117818adf40d51 (patch) | |
tree | 41ad08796ce62f03d0ea249cc80d43b12ce3340b | |
parent | 935fa8d17872cc6c35b65cc44ed6c6985ab3f448 (diff) |
Clean up a bit
-rw-r--r-- | clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/WaitCondition.java | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/WaitCondition.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/WaitCondition.java index d6d3e2876a5..deccaf282d6 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/WaitCondition.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/WaitCondition.java @@ -9,11 +9,10 @@ import com.yahoo.vespa.clustercontroller.core.ClusterStateBundle; import com.yahoo.vespa.clustercontroller.core.DummyVdsNode; import com.yahoo.vespa.clustercontroller.core.FleetController; import com.yahoo.vespa.clustercontroller.core.listeners.SystemStateListener; - import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -65,10 +64,10 @@ public interface WaitCondition { class RegexStateMatcher extends StateWait { private final Pattern pattern; - private Collection<DummyVdsNode> nodesToCheck; + private Collection<DummyVdsNode> nodesToCheck = Set.of(); private ClusterState lastCheckedState; private boolean checkAllSpaces = false; - private Set<String> checkSpaceSubset = Collections.emptySet(); + private Set<String> checkSpaceSubset = Set.of(); RegexStateMatcher(String regex, FleetController fc, Object monitor) { super(fc, monitor); @@ -76,6 +75,7 @@ public interface WaitCondition { } RegexStateMatcher includeNotifyingNodes(Collection<DummyVdsNode> nodes) { + Objects.requireNonNull(nodes, "nodes must be non-null"); nodesToCheck = nodes; return this; } @@ -86,6 +86,7 @@ public interface WaitCondition { } RegexStateMatcher checkSpaceSubset(Set<String> spaces) { + Objects.requireNonNull(spaces, "spaces must be non-null"); this.checkSpaceSubset = spaces; return this; } @@ -99,45 +100,39 @@ public interface WaitCondition { @Override public String isConditionMet() { - if (convergedState != null) { - lastCheckedState = convergedState; - Matcher m = pattern.matcher(lastCheckedState.toString()); - if (m.matches() || !checkSpaceSubset.isEmpty()) { - if (nodesToCheck != null) { - for (DummyVdsNode node : nodesToCheck) { - if (node.getClusterState() == null) { - return "Node " + node + " has not received a cluster state yet"; - } - // TODO refactor, simplify - boolean match; - if (checkAllSpaces) { - match = statesInBundle(node.getClusterStateBundle()).stream() - .allMatch(state -> pattern.matcher(withoutTimestamps(state.toString())).matches()); - } else if (!checkSpaceSubset.isEmpty()) { - match = checkSpaceSubset.stream().allMatch(space -> { - String state = node.getClusterStateBundle().getDerivedBucketSpaceStates() - .getOrDefault(space, AnnotatedClusterState.emptyState()).getClusterState().toString(); - return pattern.matcher(withoutTimestamps(state)).matches(); - }); - } else { - match = pattern.matcher(withoutTimestamps(node.getClusterState().toString())).matches(); - } - - if (!match) { - return "Node " + node + " state mismatch.\n wanted: " + pattern + "\n is: " + node.getClusterStateBundle().toString(); - } - if (node.getStateCommunicationVersion() > 0) { - if (!node.hasPendingGetNodeStateRequest()) { - return "Node " + node + " has not received another get node state request yet"; - } - } - } - } - return null; + if (convergedState == null) return "No cluster state defined yet"; + + lastCheckedState = convergedState; + Matcher m = pattern.matcher(lastCheckedState.toString()); + if (!m.matches() && checkSpaceSubset.isEmpty()) return "Cluster state mismatch"; + + for (DummyVdsNode node : nodesToCheck) { + if (node.getClusterState() == null) return "Node " + node + " has not received a cluster state yet"; + + boolean match; + if (checkAllSpaces) { + match = statesInBundle(node.getClusterStateBundle()).stream() + .allMatch(state -> pattern + .matcher(withoutTimestamps(state.toString())) + .matches()); + } else if (!checkSpaceSubset.isEmpty()) { + match = checkSpaceSubset.stream().allMatch(space -> { + String state = node.getClusterStateBundle().getDerivedBucketSpaceStates() + .getOrDefault(space, AnnotatedClusterState.emptyState()).getClusterState().toString(); + return pattern.matcher(withoutTimestamps(state)).matches(); + }); + } else { + match = pattern.matcher(withoutTimestamps(node.getClusterState().toString())).matches(); + } + + if (!match) { + return "Node " + node + " state mismatch.\n wanted: " + pattern + "\n is: " + node.getClusterStateBundle().toString(); + } + if (node.getStateCommunicationVersion() > 0 && !node.hasPendingGetNodeStateRequest()) { + return "Node " + node + " has not received another get node state request yet"; } - return "Cluster state mismatch"; } - return "No cluster state defined yet"; + return null; } /** Returns the given state string with timestamps removed */ |