Search in sources :

Example 16 with ContentChannel

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();
        }
    });
}
Also used : Response(com.yahoo.jdisc.Response) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) Callable(java.util.concurrent.Callable)

Example 17 with ContentChannel

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());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 18 with ContentChannel

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;
}
Also used : Response(com.yahoo.jdisc.Response) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) URI(java.net.URI) ByteBuffer(java.nio.ByteBuffer)

Example 19 with ContentChannel

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) {
    }
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Test(org.junit.Test)

Example 20 with ContentChannel

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);
        }
    }
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) LinkedList(java.util.LinkedList) List(java.util.List) ResourceReference(com.yahoo.jdisc.ResourceReference) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ContentChannel (com.yahoo.jdisc.handler.ContentChannel)48 Test (org.junit.Test)31 Request (com.yahoo.jdisc.Request)10 Response (com.yahoo.jdisc.Response)10 TestDriver (com.yahoo.jdisc.test.TestDriver)10 ByteBuffer (java.nio.ByteBuffer)7 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)6 HttpRequest (com.yahoo.jdisc.http.HttpRequest)4 ResourceReference (com.yahoo.jdisc.ResourceReference)3 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)3 Callable (java.util.concurrent.Callable)3 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)2 BindingNotFoundException (com.yahoo.jdisc.handler.BindingNotFoundException)2 RequestDeniedException (com.yahoo.jdisc.handler.RequestDeniedException)2 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)2 AbstractRequestHandler (com.yahoo.jdisc.handler.AbstractRequestHandler)1 BufferedContentChannel (com.yahoo.jdisc.handler.BufferedContentChannel)1 ReadableContentChannel (com.yahoo.jdisc.handler.ReadableContentChannel)1 RequestDispatch (com.yahoo.jdisc.handler.RequestDispatch)1 HttpResponse (com.yahoo.jdisc.http.HttpResponse)1