use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatRequestContentFailedIsProxied.
@Test
public void requireThatRequestContentFailedIsProxied() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
Request request = newRequest(driver, requestHandler);
ContentChannel resolvedContent = request.connect(MyResponseHandler.newEagerCompletion());
request.release();
assertSame(request, requestHandler.request);
ByteBuffer buf = ByteBuffer.allocate(69);
resolvedContent.write(buf, null);
assertSame(buf, requestHandler.content.writeBuf);
requestHandler.content.writeCompletion.completed();
MyCompletion writeCompletion = new MyCompletion();
resolvedContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
assertSame(buf, requestHandler.content.writeBuf);
assertFalse(writeCompletion.completed);
assertNull(writeCompletion.failed);
MyException writeFailed = new MyException();
requestHandler.content.writeCompletion.failed(writeFailed);
assertFalse(writeCompletion.completed);
assertSame(writeFailed, writeCompletion.failed);
MyCompletion closeCompletion = new MyCompletion();
resolvedContent.close(closeCompletion);
assertTrue(requestHandler.content.closed);
assertFalse(closeCompletion.completed);
assertNull(closeCompletion.failed);
MyException closeFailed = new MyException();
requestHandler.content.closeCompletion.failed(closeFailed);
assertFalse(writeCompletion.completed);
assertSame(closeFailed, closeCompletion.failed);
requestHandler.respond();
assertTrue(driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatRequestCloseCompletionCanOnlyBeCalledOnce.
@Test
public void requireThatRequestCloseCompletionCanOnlyBeCalledOnce() {
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.close(completion);
assertEquals(0, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
requestHandler.content.closeCompletion.completed();
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
requestHandler.content.closeCompletion.completed();
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
requestHandler.content.closeCompletion.failed(new Throwable());
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
requestHandler.respond();
assertTrue(driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel 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.handler.ContentChannel in project vespa by vespa-engine.
the class ContainerShutdownTestCase method requireThatRequestWriteCompletionBlocksTermination.
@Test
public void requireThatRequestWriteCompletionBlocksTermination() {
MyRequestHandler requestHandler = MyRequestHandler.newEagerCloseResponse();
Context ctx = Context.newPendingRequest(requestHandler);
ContentChannel requestContent = ctx.request.connect(MyResponseHandler.newEagerCompletion());
ctx.request.release();
requestContent.write(null, MyCompletion.newInstance());
requestContent.close(null);
requestHandler.requestContent.closeCompletion.completed();
assertFalse(ctx.shutdown());
requestHandler.requestContent.writeCompletion.completed();
assertTrue(ctx.terminated);
assertTrue(ctx.driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ContainerShutdownTestCase method requireThatRequestCloseCompletionExceptionDoesNotBlockTermination.
@Test
public void requireThatRequestCloseCompletionExceptionDoesNotBlockTermination() {
MyRequestHandler requestHandler = MyRequestHandler.newEagerCloseResponse();
Context ctx = Context.newPendingRequest(requestHandler);
ContentChannel requestContent = ctx.request.connect(MyResponseHandler.newEagerCompletion());
ctx.request.release();
requestContent.close(MyCompletion.newException());
assertFalse(ctx.shutdown());
try {
requestHandler.requestContent.closeCompletion.completed();
fail();
} catch (MyException e) {
// ignore
}
assertTrue(ctx.terminated);
assertTrue(ctx.driver.close());
}
Aggregations