use of com.yahoo.jdisc.application.ContainerBuilder 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());
}
use of com.yahoo.jdisc.application.ContainerBuilder 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.application.ContainerBuilder 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.application.ContainerBuilder 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.application.ContainerBuilder in project vespa by vespa-engine.
the class ApplicationLoaderTestCase method requireThatThreadFactoryCanBeBound.
@Test
public void requireThatThreadFactoryCanBeBound() {
final ThreadFactory factory = Executors.defaultThreadFactory();
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {
@Override
protected void configure() {
bind(ThreadFactory.class).toInstance(factory);
}
});
ContainerBuilder builder = driver.newContainerBuilder();
assertSame(factory, builder.getInstance(ThreadFactory.class));
assertTrue(driver.close());
}
Aggregations