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));
}
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);
}
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");
}
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");
}
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"));
}
Aggregations