use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ApplicationLoaderTestCase method requireThatApplicationDestroyIsCalledAfterContainerTermination.
@Test
public void requireThatApplicationDestroyIsCalledAfterContainerTermination() throws InterruptedException {
MyApplication app = MyApplication.newInstance();
TestDriver driver = TestDriver.newInjectedApplicationInstance(app);
ContainerBuilder builder = driver.newContainerBuilder();
MyRequestHandler requestHandler = new MyRequestHandler();
builder.serverBindings().bind("scheme://host/path", requestHandler);
driver.activateContainer(builder);
driver.dispatchRequest("scheme://host/path", new MyResponseHandler());
driver.scheduleClose();
assertFalse(app.destroy.await(100, TimeUnit.MILLISECONDS));
requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
assertTrue(app.destroy.await(600, TimeUnit.SECONDS));
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ApplicationLoaderTestCase method requireThatContainerActivatorReturnsPrev.
@Test
public void requireThatContainerActivatorReturnsPrev() throws Exception {
TestDriver driver = TestDriver.newInjectedApplicationInstance(MyApplication.newInstance());
assertNull(driver.activateContainer(driver.newContainerBuilder()));
assertNotNull(driver.activateContainer(null));
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatCancelIsUnsupported.
@Test
public void requireThatCancelIsUnsupported() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
RequestDispatch dispatch = driver.newRequestDispatch("http://localhost/", new FutureResponse());
assertFalse(dispatch.isCancelled());
try {
dispatch.cancel(true);
fail();
} catch (UnsupportedOperationException e) {
}
assertFalse(dispatch.isCancelled());
try {
dispatch.cancel(false);
fail();
} catch (UnsupportedOperationException e) {
}
assertFalse(dispatch.isCancelled());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatStreamCanBeConnected.
@Test
public void requireThatStreamCanBeConnected() throws IOException {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
ReadableContentChannel content = new ReadableContentChannel();
MyRequestHandler requestHandler = new MyRequestHandler(content, new Response(Response.Status.OK));
builder.serverBindings().bind("http://localhost/", requestHandler);
driver.activateContainer(builder);
OutputStream out = new FastContentOutputStream(driver.newRequestDispatch("http://localhost/", new FutureResponse()).connect());
out.write(6);
out.write(9);
out.close();
InputStream in = content.toStream();
assertEquals(6, in.read());
assertEquals(9, in.read());
assertEquals(-1, in.read());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class RequestDispatchTestCase method requireThatDispatchHandlesConnectException.
@Test
public void requireThatDispatchHandlesConnectException() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("http://localhost/", new AbstractRequestHandler() {
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
throw new RuntimeException();
}
});
driver.activateContainer(builder);
try {
driver.newRequestDispatch("http://localhost/", new FutureResponse()).dispatch();
fail();
} catch (RuntimeException e) {
}
assertTrue(driver.close());
}
Aggregations