aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2021-02-12 16:07:10 +0100
committerHåkon Hallingstad <hakon@verizonmedia.com>2021-02-12 16:07:10 +0100
commita3dd3560a4b1b74e8d05e783db27d94f8ccc384e (patch)
tree7ecf6e6e71f95b31e346c1f4f5feaa9e6779f501 /clustercontroller-core
parent9d588cc3e3b467e6ff046490f32aa48322741754 (diff)
Add test
Diffstat (limited to 'clustercontroller-core')
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java55
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java5
2 files changed, 49 insertions, 11 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java
index eb3261bacaf..8a9cfb4be98 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/SetNodeStateTest.java
@@ -216,7 +216,7 @@ public class SetNodeStateTest extends StateRestApiTest {
@Test
public void testShouldModifyStorageSafeBlocked() throws Exception {
// Sets up 2 groups: [0, 2, 4] and [1, 3, 5]
- setUpBookGroup(6);
+ setUpMusicGroup(6, false);
assertUnitState(1, "user", State.UP, "");
assertSetUnitState(1, State.MAINTENANCE, null);
@@ -224,28 +224,28 @@ public class SetNodeStateTest extends StateRestApiTest {
assertSetUnitState(1, State.MAINTENANCE, null); // sanity-check
// Because 2 is in a different group maintenance should be denied
- assertSetUnitStateCausesAlreadyInMaintenance(2, State.MAINTENANCE);
+ assertSetUnitStateCausesAlreadyInWantedMaintenance(2, State.MAINTENANCE);
// Because 3 and 5 are in the same group as 1, these should be OK
assertSetUnitState(3, State.MAINTENANCE, null);
assertUnitState(1, "user", State.MAINTENANCE, "whatever reason."); // sanity-check
assertUnitState(3, "user", State.MAINTENANCE, "whatever reason."); // sanity-check
assertSetUnitState(5, State.MAINTENANCE, null);
- assertSetUnitStateCausesAlreadyInMaintenance(2, State.MAINTENANCE); // sanity-check
+ assertSetUnitStateCausesAlreadyInWantedMaintenance(2, State.MAINTENANCE); // sanity-check
// Set all to up
assertSetUnitState(1, State.UP, null);
assertSetUnitState(1, State.UP, null); // sanity-check
assertSetUnitState(3, State.UP, null);
- assertSetUnitStateCausesAlreadyInMaintenance(2, State.MAINTENANCE); // sanity-check
+ assertSetUnitStateCausesAlreadyInWantedMaintenance(2, State.MAINTENANCE); // sanity-check
assertSetUnitState(5, State.UP, null);
// Now we should be allowed to upgrade second group, while the first group will be denied
assertSetUnitState(2, State.MAINTENANCE, null);
- assertSetUnitStateCausesAlreadyInMaintenance(1, State.MAINTENANCE); // sanity-check
+ assertSetUnitStateCausesAlreadyInWantedMaintenance(1, State.MAINTENANCE); // sanity-check
assertSetUnitState(0, State.MAINTENANCE, null);
assertSetUnitState(4, State.MAINTENANCE, null);
- assertSetUnitStateCausesAlreadyInMaintenance(1, State.MAINTENANCE); // sanity-check
+ assertSetUnitStateCausesAlreadyInWantedMaintenance(1, State.MAINTENANCE); // sanity-check
// And set second group up again
assertSetUnitState(0, State.MAINTENANCE, null);
@@ -253,6 +253,35 @@ public class SetNodeStateTest extends StateRestApiTest {
assertSetUnitState(4, State.MAINTENANCE, null);
}
+ @Test
+ public void settingSafeMaintenanceWhenNodeAlreadyInMaintenance() throws Exception {
+ // Sets up 2 groups: [0, 2, 4] and [1, 3, 5], with 1 being in maintenance
+ setUpMusicGroup(6, true);
+ assertUnitState(1, "generated", State.MAINTENANCE, "");
+
+ assertUnitState(1, "user", State.UP, "");
+ assertSetUnitState(1, State.MAINTENANCE, null);
+ assertUnitState(1, "user", State.MAINTENANCE, "whatever reason.");
+ assertSetUnitState(1, State.MAINTENANCE, null); // sanity-check
+
+ // Because 2 is in a different group maintenance should be denied
+ assertSetUnitStateCausesAlreadyInMaintenance(2, State.MAINTENANCE);
+
+ // Because 3 and 5 are in the same group as 1, these should be OK
+ assertSetUnitState(3, State.MAINTENANCE, null);
+ assertUnitState(1, "user", State.MAINTENANCE, "whatever reason."); // sanity-check
+ assertUnitState(3, "user", State.MAINTENANCE, "whatever reason."); // sanity-check
+ assertSetUnitState(5, State.MAINTENANCE, null);
+ assertSetUnitStateCausesAlreadyInMaintenance(2, State.MAINTENANCE); // sanity-check
+
+ // Set all to up
+ assertSetUnitState(1, State.UP, null);
+ assertSetUnitState(1, State.UP, null); // sanity-check
+ assertSetUnitState(3, State.UP, null);
+ assertSetUnitStateCausesAlreadyInMaintenance(2, State.MAINTENANCE); // sanity-check
+ assertSetUnitState(5, State.UP, null);
+ }
+
private void assertUnitState(int index, String type, State state, String reason) throws StateRestApiException {
String path = "music/storage/" + index;
UnitResponse response = restAPI.getState(new StateRequest(path, 0));
@@ -276,15 +305,23 @@ public class SetNodeStateTest extends StateRestApiTest {
}
}
+ private void assertSetUnitStateCausesAlreadyInWantedMaintenance(int index, State state) throws StateRestApiException {
+ assertSetUnitStateCausesAlreadyInMaintenance(index, state, "^Another node wants maintenance:([0-9]+)$");
+ }
+
private void assertSetUnitStateCausesAlreadyInMaintenance(int index, State state) throws StateRestApiException {
+ assertSetUnitStateCausesAlreadyInMaintenance(index, state, "^Another node is already in maintenance:([0-9]+)$");
+ }
+
+ private void assertSetUnitStateCausesAlreadyInMaintenance(int index, State state, String reasonRegex)
+ throws StateRestApiException {
SetResponse setResponse = restAPI.setUnitState(new SetUnitStateRequestImpl("music/storage/" + index)
.setNewState("user", state.toString().toLowerCase(), "whatever reason.")
.setCondition(SetUnitStateRequest.Condition.SAFE));
- String regex = "^Another node wants maintenance:([0-9]+)$";
- Matcher matcher = Pattern.compile(regex).matcher(setResponse.getReason());
+ Matcher matcher = Pattern.compile(reasonRegex).matcher(setResponse.getReason());
- String errorMessage = "Expected reason to match '" + regex + "', but got: " + setResponse.getReason() + "'";
+ String errorMessage = "Expected reason to match '" + reasonRegex + "', but got: " + setResponse.getReason() + "'";
assertTrue(errorMessage, matcher.find());
int alreadyMaintainedIndex = Integer.parseInt(matcher.group(1));
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java
index 4ef6c587348..4d079ec782f 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/StateRestApiTest.java
@@ -98,7 +98,7 @@ public abstract class StateRestApiTest {
}, ccSockets);
}
- protected void setUpBookGroup(int nodeCount) {
+ protected void setUpMusicGroup(int nodeCount, boolean node1InMaintenance) {
books = null;
Distribution distribution = new Distribution(Distribution.getSimpleGroupConfig(2, nodeCount));
jsonWriter.setDefaultPathPrefix("/cluster/v2");
@@ -106,7 +106,8 @@ public abstract class StateRestApiTest {
"music", distribution.getNodes(), distribution, 0 /* minStorageNodesUp*/, 0.0 /* minRatioOfStorageNodesUp */);
initializeCluster(cluster, distribution.getNodes());
AnnotatedClusterState baselineState = AnnotatedClusterState
- .withoutAnnotations(ClusterState.stateFromString("distributor:" + nodeCount + " storage:" + nodeCount));
+ .withoutAnnotations(ClusterState.stateFromString("distributor:" + nodeCount + " storage:" + nodeCount +
+ (node1InMaintenance ? " .1.s:m" : "")));
Map<String, AnnotatedClusterState> bucketSpaceStates = new HashMap<>();
bucketSpaceStates.put("default", AnnotatedClusterState
.withoutAnnotations(ClusterState.stateFromString("distributor:" + nodeCount + " storage:" + nodeCount)));