use of com.yahoo.jdisc.test.TestDriver 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.test.TestDriver in project vespa by vespa-engine.
the class ContainerTestCase method requireThatInjectionWorks.
@Test
public void requireThatInjectionWorks() throws BindingSetNotFoundException {
final Object foo = new Object();
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {
@Override
protected void configure() {
bind(Object.class).toInstance(foo);
}
});
driver.activateContainer(driver.newContainerBuilder());
Request request = new Request(driver, URI.create("http://host/path"));
assertSame(foo, request.container().getInstance(Object.class));
request.release();
driver.close();
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ContainerTestCase method requireThatNewRequestsReferenceSameSnapshot.
@Test
public void requireThatNewRequestsReferenceSameSnapshot() throws Exception {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
Request foo = new Request(driver, URI.create("http://foo"));
Request bar = new Request(foo, URI.create("http://bar"));
assertNotNull(foo.container());
assertSame(foo.container(), bar.container());
foo.release();
bar.release();
driver.close();
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatResponseCloseCompletionCanOnlyBeCalledOnce.
@Test
public void requireThatResponseCloseCompletionCanOnlyBeCalledOnce() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
MyResponseHandler responseHandler = MyResponseHandler.newInstance();
Request request = newRequest(driver, requestHandler);
request.connect(responseHandler).close(null);
request.release();
ContentChannel resolvedContent = requestHandler.handler.handleResponse(new Response(Response.Status.OK));
CountingCompletionHandler completion = new CountingCompletionHandler();
resolvedContent.close(completion);
assertEquals(0, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
responseHandler.content.closeCompletion.completed();
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
responseHandler.content.closeCompletion.completed();
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
responseHandler.content.closeCompletion.failed(new Throwable());
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatRequestWriteCompletionCanOnlyBeCalledOnce.
@Test
public void requireThatRequestWriteCompletionCanOnlyBeCalledOnce() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
Request request = newRequest(driver, requestHandler);
ContentChannel resolvedContent = request.connect(MyResponseHandler.newEagerCompletion());
request.release();
CountingCompletionHandler completion = new CountingCompletionHandler();
resolvedContent.write(ByteBuffer.allocate(0), completion);
assertEquals(0, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
requestHandler.content.writeCompletion.completed();
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
requestHandler.content.writeCompletion.completed();
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
requestHandler.content.writeCompletion.failed(new Throwable());
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
resolvedContent.close(null);
requestHandler.content.closeCompletion.completed();
requestHandler.respond();
assertTrue(driver.close());
}
Aggregations