summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2022-08-18 09:41:36 +0200
committerHarald Musum <musum@yahooinc.com>2022-08-23 14:01:11 +0200
commitfaa612ab2e63a7ba9160d90c90d1c9e9429ecacf (patch)
tree922d8e2bc82f4ccf2ff3d6274d3093e4fc5befaa /clustercontroller-core
parent41f4a0eff08f40023b9f4dff5364dea84799fc19 (diff)
Clean up a bit
Diffstat (limited to 'clustercontroller-core')
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/WaitCondition.java77
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 */