use of com.yahoo.jdisc.test.TestDriver 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.test.TestDriver in project vespa by vespa-engine.
the class ThreadedRequestHandlerTestCase method requireThatRequestContentIsClosedIfHandlerIgnoresIt.
@Test
public void requireThatRequestContentIsClosedIfHandlerIgnoresIt() throws InterruptedException {
Executor executor = Executors.newSingleThreadExecutor();
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
MyRequestHandler requestHandler = MyRequestHandler.newIgnoreContent(executor);
builder.serverBindings().bind("http://localhost/", requestHandler);
driver.activateContainer(builder);
MyResponseHandler responseHandler = new MyResponseHandler();
ContentChannel content = driver.connectRequest("http://localhost/", responseHandler);
MyCompletion writeCompletion = new MyCompletion();
content.write(ByteBuffer.allocate(69), writeCompletion);
MyCompletion closeCompletion = new MyCompletion();
content.close(closeCompletion);
requestHandler.entryLatch.countDown();
assertTrue(requestHandler.exitLatch.await(60, TimeUnit.SECONDS));
assertTrue(writeCompletion.latch.await(60, TimeUnit.SECONDS));
assertTrue(writeCompletion.completed);
assertTrue(closeCompletion.latch.await(60, TimeUnit.SECONDS));
assertTrue(writeCompletion.completed);
assertTrue(responseHandler.latch.await(60, TimeUnit.SECONDS));
assertSame(requestHandler.response, responseHandler.response);
assertNull(responseHandler.content.read());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class Main method startContainer.
public static TestDriver startContainer(final String configId) {
System.setProperty("config.id", configId);
@SuppressWarnings("unused") TestDriver driver = TestDriver.newInjectedApplicationInstance(ConfiguredApplication.class, new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(Names.named("configId")).toInstance(configId);
}
});
return driver;
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class AbstractServerProviderTestCase method requireThatAccessorsWork.
@Test
public void requireThatAccessorsWork() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
MyServerProvider server = builder.getInstance(MyServerProvider.class);
assertNotNull(server.container());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver 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();
}
Aggregations