use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestHandlerTestDriver method sendRequest.
public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, ByteBuffer body) {
responseHandler = new MockResponseHandler();
Request request = HttpRequest.newServerRequest(driver, URI.create(uri), method);
// TODO: Add a method for accepting a Request instead
request.context().put("contextVariable", 37);
ContentChannel requestContent = request.connect(responseHandler);
requestContent.write(body, null);
requestContent.close(null);
request.release();
return responseHandler;
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ThreadedRequestHandlerTestCase method requireThatRequestAndResponseReachHandlers.
@Test
public void requireThatRequestAndResponseReachHandlers() throws InterruptedException {
Executor executor = Executors.newSingleThreadExecutor();
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
MyRequestHandler requestHandler = MyRequestHandler.newInstance(executor);
builder.serverBindings().bind("http://localhost/", requestHandler);
driver.activateContainer(builder);
MyResponseHandler responseHandler = new MyResponseHandler();
Request request = new Request(driver, URI.create("http://localhost/"));
ContentChannel requestContent = request.connect(responseHandler);
ByteBuffer buf = ByteBuffer.allocate(69);
requestContent.write(buf, null);
requestContent.close(null);
request.release();
requestHandler.entryLatch.countDown();
assertTrue(requestHandler.exitLatch.await(60, TimeUnit.SECONDS));
assertSame(request, requestHandler.request);
assertSame(buf, requestHandler.content.read());
assertNull(requestHandler.content.read());
assertTrue(responseHandler.latch.await(60, TimeUnit.SECONDS));
assertSame(requestHandler.response, responseHandler.response);
assertNull(responseHandler.content.read());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ConnectToHandlerTestCase method requireThatNullResponseHandlerThrowsException.
@Test
public void requireThatNullResponseHandlerThrowsException() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
Request request = new Request(driver, URI.create("http://host/path"));
try {
request.connect(null);
fail();
} catch (NullPointerException e) {
// expected
}
request.release();
driver.close();
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ConnectToHandlerTestCase method requireThatConnectToHandlerWorks.
@Test
public void requireThatConnectToHandlerWorks() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = new MyRequestHandler(new MyContent());
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("http://host/*", requestHandler);
driver.activateContainer(builder);
Request request = new Request(driver, URI.create("http://host/path"));
MyResponseHandler responseHandler = new MyResponseHandler();
ContentChannel content = request.connect(responseHandler);
request.release();
assertNotNull(content);
content.close(null);
assertNotNull(requestHandler.handler);
assertSame(request, requestHandler.request);
requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
driver.close();
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestNondeterministicExceptionWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestNondeterministicExceptionWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {
@Override
public ContentChannel handle(final Request request, final ResponseHandler handler) {
callInOtherThread(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
closeResponse(out);
} catch (Throwable ignored) {
}
return null;
}
});
throw new ConformanceException();
}
});
}
Aggregations