use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatDispatchHandlesCloseException.
@Test
public void requireThatDispatchHandlesCloseException() {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
Response response = new Response(Response.Status.OK);
builder.serverBindings().bind("http://localhost/", new MyRequestHandler(new ContentChannel() {
@Override
public void write(ByteBuffer buf, CompletionHandler handler) {
handler.completed();
}
@Override
public void close(CompletionHandler handler) {
throw new RuntimeException();
}
}, response));
driver.activateContainer(builder);
try {
new RequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://localhost/"));
}
@Override
protected Iterable<ByteBuffer> requestContent() {
return Arrays.asList(ByteBuffer.allocate(69));
}
}.dispatch();
fail();
} catch (RuntimeException e) {
}
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatDispatchCanBeListenedTo.
@Test
public void requireThatDispatchCanBeListenedTo() throws InterruptedException {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
ReadableContentChannel requestContent = new ReadableContentChannel();
MyRequestHandler requestHandler = new MyRequestHandler(requestContent, null);
builder.serverBindings().bind("http://localhost/", requestHandler);
driver.activateContainer(builder);
RunnableLatch listener = new RunnableLatch();
new RequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://localhost/"));
}
}.dispatch().addListener(listener, MoreExecutors.directExecutor());
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
ContentChannel responseContent = ResponseDispatch.newInstance(Response.Status.OK).connect(requestHandler.responseHandler);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
assertNull(requestContent.read());
assertTrue(listener.await(600, TimeUnit.SECONDS));
responseContent.close(null);
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatDispatchHandlesWriteException.
@Test
public void requireThatDispatchHandlesWriteException() {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
Response response = new Response(Response.Status.OK);
builder.serverBindings().bind("http://localhost/", new MyRequestHandler(new ContentChannel() {
@Override
public void write(ByteBuffer buf, CompletionHandler handler) {
throw new RuntimeException();
}
@Override
public void close(CompletionHandler handler) {
handler.completed();
}
}, response));
driver.activateContainer(builder);
try {
new RequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://localhost/"));
}
@Override
protected Iterable<ByteBuffer> requestContent() {
return Arrays.asList(ByteBuffer.allocate(69));
}
}.dispatch();
fail();
} catch (RuntimeException e) {
}
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Request in project vespa by vespa-engine.
the class ContainerSnapshotTestCase method requireThatClientHandlerCanBeResolved.
@Test
public void requireThatClientHandlerCanBeResolved() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
builder.clientBindings().bind("http://foo/*", MyRequestHandler.newInstance());
driver.activateContainer(builder);
Request request = new Request(driver, URI.create("http://foo/"));
assertNull(request.container().resolveHandler(request));
assertNull(request.getBindingMatch());
request.release();
request = new Request(driver, URI.create("http://foo/"));
request.setServerRequest(false);
assertNotNull(request.container().resolveHandler(request));
assertNotNull(request.getBindingMatch());
request.release();
request = new Request(driver, URI.create("http://bar/"));
assertNull(request.container().resolveHandler(request));
assertNull(request.getBindingMatch());
request.release();
request = new Request(driver, URI.create("http://bar/"));
request.setServerRequest(false);
assertNull(request.container().resolveHandler(request));
assertNull(request.getBindingMatch());
request.release();
assertTrue(driver.close());
}
Aggregations