use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class TestDriverTestCase method requireThatDispatchRequestWorks.
@Test
public void requireThatDispatchRequestWorks() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = new MyRequestHandler(new MyContentChannel());
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("scheme://host/path", requestHandler);
driver.activateContainer(builder);
driver.dispatchRequest("scheme://host/path", new MyResponseHandler());
assertNotNull(requestHandler.handler);
assertTrue(requestHandler.content.closed);
requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class TestDriverTestCase method requireThatConnectRequestWorks.
@Test
public void requireThatConnectRequestWorks() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = new MyRequestHandler(new MyContentChannel());
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("scheme://host/path", requestHandler);
driver.activateContainer(builder);
ContentChannel content = driver.connectRequest("scheme://host/path", new MyResponseHandler());
assertNotNull(content);
content.close(null);
assertNotNull(requestHandler.handler);
requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class MockClient method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
counter.incrementAndGet();
final ContentChannel responseContentChannel = handler.handleResponse(new Response(200));
responseContentChannel.close(NOOP_COMPLETION_HANDLER);
return null;
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ProcessingHandlerTestCase method testResponseDataStatusOverridesErrors.
/**
* Tests that the ResponseStatus takes precedence over errors
*/
@Test
public void testResponseDataStatusOverridesErrors() throws InterruptedException {
ProcessingTestDriver.MockResponseHandler responseHandler = null;
try {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(new Chain<Processor>("default", new ResponseStatusSetter(200), new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
driver = new ProcessingTestDriver(chains);
responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
Response response = responseHandler.getResponse();
assertEquals(200, response.getStatus());
} finally {
if (responseHandler != null)
responseHandler.readAll();
}
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ProcessingHandlerTestCase method testResponseDataStatus.
@Test
public void testResponseDataStatus() throws InterruptedException {
ProcessingTestDriver.MockResponseHandler responseHandler = null;
try {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(new Chain<Processor>("default", new ResponseStatusSetter(429)));
driver = new ProcessingTestDriver(chains);
responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
Response response = responseHandler.getResponse();
assertEquals(429, response.getStatus());
assertEquals("ResponseHeaders are not rendered", "{\"datalist\":[]}", responseHandler.read());
} finally {
if (responseHandler != null)
responseHandler.readAll();
}
}
Aggregations