use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ResponseMerger method handleResponse.
@Override
public ContentChannel handleResponse(Response response) {
synchronized (this) {
if (response instanceof MbusResponse) {
Reply reply = ((MbusResponse) response).getReply();
requestTrace.addChild(reply.getTrace().getRoot());
replies.add(reply);
}
if (--numPending != 0) {
return null;
}
}
requestMsg.getTrace().getRoot().addChild(requestTrace);
Reply reply = DocumentProtocol.merge(replies);
Response mbusResponse = new MbusResponse(StatusCodes.fromMbusReply(reply), reply);
ResponseDispatch.newInstance(mbusResponse).dispatch(responseHandler);
return null;
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class AbstractRequestHandlerTestCase method requireThatHandleTimeoutIsImplemented.
@Test
public void requireThatHandleTimeoutIsImplemented() throws Exception {
FutureResponse handler = new FutureResponse();
new AbstractRequestHandler() {
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
return null;
}
}.handleTimeout(NonWorkingRequest.newInstance("http://localhost/"), handler);
Response response = handler.get(600, TimeUnit.SECONDS);
assertNotNull(response);
assertEquals(Response.Status.GATEWAY_TIMEOUT, response.getStatus());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class CallableRequestDispatchTestCase method requireThatDispatchIsCalled.
@Test
public void requireThatDispatchIsCalled() throws Exception {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
Response response = new Response(Response.Status.OK);
builder.serverBindings().bind("http://host/path", new MyRequestHandler(response));
driver.activateContainer(builder);
assertSame(response, new CallableRequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://host/path"));
}
}.call());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ResponseDispatchTestCase method requireThatStreamCanBeConnected.
@Test
public void requireThatStreamCanBeConnected() throws IOException {
ReadableContentChannel responseContent = new ReadableContentChannel();
OutputStream out = new FastContentOutputStream(new ResponseDispatch() {
@Override
protected Response newResponse() {
return new Response(Response.Status.OK);
}
}.connect(new MyResponseHandler(responseContent)));
out.write(6);
out.write(9);
out.close();
InputStream in = responseContent.toStream();
assertEquals(6, in.read());
assertEquals(9, in.read());
assertEquals(-1, in.read());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class ResponseDispatchTestCase method requireThatResponseCanBeDispatched.
@Test
public void requireThatResponseCanBeDispatched() throws Exception {
final Response response = new Response(Response.Status.OK);
final List<ByteBuffer> writtenContent = Arrays.asList(ByteBuffer.allocate(6), ByteBuffer.allocate(9));
ResponseDispatch dispatch = new ResponseDispatch() {
@Override
protected Response newResponse() {
return response;
}
@Override
protected Iterable<ByteBuffer> responseContent() {
return writtenContent;
}
};
ReadableContentChannel receivedContent = new ReadableContentChannel();
MyResponseHandler responseHandler = new MyResponseHandler(receivedContent);
dispatch.dispatch(responseHandler);
assertFalse(dispatch.isDone());
assertSame(response, responseHandler.response);
assertSame(writtenContent.get(0), receivedContent.read());
assertFalse(dispatch.isDone());
assertSame(writtenContent.get(1), receivedContent.read());
assertFalse(dispatch.isDone());
assertNull(receivedContent.read());
assertTrue(dispatch.isDone());
assertTrue(dispatch.get(600, TimeUnit.SECONDS));
assertTrue(dispatch.get());
}
Aggregations