use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class MbusServerTestCase method requireThatRequestResponseWorks.
@Test
public void requireThatRequestResponseWorks() {
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
assertTrue(driver.sendMessage(new SimpleMessage("foo")));
assertNotNull(requestHandler.awaitRequest());
assertTrue(requestHandler.sendResponse(new Response(Response.Status.OK)));
assertNotNull(driver.awaitSuccess());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class MbusServerTestCase method requireThatResponseContentDoesNotSupportWrite.
@Test
public void requireThatResponseContentDoesNotSupportWrite() throws InterruptedException {
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
assertTrue(driver.sendMessage(new SimpleMessage("foo")));
assertNotNull(requestHandler.awaitRequest());
ContentChannel content = requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK));
assertNotNull(content);
try {
content.write(ByteBuffer.allocate(69), null);
fail();
} catch (UnsupportedOperationException e) {
}
content.close(null);
assertNotNull(driver.awaitSuccess());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class CallableResponseDispatchTestCase method requireThatDispatchIsCalled.
@Test
public void requireThatDispatchIsCalled() throws Exception {
final Response response = new Response(Response.Status.OK);
FutureResponse handler = new FutureResponse();
new CallableResponseDispatch(handler) {
@Override
protected Response newResponse() {
return response;
}
}.call();
assertSame(response, handler.get(600, TimeUnit.SECONDS));
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class FutureResponseTestCase method requireThatResponseCanBeListenedTo.
@Test
public void requireThatResponseCanBeListenedTo() throws InterruptedException {
FutureResponse response = new FutureResponse();
RunnableLatch listener = new RunnableLatch();
response.addListener(listener, MoreExecutors.directExecutor());
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
response.handleResponse(new Response(Response.Status.OK));
assertTrue(listener.await(600, TimeUnit.SECONDS));
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatRequestCanBeDispatched.
@Test
public void requireThatRequestCanBeDispatched() throws Exception {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
final List<ByteBuffer> writtenContent = Arrays.asList(ByteBuffer.allocate(6), ByteBuffer.allocate(9));
ReadableContentChannel receivedContent = new ReadableContentChannel();
ContainerBuilder builder = driver.newContainerBuilder();
Response response = new Response(Response.Status.OK);
builder.serverBindings().bind("http://localhost/", new MyRequestHandler(receivedContent, response));
driver.activateContainer(builder);
RequestDispatch dispatch = new RequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://localhost/"));
}
@Override
protected Iterable<ByteBuffer> requestContent() {
return writtenContent;
}
};
dispatch.dispatch();
assertFalse(dispatch.isDone());
assertSame(writtenContent.get(0), receivedContent.read());
assertFalse(dispatch.isDone());
assertSame(writtenContent.get(1), receivedContent.read());
assertFalse(dispatch.isDone());
assertNull(receivedContent.read());
assertTrue(dispatch.isDone());
assertSame(response, dispatch.get(600, TimeUnit.SECONDS));
assertTrue(driver.close());
}
Aggregations