use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class ApplicationTest method handler.
@Test
public void handler() throws Exception {
try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().handler("http://*/*", MockHttpHandler.class))))) {
RequestHandler handler = app.getRequestHandlerById(MockHttpHandler.class.getName());
assertNotNull(handler);
Request request = new Request("http://localhost:" + getDefaults().vespaWebServicePort() + "/");
Response response = app.handleRequest(request);
assertNotNull(response);
assertEquals(response.getStatus(), 200);
assertEquals(response.getBodyAsString(), "OK");
request = new Request("http://localhost");
response = app.handleRequest(request);
assertNotNull(response);
assertEquals(response.getStatus(), 200);
assertEquals(response.getBodyAsString(), "OK");
request = new Request("http://localhost/query=foo");
response = app.handleRequest(request);
assertNotNull(response);
assertEquals(response.getStatus(), 200);
assertEquals(response.getBodyAsString(), "OK");
}
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class ApplicationTest method renderer.
@Test
public void renderer() throws Exception {
try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().renderer("mock", MockRenderer.class))))) {
Request request = new Request("http://localhost:" + getDefaults().vespaWebServicePort() + "/search/?format=mock");
Response response = app.handleRequest(request);
assertNotNull(response);
assertEquals(response.getStatus(), 200);
assertEquals(response.getBodyAsString(), "<mock hits=\"0\" />");
}
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class JDiscContainerRequestTest method requireThatCustomRequestHeadersWork.
@Test
public void requireThatCustomRequestHeadersWork() throws InterruptedException {
Request req = new Request("http://banana/echo");
req.getHeaders().add("X-Foo", "Bar");
try (JDisc container = JDisc.fromServicesXml(getXML(HeaderEchoRequestHandler.class.getCanonicalName(), "http://*/echo"), Networking.disable)) {
Response response = container.handleRequest(req);
assertThat(response.getHeaders().contains("X-Foo", "Bar"), is(true));
req.toString();
response.toString();
}
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class JDiscContainerRequestTest method requireThatRequestBodyWorks.
@Test
public void requireThatRequestBodyWorks() throws InterruptedException, CharacterCodingException {
String DATA = "we have no bananas today";
Request req = new Request("http://banana/echo", DATA.getBytes(Utf8.getCharset()));
try (JDisc container = JDisc.fromServicesXml(getXML(EchoRequestHandler.class.getCanonicalName(), "http://*/echo"), Networking.disable)) {
Response response = container.handleRequest(req);
assertThat(response.getBodyAsString(), equalTo(DATA));
req.toString();
response.toString();
}
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class ApplicationApiTest method testJobStatusReporting.
@Test
public void testJobStatusReporting() throws Exception {
ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
addUserToHostedOperatorRole(HostedAthenzIdentities.from(HOSTED_VESPA_OPERATOR));
tester.containerTester().updateSystemVersion();
long projectId = 1;
Application app = tester.createApplication();
ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("corp-us-east-1").build();
// system version from mock config server client
Version vespaVersion = new Version("6.1");
BuildJob job = new BuildJob(report -> notifyCompletion(report, tester), tester.artifactRepository()).application(app).projectId(projectId);
job.type(DeploymentJobs.JobType.component).uploadArtifact(applicationPackage).submit();
tester.deploy(app, applicationPackage, TEST_ZONE, projectId);
job.type(DeploymentJobs.JobType.systemTest).submit();
// Notifying about unknown job fails
Request request = request("/application/v4/tenant/tenant1/application/application1/jobreport", POST).data(asJson(job.type(DeploymentJobs.JobType.productionUsEast3).report())).userIdentity(HOSTED_VESPA_OPERATOR).get();
tester.containerTester().assertResponse(request, new File("jobreport-unexpected-completion.json"), 400);
// ... and assert it was recorded
JobStatus recordedStatus = tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(DeploymentJobs.JobType.component);
assertNotNull("Status was recorded", recordedStatus);
assertTrue(recordedStatus.isSuccess());
assertEquals(vespaVersion, recordedStatus.lastCompleted().get().version());
recordedStatus = tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(DeploymentJobs.JobType.productionApNortheast2);
assertNull("Status of never-triggered jobs is empty", recordedStatus);
Response response;
response = container.handleRequest(request("/screwdriver/v1/jobsToRun", GET).get());
assertTrue("Response contains system-test", response.getBodyAsString().contains(DeploymentJobs.JobType.systemTest.jobName()));
assertTrue("Response contains staging-test", response.getBodyAsString().contains(DeploymentJobs.JobType.stagingTest.jobName()));
assertEquals("Response contains only two items", 2, SlimeUtils.jsonToSlime(response.getBody()).get().entries());
// Check that GET didn't affect the enqueued jobs.
response = container.handleRequest(request("/screwdriver/v1/jobsToRun", GET).get());
assertTrue("Response contains system-test", response.getBodyAsString().contains(DeploymentJobs.JobType.systemTest.jobName()));
assertTrue("Response contains staging-test", response.getBodyAsString().contains(DeploymentJobs.JobType.stagingTest.jobName()));
assertEquals("Response contains only two items", 2, SlimeUtils.jsonToSlime(response.getBody()).get().entries());
}
Aggregations