use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestExceptionAfterResponseWriteWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestExceptionAfterResponseWriteWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {
@Override
public ContentChannel handle(final Request request, final ResponseHandler handler) {
callInOtherThread(new Callable<Void>() {
@Override
public Void call() throws Exception {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
writeResponse(out);
closeResponse(out);
return null;
}
});
responseWritten.await();
throw new ConformanceException();
}
});
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class ProxyRequestHandlerTestCase method requireThatRequestContentCompletedIsProxied.
@Test
public void requireThatRequestContentCompletedIsProxied() {
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);
requestHandler.content.writeCompletion.completed();
assertTrue(writeCompletion.completed);
assertNull(writeCompletion.failed);
MyCompletion closeCompletion = new MyCompletion();
resolvedContent.close(closeCompletion);
assertTrue(requestHandler.content.closed);
assertFalse(closeCompletion.completed);
assertNull(writeCompletion.failed);
requestHandler.content.closeCompletion.completed();
assertTrue(closeCompletion.completed);
assertNull(closeCompletion.failed);
requestHandler.respond();
assertTrue(driver.close());
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class LatencyTestCase method measureLatency.
private static TimeFrame measureLatency(CurrentContainer container, MyRequestHandler requestHandler) {
TimeFrame frame = new TimeFrame();
Request request = null;
ContentChannel requestContent = null;
MyResponseHandler responseHandler = new MyResponseHandler();
try {
URI uri = URI.create(requestHandler.uri);
request = new Request(container, uri);
frame.handleRequestBegin = System.nanoTime();
requestContent = request.connect(responseHandler);
frame.handleRequestEnd = requestHandler.handleTime;
} finally {
if (request != null) {
request.release();
}
}
ByteBuffer buf = ByteBuffer.allocate(69);
MyCompletion requestWrite = new MyCompletion();
frame.requestWriteBegin = System.nanoTime();
requestContent.write(buf, requestWrite);
frame.requestWriteEnd = requestHandler.requestContent.writeTime;
frame.requestWriteCompletionBegin = System.nanoTime();
requestHandler.requestContent.writeCompletion.completed();
frame.requestWriteCompletionEnd = requestWrite.completedTime;
MyCompletion requestClose = new MyCompletion();
frame.requestCloseBegin = System.nanoTime();
requestContent.close(requestClose);
frame.requestCloseEnd = requestHandler.requestContent.closeTime;
frame.requestCloseCompletionBegin = System.nanoTime();
requestHandler.requestContent.closeCompletion.completed();
frame.requestCloseCompletionEnd = requestClose.completedTime;
Response response = new Response(Response.Status.OK);
frame.handleResponseBegin = System.nanoTime();
ContentChannel responseContent = requestHandler.responseHandler.handleResponse(response);
frame.handleResponseEnd = responseHandler.handleTime;
MyCompletion responseWrite = new MyCompletion();
frame.responseWriteBegin = System.nanoTime();
responseContent.write(buf, responseWrite);
frame.responseWriteEnd = responseHandler.responseContent.writeTime;
frame.responseWriteCompletionBegin = System.nanoTime();
responseHandler.responseContent.writeCompletion.completed();
frame.responseWriteCompletionEnd = responseWrite.completedTime;
MyCompletion responseClose = new MyCompletion();
frame.responseCloseBegin = System.nanoTime();
responseContent.close(responseClose);
frame.responseCloseEnd = responseHandler.responseContent.closeTime;
frame.responseCloseCompletionBegin = System.nanoTime();
responseHandler.responseContent.closeCompletion.completed();
frame.responseCloseCompletionEnd = responseClose.completedTime;
return frame;
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class NonWorkingContentChannelTestCase method requireThatCloseThrowsException.
@Test
public void requireThatCloseThrowsException() {
ContentChannel content = new NonWorkingContentChannel();
try {
content.close(null);
fail();
} catch (UnsupportedOperationException e) {
}
content = new NonWorkingContentChannel();
try {
content.close(new MyCompletion());
fail();
} catch (UnsupportedOperationException e) {
}
}
use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.
the class FormPostRequestHandler method close.
@SuppressWarnings("try")
@Override
public void close(final CompletionHandler completionHandler) {
try (final ResourceReference ref = requestReference) {
final byte[] requestContentBytes = accumulatedRequestContent.toByteArray();
final String content = new String(requestContentBytes, contentCharset);
completionHandler.completed();
final Map<String, List<String>> parameterMap = parseFormParameters(content);
mergeParameters(parameterMap, request.parameters());
final ContentChannel contentChannel = delegateHandler.handleRequest(request, responseHandler);
if (contentChannel != null) {
if (!removeBody) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(requestContentBytes);
contentChannel.write(byteBuffer, NOOP_COMPLETION_HANDLER);
}
contentChannel.close(NOOP_COMPLETION_HANDLER);
}
}
}
Aggregations