Search in sources :

Example 11 with HttpRequest

use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest 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 12 with HttpRequest

use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest 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)

Example 13 with HttpRequest

use of com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest in project vespa by vespa-engine.

the class StateRestAPITest method retireAndExpectHttp400Response.

private String retireAndExpectHttp400Response(String condition, 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", condition).put("response-wait", responseWait);
    HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json));
    assertEquals(result.toString(true), 400, 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)

Aggregations

HttpRequest (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest)13 HttpResult (com.yahoo.vespa.clustercontroller.utils.communication.http.HttpResult)12 Test (org.junit.Test)8 JSONObject (org.codehaus.jettison.json.JSONObject)2 Distribution (com.yahoo.vdslib.distribution.Distribution)1 StatusHandler (com.yahoo.vespa.clustercontroller.core.status.StatusHandler)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 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)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 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpPut (org.apache.http.client.methods.HttpPut)1