use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ClientTestDriver method newClientRequest.
public Request newClientRequest(Message msg) {
msg.setRoute(Route.parse(server.connectionSpec()));
if (msg.getTrace().getLevel() == 0) {
msg.getTrace().setLevel(9);
}
final Request parent = newServerRequest();
try (final ResourceReference ref = References.fromResource(parent)) {
return new MbusRequest(parent, URI.create("mbus://remotehost/"), msg);
}
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class MbusClientTestCase method requireThatRequestContentDoesNotSupportWrite.
@Test
public void requireThatRequestContentDoesNotSupportWrite() throws InterruptedException {
ClientTestDriver driver = ClientTestDriver.newInstance();
MyResponseHandler responseHandler = MyResponseHandler.newInstance();
Request request = null;
ContentChannel content;
try {
request = driver.newClientRequest(new SimpleMessage("foo"));
content = request.connect(responseHandler);
} finally {
if (request != null) {
request.release();
}
}
try {
content.write(ByteBuffer.allocate(69), null);
fail();
} catch (UnsupportedOperationException e) {
}
content.close(null);
assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
assertNotNull(responseHandler.awaitResponse());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class MbusClientTestCase method requireThatStateIsTransferredToTimeoutResponse.
@Test
public void requireThatStateIsTransferredToTimeoutResponse() throws InterruptedException {
ClientTestDriver driver = ClientTestDriver.newInstance();
MyResponseHandler responseHandler = MyResponseHandler.newInstance();
Message msg = new SimpleMessage("foo");
ReplyHandler pushedHandler = new MyReplyHandler();
Object pushedCtx = new Object();
msg.setContext(pushedCtx);
msg.pushHandler(pushedHandler);
Object currentCtx = new Object();
msg.setContext(currentCtx);
msg.getTrace().setLevel(6);
Request request = driver.newClientRequest(msg);
request.setTimeout(1, TimeUnit.MILLISECONDS);
assertTrue(driver.sendRequest(request, responseHandler));
request.release();
Response response = responseHandler.awaitResponse();
assertNotNull(response);
assertTrue(response.getClass().getName(), response instanceof MbusResponse);
Reply reply = ((MbusResponse) response).getReply();
assertSame(currentCtx, reply.getContext());
assertEquals(6, reply.getTrace().getLevel());
assertSame(pushedHandler, reply.popHandler());
assertSame(pushedCtx, reply.getContext());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class BindingNotFoundTestCase method requireThatBindingNotFoundIsThrown.
@Test
public void requireThatBindingNotFoundIsThrown() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
Request request = new Request(driver, URI.create("http://host/path"));
try {
request.connect(new MyResponseHandler());
fail();
} catch (BindingNotFoundException e) {
assertEquals(request.getUri(), e.uri());
}
request.release();
driver.close();
}
use of com.yahoo.jdisc.Request 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