Search in sources :

Example 81 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method require_debug.

@Test
public void require_debug() throws Exception {
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 9999L, "?debug=true"));
    assertThat(response.getStatus(), is(NOT_FOUND));
    assertThat(SessionHandlerTest.getRenderedString(response), containsString("NotFoundException"));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 82 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method require_that_config_change_actions_are_in_response.

@Test
public void require_that_config_change_actions_are_in_response() throws Exception {
    MockSession session = new MockSession(1, null);
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertResponseContains(response, "\"configChangeActions\":{\"restart\":[],\"refeed\":[]}");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 83 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method test_application_lock_failure.

@Test
public void test_application_lock_failure() throws InterruptedException, IOException {
    String message = "Timed out after waiting PT1M to acquire lock '/provision/v1/locks/foo/bar/default'";
    SessionThrowingException session = new SessionThrowingException(new ApplicationLockException(new UncheckedTimeoutException(message)));
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertEquals(500, response.getStatus());
    Slime data = getData(response);
    assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.APPLICATION_LOCK_FAILURE.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) Matchers.containsString(org.hamcrest.Matchers.containsString) Slime(com.yahoo.slime.Slime) ApplicationLockException(com.yahoo.config.provision.ApplicationLockException) Test(org.junit.Test)

Example 84 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class ApplicationConvergenceCheckerTest method converge.

@Test
public void converge() throws IOException, SAXException {
    ApplicationConvergenceChecker checker = new ApplicationConvergenceChecker((client, serviceUri) -> () -> string2json("{\"config\":{\"generation\":3}}"));
    HttpResponse serviceListResponse = checker.serviceListToCheckForConfigConvergence(application, URI.create("http://foo:234/serviceconverge"));
    assertThat(serviceListResponse.getStatus(), is(200));
    assertEquals("{\"services\":[" + "{\"host\":\"localhost\"," + "\"port\":1337," + "\"type\":\"container\"," + "\"url\":\"http://foo:234/serviceconverge/localhost:1337\"}]," + "\"debug\":{\"wantedGeneration\":3}," + "\"url\":\"http://foo:234/serviceconverge\"}", SessionHandlerTest.getRenderedString(serviceListResponse));
    ServiceResponse serviceResponse = checker.serviceConvergenceCheck(application, "localhost:1337", URI.create("http://foo:234/serviceconverge/localhost:1337"));
    assertThat(serviceResponse.getStatus(), is(200));
    assertEquals("{" + "\"debug\":{" + "\"host\":\"localhost:1337\"," + "\"wantedGeneration\":3," + "\"currentGeneration\":3}," + "\"url\":\"http://foo:234/serviceconverge/localhost:1337\"," + "\"converged\":true}", SessionHandlerTest.getRenderedString(serviceResponse));
    ServiceResponse hostMissingResponse = checker.serviceConvergenceCheck(application, "notPresent:1337", URI.create("http://foo:234/serviceconverge/notPresent:1337"));
    assertThat(hostMissingResponse.getStatus(), is(410));
    assertEquals("{\"debug\":{" + "\"host\":\"notPresent:1337\"," + "\"wantedGeneration\":3," + "\"problem\":\"Host:port (service) no longer part of application, refetch list of services.\"}," + "\"url\":\"http://foo:234/serviceconverge/notPresent:1337\"}", SessionHandlerTest.getRenderedString(hostMissingResponse));
}
Also used : ServiceResponse(com.yahoo.vespa.config.server.application.ApplicationConvergenceChecker.ServiceResponse) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

Example 85 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class HttpGetConfigHandlerTest method require_correct_error_response.

@Test
public void require_correct_error_response() throws IOException {
    final String nonExistingConfigNameUri = "http://yahoo.com:8080/config/v1/nonexisting.config/myid";
    final String nonExistingConfigUri = "http://yahoo.com:8080/config/v1/foo.bar/myid/nonexisting/id";
    final String illegalConfigNameUri = "http://yahoo.com:8080/config/v1/foobar/myid";
    HttpResponse response = handler.handle(HttpRequest.createTestRequest(nonExistingConfigNameUri, GET));
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, NOT_FOUND, HttpErrorResponse.errorCodes.NOT_FOUND, "No such config: nonexisting.config");
    assertTrue(SessionHandlerTest.getRenderedString(response).contains("No such config:"));
    response = handler.handle(HttpRequest.createTestRequest(nonExistingConfigUri, GET));
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, NOT_FOUND, HttpErrorResponse.errorCodes.NOT_FOUND, "No such config id: myid/nonexisting/id");
    assertEquals(response.getContentType(), "application/json");
    assertTrue(SessionHandlerTest.getRenderedString(response).contains("No such config id:"));
    response = handler.handle(HttpRequest.createTestRequest(illegalConfigNameUri, GET));
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Illegal config, must be of form namespace.name.");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Aggregations

HttpResponse (com.yahoo.container.jdisc.HttpResponse)103 Test (org.junit.Test)75 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)33 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)24 HttpRequest (com.yahoo.container.jdisc.HttpRequest)16 CompressedApplicationInputStreamTest (com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)6 SessionTest (com.yahoo.vespa.config.server.session.SessionTest)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)5 InnerCNode (com.yahoo.config.codegen.InnerCNode)5 Slime (com.yahoo.slime.Slime)5 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)5 OutputStream (java.io.OutputStream)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ApplicationId (com.yahoo.config.provision.ApplicationId)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3