Search in sources :

Example 76 with HttpResponse

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

the class SessionPrepareHandlerTest method require_that_preparing_with_multiple_tenants_work.

@Test
public void require_that_preparing_with_multiple_tenants_work() throws Exception {
    // Need different repos for 'default' tenant as opposed to the 'test' tenant
    LocalSessionRepo localRepoDefault = new LocalSessionRepo(Clock.systemUTC());
    final TenantName defaultTenant = TenantName.defaultName();
    addTenant(defaultTenant, localRepoDefault, new RemoteSessionRepo(tenant), new MockSessionFactory());
    addTestTenant();
    final SessionHandler handler = createHandler(builder);
    long sessionId = 1;
    // Deploy with default tenant
    MockSession session = new MockSession(sessionId, null);
    localRepoDefault.addSession(session);
    pathPrefix = "/application/v2/tenant/" + defaultTenant + "/session/";
    HttpResponse response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, sessionId));
    assertNotNull(response);
    assertThat(SessionHandlerTest.getRenderedString(response), response.getStatus(), is(OK));
    assertThat(session.getStatus(), is(Session.Status.PREPARE));
    // Same session id, as this is for another tenant
    session = new MockSession(sessionId, null);
    localRepo.addSession(session);
    String applicationName = "myapp";
    pathPrefix = "/application/v2/tenant/" + tenant + "/session/" + sessionId + "/prepared?applicationName=" + applicationName;
    response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix));
    assertNotNull(response);
    assertThat(SessionHandlerTest.getRenderedString(response), response.getStatus(), is(OK));
    assertThat(session.getStatus(), is(Session.Status.PREPARE));
    sessionId++;
    session = new MockSession(sessionId, null);
    localRepo.addSession(session);
    pathPrefix = "/application/v2/tenant/" + tenant + "/session/" + sessionId + "/prepared?applicationName=" + applicationName + "&instance=quux";
    response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix));
    assertNotNull(response);
    assertThat(SessionHandlerTest.getRenderedString(response), response.getStatus(), is(OK));
    assertThat(session.getStatus(), is(Session.Status.PREPARE));
}
Also used : TenantName(com.yahoo.config.provision.TenantName) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 77 with HttpResponse

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

the class SessionPrepareHandlerTest method require_that_activate_url_is_returned_on_success.

@Test
public void require_that_activate_url_is_returned_on_success() throws Exception {
    MockSession session = new MockSession(1, null);
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertThat(session.getStatus(), is(Session.Status.PREPARE));
    assertNotNull(response);
    assertThat(response.getStatus(), is(OK));
    assertResponseContains(response, "\"activate\":\"http://foo:1337" + pathPrefix + "1/active\",\"message\":\"Session 1" + preparedMessage);
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 78 with HttpResponse

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

the class SessionPrepareHandlerTest method require_cannot_prepare_active_session.

@Test
public void require_cannot_prepare_active_session() throws Exception {
    MockSession session = new MockSession(1, null);
    localRepo.addSession(session);
    session.setStatus(Session.Status.ACTIVATE);
    SessionHandler sessionHandler = createHandler(fromLocalSessionRepo(localRepo, Clock.systemUTC()));
    HttpResponse putResponse = sessionHandler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertHttpStatusCodeErrorCodeAndMessage(putResponse, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Session is active: 1");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 79 with HttpResponse

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

the class SessionPrepareHandlerTest method require_get_response_error_when_session_id_does_not_exist.

@Test
public void require_get_response_error_when_session_id_does_not_exist() throws Exception {
    MockSession session = new MockSession(1, null);
    localRepo.addSession(session);
    SessionHandler sessHandler = createHandler(fromLocalSessionRepo(localRepo, Clock.systemUTC()));
    HttpResponse getResponse = sessHandler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.GET, Cmd.PREPARED, 9999L));
    assertHttpStatusCodeErrorCodeAndMessage(getResponse, NOT_FOUND, HttpErrorResponse.errorCodes.NOT_FOUND, "Session 9999 was not found");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 80 with HttpResponse

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

the class SessionPrepareHandlerTest method require_verbose.

@Test
public void require_verbose() throws Exception {
    MockSession session = new MockSession(1, null);
    session.doVerboseLogging = true;
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L, "?verbose=true"));
    assertThat(response.getStatus(), is(OK));
    assertThat(SessionHandlerTest.getRenderedString(response), containsString("debuglog"));
}
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