use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult in project vespa by vespa-engine.
the class StateRestAPITest method executeOkJsonRequest.
private JSONObject executeOkJsonRequest(HttpRequest request) {
HttpResult result = execute(request);
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type"));
return (JSONObject) result.getContent();
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult in project vespa by vespa-engine.
the class StateRestAPITest method testTopLevelList.
@Test
public void testTopLevelList() throws Exception {
setupDummyStateApi();
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type"));
String expected = "{\"cluster\": {\n" + " \"foo\": {\"link\": \"\\/cluster\\/v2\\/foo\"},\n" + " \"bar\": {\"link\": \"\\/cluster\\/v2\\/bar\"}\n" + "}}";
assertEquals(expected, ((JSONObject) result.getContent()).toString(2));
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult in project vespa by vespa-engine.
the class StateRestAPITest method testNodeState.
@Test
public void testNodeState() throws Exception {
setupDummyStateApi();
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3"));
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type"));
String expected = "{\n" + " \"attributes\": {\"group\": \"mygroup\"},\n" + " \"state\": {\"current\": {\n" + " \"state\": \"up\",\n" + " \"reason\": \"\"\n" + " }},\n" + " \"metrics\": {\"doc-count\": 8}\n" + "}";
assertEquals(expected, ((JSONObject) result.getContent()).toString(2));
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult in project vespa by vespa-engine.
the class StateRestAPITest method retireAndExpectHttp200Response.
private String retireAndExpectHttp200Response(Optional<String> responseWait) throws Exception {
JSONObject json = new JSONObject().put("state", new JSONObject().put("current", new JSONObject().put("state", "retired").put("reason", "No reason"))).put("condition", "FORCE");
if (responseWait.isPresent()) {
json.put("response-wait", responseWait.get());
}
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json));
assertEquals(result.toString(true), 200, result.getHttpReturnCode());
assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type"));
StringBuilder print = new StringBuilder();
result.printContent(print);
return print.toString();
}
use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult in project vespa by vespa-engine.
the class StateRestAPITest method testUnknownMaster.
@Test
public void testUnknownMaster() throws Exception {
setupDummyStateApi();
stateApi.induceException(new UnknownMasterException());
HttpResult result = execute(new HttpRequest().setPath("/cluster/v2"));
assertEquals(result.toString(true), 503, result.getHttpReturnCode());
assertEquals(result.toString(true), "Service Unavailable", result.getHttpReturnCodeDescription());
assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type"));
String expected = "{\"message\":\"No known master cluster controller currently exists.\"}";
assertEquals(expected, result.getContent().toString());
assertTrue(result.getHeader("Location") == null);
}
Aggregations