use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatNullResponseContentIsProxied.
@Test
public void requireThatNullResponseContentIsProxied() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
Request request = newRequest(driver, requestHandler);
ResponseHandler responseHandler = new ResponseHandler() {
@Override
public ContentChannel handleResponse(Response response) {
return null;
}
};
request.connect(responseHandler).close(null);
requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
request.release();
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatResponseContentCompletedIsProxied.
@Test
public void requireThatResponseContentCompletedIsProxied() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
Request request = newRequest(driver, requestHandler);
MyResponseHandler responseHandler = MyResponseHandler.newInstance();
request.connect(responseHandler).close(null);
request.release();
Response response = new Response(Response.Status.OK);
ContentChannel resolvedContent = requestHandler.handler.handleResponse(response);
assertSame(response, responseHandler.response);
ByteBuffer buf = ByteBuffer.allocate(69);
resolvedContent.write(buf, null);
assertSame(buf, responseHandler.content.writeBuf);
responseHandler.content.writeCompletion.completed();
MyCompletion writeCompletion = new MyCompletion();
resolvedContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
assertSame(buf, responseHandler.content.writeBuf);
assertFalse(writeCompletion.completed);
assertNull(writeCompletion.failed);
responseHandler.content.writeCompletion.completed();
assertTrue(writeCompletion.completed);
assertNull(writeCompletion.failed);
MyCompletion closeCompletion = new MyCompletion();
resolvedContent.close(closeCompletion);
assertTrue(responseHandler.content.closed);
assertFalse(closeCompletion.completed);
assertNull(closeCompletion.failed);
responseHandler.content.closeCompletion.completed();
assertTrue(closeCompletion.completed);
assertNull(closeCompletion.failed);
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class AbstractRequestHandlerTestCase method requireThatEchoWorks.
@Test
public void requireThatEchoWorks() throws InterruptedException {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("http://localhost/", new EchoHandler());
driver.activateContainer(builder);
for (int i = 0; i < NUM_REQUESTS; ++i) {
MyResponseHandler responseHandler = new MyResponseHandler();
RequestDispatch dispatch = driver.newRequestDispatch("http://localhost/", responseHandler);
FastContentWriter requestContent = dispatch.connectFastWriter();
ByteBuffer buf = ByteBuffer.allocate(69);
requestContent.write(buf);
requestContent.close();
assertSame(buf, responseHandler.content.read());
assertNull(responseHandler.content.read());
}
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class AbstractRequestHandlerTestCase method requireThatHelloWorldWorks.
@Test
public void requireThatHelloWorldWorks() throws InterruptedException {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
builder.serverBindings().bind("http://localhost/", new HelloWorldHandler());
driver.activateContainer(builder);
for (int i = 0; i < NUM_REQUESTS; ++i) {
MyResponseHandler responseHandler = new MyResponseHandler();
driver.newRequestDispatch("http://localhost/", responseHandler).dispatch();
ByteBuffer buf = responseHandler.content.read();
assertNotNull(buf);
assertEquals("Hello World!", new String(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), UTF8));
assertNull(responseHandler.content.read());
}
assertTrue(driver.close());
}
use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.
the class ResourcePoolTestCase method requireThatResourcesAreReleasedOnDestroy.
@Test
public void requireThatResourcesAreReleasedOnDestroy() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ResourcePool pool = new ResourcePool(driver.newContainerBuilder());
MyResource foo = pool.add(new MyResource());
MyResource bar = pool.add(new MyResource());
MyResource baz = pool.add(new MyResource());
assertEquals(1, pool.retainCount());
assertEquals(1, foo.retainCount());
assertEquals(1, bar.retainCount());
assertEquals(1, baz.retainCount());
final ResourceReference secondPoolReference = pool.refer();
assertEquals(2, pool.retainCount());
assertEquals(1, foo.retainCount());
assertEquals(1, bar.retainCount());
assertEquals(1, baz.retainCount());
secondPoolReference.close();
assertEquals(1, pool.retainCount());
assertEquals(1, foo.retainCount());
assertEquals(1, bar.retainCount());
assertEquals(1, baz.retainCount());
pool.release();
assertEquals(0, pool.retainCount());
assertEquals(0, foo.retainCount());
assertEquals(0, bar.retainCount());
assertEquals(0, baz.retainCount());
assertTrue(driver.close());
}
Aggregations