Search in sources :

Example 11 with HttpResult

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();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)

Example 12 with HttpResult

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));
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult) Test(org.junit.Test)

Example 13 with HttpResult

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));
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult) Test(org.junit.Test)

Example 14 with HttpResult

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();
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) JSONObject(org.codehaus.jettison.json.JSONObject) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)

Example 15 with HttpResult

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);
}
Also used : HttpRequest(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest) HttpResult(com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult) Test(org.junit.Test)

Aggregations

HttpResult (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)16 HttpRequest (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest)13 Test (org.junit.Test)7 JSONObject (org.codehaus.jettison.json.JSONObject)3 StringWriter (java.io.StringWriter)2 Distribution (com.yahoo.vdslib.distribution.Distribution)1 StatusHandler (com.yahoo.vespa.clustercontroller.core.status.StatusHandler)1 StatusPageResponse (com.yahoo.vespa.clustercontroller.core.status.statuspage.StatusPageResponse)1 StatusPageServer (com.yahoo.vespa.clustercontroller.core.status.statuspage.StatusPageServer)1 AsyncOperationImpl (com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl)1 SyncHttpClient (com.yahoo.vespa.clustercontroller.utils.communication.http.SyncHttpClient)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Header (org.apache.http.Header)1 HttpEntity (org.apache.http.HttpEntity)1 HttpHost (org.apache.http.HttpHost)1 HttpResponse (org.apache.http.HttpResponse)1 HttpDelete (org.apache.http.client.methods.HttpDelete)1