diff options
Diffstat (limited to 'clustercontroller-core/src')
7 files changed, 437 insertions, 343 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterListTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterListTest.java index 8e49703c94b..80fa5098472 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterListTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterListTest.java @@ -12,58 +12,80 @@ public class ClusterListTest extends StateRestApiTest { void testClusterList() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("", 0)); - String expected = - "{\"cluster\": {\n" + - " \"books\": {\"link\": \"\\/cluster\\/v2\\/books\"},\n" + - " \"music\": {\"link\": \"\\/cluster\\/v2\\/music\"}\n" + - "}}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "cluster" : { + "books" : { + "link" : "/cluster/v2/books" + }, + "music" : { + "link" : "/cluster/v2/music" + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } @Test void testRecursiveClusterList() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("", 1)); - String expected = - "{\"cluster\": {\n" + - " \"books\": {\n" + - " \"state\": {\"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"service\": {\n" + - " \"storage\": {\"link\": \"\\/cluster\\/v2\\/books\\/storage\"},\n" + - " \"distributor\": {\"link\": \"\\/cluster\\/v2\\/books\\/distributor\"}\n" + - " },\n" + - " \"distribution-states\": {\"published\": {\n" + - " \"baseline\": \"distributor:4 storage:4\",\n" + - " \"bucket-spaces\": [\n" + - " {\n" + - " \"name\": \"default\",\n" + - " \"state\": \"distributor:4 storage:4 .3.s:m\"\n" + - " },\n" + - " {\n" + - " \"name\": \"global\",\n" + - " \"state\": \"distributor:4 storage:4\"\n" + - " }\n" + - " ]\n" + - " }}\n" + - " },\n" + - " \"music\": {\n" + - " \"state\": {\"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"service\": {\n" + - " \"storage\": {\"link\": \"\\/cluster\\/v2\\/music\\/storage\"},\n" + - " \"distributor\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\"}\n" + - " },\n" + - " \"distribution-states\": {\"published\": {\n" + - " \"baseline\": \"distributor:8 .0.s:d .2.s:d .4.s:d .6.s:d storage:8 .0.s:d .2.s:d .4.s:d .6.s:d\",\n" + - " \"bucket-spaces\": []\n" + - " }}\n" + - " }\n" + - "}}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "cluster" : { + "books" : { + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + } + }, + "service" : { + "storage" : { + "link" : "/cluster/v2/books/storage" + }, + "distributor" : { + "link" : "/cluster/v2/books/distributor" + } + }, + "distribution-states" : { + "published" : { + "baseline" : "distributor:4 storage:4", + "bucket-spaces" : [ { + "name" : "default", + "state" : "distributor:4 storage:4 .3.s:m" + }, { + "name" : "global", + "state" : "distributor:4 storage:4" + } ] + } + } + }, + "music" : { + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + } + }, + "service" : { + "storage" : { + "link" : "/cluster/v2/music/storage" + }, + "distributor" : { + "link" : "/cluster/v2/music/distributor" + } + }, + "distribution-states" : { + "published" : { + "baseline" : "distributor:8 .0.s:d .2.s:d .4.s:d .6.s:d storage:8 .0.s:d .2.s:d .4.s:d .6.s:d", + "bucket-spaces" : [ ] + } + } + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } + } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterTest.java index ab9c92a6d9e..1f794fc6bce 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ClusterTest.java @@ -12,64 +12,97 @@ public class ClusterTest extends StateRestApiTest { void testCluster() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("books", 0)); - String expected = - "{\n" + - " \"state\": {\"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"service\": {\n" + - " \"storage\": {\"link\": \"\\/cluster\\/v2\\/books\\/storage\"},\n" + - " \"distributor\": {\"link\": \"\\/cluster\\/v2\\/books\\/distributor\"}\n" + - " },\n" + - " \"distribution-states\": {\"published\": {\n" + - " \"baseline\": \"distributor:4 storage:4\",\n" + - " \"bucket-spaces\": [\n" + - " {\n" + - " \"name\": \"default\",\n" + - " \"state\": \"distributor:4 storage:4 .3.s:m\"\n" + - " },\n" + - " {\n" + - " \"name\": \"global\",\n" + - " \"state\": \"distributor:4 storage:4\"\n" + - " }\n" + - " ]\n" + - " }}\n" + - "}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + } + }, + "service" : { + "storage" : { + "link" : "/cluster/v2/books/storage" + }, + "distributor" : { + "link" : "/cluster/v2/books/distributor" + } + }, + "distribution-states" : { + "published" : { + "baseline" : "distributor:4 storage:4", + "bucket-spaces" : [ { + "name" : "default", + "state" : "distributor:4 storage:4 .3.s:m" + }, { + "name" : "global", + "state" : "distributor:4 storage:4" + } ] + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } @Test void testRecursiveCluster() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("music", 1)); - String expected = - "{\n" + - " \"state\": {\"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"service\": {\n" + - " \"storage\": {\"node\": {\n" + - " \"1\": {\"link\": \"\\/cluster\\/v2\\/music\\/storage\\/1\"},\n" + - " \"2\": {\"link\": \"\\/cluster\\/v2\\/music\\/storage\\/2\"},\n" + - " \"3\": {\"link\": \"\\/cluster\\/v2\\/music\\/storage\\/3\"},\n" + - " \"5\": {\"link\": \"\\/cluster\\/v2\\/music\\/storage\\/5\"},\n" + - " \"7\": {\"link\": \"\\/cluster\\/v2\\/music\\/storage\\/7\"}\n" + - " }},\n" + - " \"distributor\": {\"node\": {\n" + - " \"1\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/1\"},\n" + - " \"2\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/2\"},\n" + - " \"3\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/3\"},\n" + - " \"5\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/5\"},\n" + - " \"7\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/7\"}\n" + - " }}\n" + - " },\n" + - " \"distribution-states\": {\"published\": {\n" + - " \"baseline\": \"distributor:8 .0.s:d .2.s:d .4.s:d .6.s:d storage:8 .0.s:d .2.s:d .4.s:d .6.s:d\",\n" + - " \"bucket-spaces\": []\n" + - " }}\n" + - "}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + } + }, + "service" : { + "storage" : { + "node" : { + "1" : { + "link" : "/cluster/v2/music/storage/1" + }, + "2" : { + "link" : "/cluster/v2/music/storage/2" + }, + "3" : { + "link" : "/cluster/v2/music/storage/3" + }, + "5" : { + "link" : "/cluster/v2/music/storage/5" + }, + "7" : { + "link" : "/cluster/v2/music/storage/7" + } + } + }, + "distributor" : { + "node" : { + "1" : { + "link" : "/cluster/v2/music/distributor/1" + }, + "2" : { + "link" : "/cluster/v2/music/distributor/2" + }, + "3" : { + "link" : "/cluster/v2/music/distributor/3" + }, + "5" : { + "link" : "/cluster/v2/music/distributor/5" + }, + "7" : { + "link" : "/cluster/v2/music/distributor/7" + } + } + } + }, + "distribution-states" : { + "published" : { + "baseline" : "distributor:8 .0.s:d .2.s:d .4.s:d .6.s:d storage:8 .0.s:d .2.s:d .4.s:d .6.s:d", + "bucket-spaces" : [ ] + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NodeTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NodeTest.java index 39a2e22f6c5..53756e9be22 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NodeTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NodeTest.java @@ -17,88 +17,91 @@ public class NodeTest extends StateRestApiTest { void testDistributor() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("music/distributor/1", 0)); - String expected = - """ - { - "attributes": {"hierarchical-group": "east.g2"}, - "state": { - "generated": { - "state": "up", - "reason": "" - }, - "unit": { - "state": "up", - "reason": "" - }, - "user": { - "state": "up", - "reason": "" - } - } - }"""; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + }, + "unit" : { + "state" : "up", + "reason" : "" + }, + "user" : { + "state" : "up", + "reason" : "" + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } @Test void testStorage() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("music/storage/1", 0)); - String expected = - """ - { - "attributes": {"hierarchical-group": "east.g2"}, - "state": { - "generated": { - "state": "up", - "reason": "" - }, - "unit": { - "state": "up", - "reason": "" - }, - "user": { - "state": "up", - "reason": "" - } - }, - "metrics": { - "bucket-count": 1, - "unique-document-count": 2, - "unique-document-total-size": 3 - } - }"""; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + }, + "unit" : { + "state" : "up", + "reason" : "" + }, + "user" : { + "state" : "up", + "reason" : "" + } + }, + "metrics" : { + "bucket-count" : 1, + "unique-document-count" : 2, + "unique-document-total-size" : 3 + } + }""", + jsonWriter.createJson(response).toPrettyString()); } @Test void testRecursiveNode() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("music/storage/1", 1)); - String expected = - """ - { - "attributes": {"hierarchical-group": "east.g2"}, - "state": { - "generated": { - "state": "up", - "reason": "" - }, - "unit": { - "state": "up", - "reason": "" - }, - "user": { - "state": "up", - "reason": "" - } - }, - "metrics": { - "bucket-count": 1, - "unique-document-count": 2, - "unique-document-total-size": 3 - } - }"""; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + }, + "unit" : { + "state" : "up", + "reason" : "" + }, + "user" : { + "state" : "up", + "reason" : "" + } + }, + "metrics" : { + "bucket-count" : 1, + "unique-document-count" : 2, + "unique-document-total-size" : 3 + } + }""", + jsonWriter.createJson(response).toPrettyString()); } @Test @@ -110,26 +113,26 @@ public class NodeTest extends StateRestApiTest { currentState.setDescription("Not seen"); music.context.currentConsolidatedState.setNodeState(new Node(NodeType.STORAGE, 1), currentState); UnitResponse response = restAPI.getState(new StateRequest("music/storage/1", 0)); - String expected = - """ - { - "attributes": {"hierarchical-group": "east.g2"}, - "state": { - "generated": { - "state": "down", - "reason": "Not seen" - }, - "unit": { - "state": "down", - "reason": "Node not seen in slobrok." - }, - "user": { - "state": "up", - "reason": "" - } - } - }"""; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "down", + "reason" : "Not seen" + }, + "unit" : { + "state" : "down", + "reason" : "Node not seen in slobrok." + }, + "user" : { + "state" : "up", + "reason" : "" + } + } + }""", jsonWriter.createJson(response).toPrettyString()); } } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NotMasterTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NotMasterTest.java index 3beeecf8dc4..912bd34c33a 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NotMasterTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/NotMasterTest.java @@ -20,12 +20,17 @@ public class NotMasterTest extends StateRestApiTest { // Non-recursive cluster list works, as it doesn't touches into fleetcontrollers { UnitResponse response = restAPI.getState(new StateRequest("", 0)); - String expected = - "{\"cluster\": {\n" + - " \"books\": {\"link\": \"\\/cluster\\/v2\\/books\"},\n" + - " \"music\": {\"link\": \"\\/cluster\\/v2\\/music\"}\n" + - "}}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "cluster" : { + "books" : { + "link" : "/cluster/v2/books" + }, + "music" : { + "link" : "/cluster/v2/music" + } + } + }""", jsonWriter.createJson(response).toPrettyString()); } // Recursive cluster list does not work try { @@ -70,12 +75,18 @@ public class NotMasterTest extends StateRestApiTest { // Non-recursive cluster list works, as it doesn't touches into fleetcontrollers { UnitResponse response = restAPI.getState(new StateRequest("", 0)); - String expected = - "{\"cluster\": {\n" + - " \"books\": {\"link\": \"\\/cluster\\/v2\\/books\"},\n" + - " \"music\": {\"link\": \"\\/cluster\\/v2\\/music\"}\n" + - "}}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "cluster" : { + "books" : { + "link" : "/cluster/v2/books" + }, + "music" : { + "link" : "/cluster/v2/music" + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } // Recursive cluster list does not work try { diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ServiceTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ServiceTest.java index 2e5b610a039..8d1bdb021da 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ServiceTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/restapiv2/ServiceTest.java @@ -12,109 +12,133 @@ public class ServiceTest extends StateRestApiTest { void testService() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("music/distributor", 0)); - String expected = - "{\"node\": {\n" + - " \"1\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/1\"},\n" + - " \"2\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/2\"},\n" + - " \"3\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/3\"},\n" + - " \"5\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/5\"},\n" + - " \"7\": {\"link\": \"\\/cluster\\/v2\\/music\\/distributor\\/7\"}\n" + - "}}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "node" : { + "1" : { + "link" : "/cluster/v2/music/distributor/1" + }, + "2" : { + "link" : "/cluster/v2/music/distributor/2" + }, + "3" : { + "link" : "/cluster/v2/music/distributor/3" + }, + "5" : { + "link" : "/cluster/v2/music/distributor/5" + }, + "7" : { + "link" : "/cluster/v2/music/distributor/7" + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } @Test void testRecursiveCluster() throws Exception { setUp(true); UnitResponse response = restAPI.getState(new StateRequest("music/distributor", 1)); - String expected = - "{\"node\": {\n" + - " \"1\": {\n" + - " \"attributes\": {\"hierarchical-group\": \"east.g2\"},\n" + - " \"state\": {\n" + - " \"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"unit\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"user\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }\n" + - " }\n" + - " },\n" + - " \"2\": {\n" + - " \"attributes\": {\"hierarchical-group\": \"east.g1\"},\n" + - " \"state\": {\n" + - " \"generated\": {\n" + - " \"state\": \"down\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"unit\": {\n" + - " \"state\": \"down\",\n" + - " \"reason\": \"Node not seen in slobrok.\"\n" + - " },\n" + - " \"user\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }\n" + - " }\n" + - " },\n" + - " \"3\": {\n" + - " \"attributes\": {\"hierarchical-group\": \"east.g2\"},\n" + - " \"state\": {\n" + - " \"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"unit\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"user\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }\n" + - " }\n" + - " },\n" + - " \"5\": {\n" + - " \"attributes\": {\"hierarchical-group\": \"east.g2\"},\n" + - " \"state\": {\n" + - " \"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"unit\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"user\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }\n" + - " }\n" + - " },\n" + - " \"7\": {\n" + - " \"attributes\": {\"hierarchical-group\": \"east.g2\"},\n" + - " \"state\": {\n" + - " \"generated\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"unit\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"user\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }\n" + - " }\n" + - " }\n" + - "}}"; - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "node" : { + "1" : { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + }, + "unit" : { + "state" : "up", + "reason" : "" + }, + "user" : { + "state" : "up", + "reason" : "" + } + } + }, + "2" : { + "attributes" : { + "hierarchical-group" : "east.g1" + }, + "state" : { + "generated" : { + "state" : "down", + "reason" : "" + }, + "unit" : { + "state" : "down", + "reason" : "Node not seen in slobrok." + }, + "user" : { + "state" : "up", + "reason" : "" + } + } + }, + "3" : { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + }, + "unit" : { + "state" : "up", + "reason" : "" + }, + "user" : { + "state" : "up", + "reason" : "" + } + } + }, + "5" : { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + }, + "unit" : { + "state" : "up", + "reason" : "" + }, + "user" : { + "state" : "up", + "reason" : "" + } + } + }, + "7" : { + "attributes" : { + "hierarchical-group" : "east.g2" + }, + "state" : { + "generated" : { + "state" : "up", + "reason" : "" + }, + "unit" : { + "state" : "up", + "reason" : "" + }, + "user" : { + "state" : "up", + "reason" : "" + } + } + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } } 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 33a962a532d..131b011df48 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 @@ -107,7 +107,7 @@ public class SetNodeStateTest extends StateRestApiTest { "music/distributor/1").setNewState("user", state, reason)); UnitResponse response = restAPI.getState(new StateRequest("music/distributor/1", 0)); String expected = musicClusterExpectedUserStateString("east.g2", "up", "up", state.toLowerCase(), reason); - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(expected, jsonWriter.createJson(response).toPrettyString()); } private void verifyClusterSet(String state, String reason) throws Exception { @@ -121,48 +121,29 @@ public class SetNodeStateTest extends StateRestApiTest { } } - private String musicClusterExpectedUserStateStringWithUninitializedNode(String groupName, - String generatedState, String unitState, - String userState, String userReason) { - return "{\n" + - " \"attributes\": {\"hierarchical-group\": \"" + groupName + "\"},\n" + - " \"state\": {\n" + - " \"generated\": {\n" + - " \"state\": \"" + generatedState + "\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"unit\": {\n" + - " \"state\": \"" + unitState + "\",\n" + - " \"reason\": \"Node not seen in slobrok.\"\n" + - " },\n" + - " \"user\": {\n" + - " \"state\": \"" + userState + "\",\n" + - " \"reason\": \"" + userReason + "\"\n" + - " }\n" + - " }\n" + - "}"; - } - private String musicClusterExpectedUserStateString(String groupName, String generatedState, String unitState, String userState, String userReason) { - return "{\n" + - " \"attributes\": {\"hierarchical-group\": \"" + groupName + "\"},\n" + - " \"state\": {\n" + - " \"generated\": {\n" + - " \"state\": \"" + generatedState + "\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"unit\": {\n" + - " \"state\": \"" + unitState + "\",\n" + - " \"reason\": \"\"\n" + - " },\n" + - " \"user\": {\n" + - " \"state\": \"" + userState + "\",\n" + - " \"reason\": \"" + userReason + "\"\n" + - " }\n" + - " }\n" + - "}"; + return """ + { + "attributes" : { + "hierarchical-group" : "%s" + }, + "state" : { + "generated" : { + "state" : "%s", + "reason" : "" + }, + "unit" : { + "state" : "%s", + "reason" : "" + }, + "user" : { + "state" : "%s", + "reason" : "%s" + } + } + }""".formatted(groupName, generatedState, unitState, userState, userReason); } @Test @@ -332,8 +313,27 @@ public class SetNodeStateTest extends StateRestApiTest { setUp(true); restAPI.setUnitState(new SetUnitStateRequestImpl("music/distributor/2").setNewState("user", "down", "borked node")); UnitResponse response = restAPI.getState(new StateRequest("music/distributor/2", 0)); - String expected = musicClusterExpectedUserStateStringWithUninitializedNode("east.g1", "down", "down", "down", "borked node"); - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(""" + { + "attributes" : { + "hierarchical-group" : "east.g1" + }, + "state" : { + "generated" : { + "state" : "down", + "reason" : "" + }, + "unit" : { + "state" : "down", + "reason" : "Node not seen in slobrok." + }, + "user" : { + "state" : "down", + "reason" : "borked node" + } + } + }""", + jsonWriter.createJson(response).toPrettyString()); } @Test @@ -467,7 +467,7 @@ public class SetNodeStateTest extends StateRestApiTest { "music/distributor/1").setNewState("user", "down", "testing more")); UnitResponse response = restAPI.getState(new StateRequest("music/distributor/1", 0)); String expected = musicClusterExpectedUserStateString("east.g2", "up", "up", "down", "testing more"); - assertEquals(expected, jsonWriter.createJson(response).toString(2)); + assertEquals(expected, jsonWriter.createJson(response).toPrettyString()); } private Id.Node createDummyId() { diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java index 32c4ee99c3c..1d45b1a455e 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java @@ -14,6 +14,7 @@ import java.util.regex.Pattern; * Deprecated.. Use the Waiter class instead */ public class StateWaiter implements SystemStateListener { + private final FakeTimer timer; protected ClusterState current; |