use of com.yahoo.jdisc.handler.ContentChannel 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.handler.ContentChannel 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());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatResponseWriteCompletionCanOnlyBeCalledOnce.
@Test
public void requireThatResponseWriteCompletionCanOnlyBeCalledOnce() {
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.write(ByteBuffer.allocate(0), completion);
assertEquals(0, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
responseHandler.content.writeCompletion.completed();
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
responseHandler.content.writeCompletion.completed();
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
try {
responseHandler.content.writeCompletion.failed(new Throwable());
fail();
} catch (IllegalStateException e) {
// ignore
}
assertEquals(1, completion.numCompleted.get());
assertEquals(0, completion.numFailed.get());
resolvedContent.close(null);
responseHandler.content.closeCompletion.completed();
assertTrue(driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatResponseContentFailedIsProxied.
@Test
public void requireThatResponseContentFailedIsProxied() {
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);
MyException writeFailed = new MyException();
responseHandler.content.writeCompletion.failed(writeFailed);
assertFalse(writeCompletion.completed);
assertSame(writeFailed, writeCompletion.failed);
MyCompletion closeCompletion = new MyCompletion();
resolvedContent.close(closeCompletion);
assertTrue(responseHandler.content.closed);
assertFalse(closeCompletion.completed);
assertNull(closeCompletion.failed);
MyException closeFailed = new MyException();
responseHandler.content.closeCompletion.failed(closeFailed);
assertFalse(closeCompletion.completed);
assertSame(closeFailed, closeCompletion.failed);
assertTrue(driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatUncaughtCompletionFailureIsLogged.
@Test
public void requireThatUncaughtCompletionFailureIsLogged() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
MyRequestHandler requestHandler = MyRequestHandler.newInstance();
Request request = newRequest(driver, requestHandler);
ContentChannel resolvedContent = request.connect(MyResponseHandler.newEagerCompletion());
request.release();
MyLogHandler logHandler = new MyLogHandler();
Logger.getLogger(ProxyRequestHandler.class.getName()).addHandler(logHandler);
resolvedContent.write(ByteBuffer.allocate(69), null);
MyException writeFailed = new MyException();
requestHandler.content.writeCompletion.failed(writeFailed);
assertNotNull(logHandler.record);
assertSame(writeFailed, logHandler.record.getThrown());
resolvedContent.close(null);
MyException closeFailed = new MyException();
requestHandler.content.closeCompletion.failed(closeFailed);
assertNotNull(logHandler.record);
assertSame(closeFailed, logHandler.record.getThrown());
requestHandler.respond();
assertTrue(driver.close());
}
Aggregations