Search in sources :

Example 11 with ContentChannel

use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.

the class ContainerShutdownTestCase method requireThatRequestContentCloseExceptionDoesNotBlockTermination.

@Test
public void requireThatRequestContentCloseExceptionDoesNotBlockTermination() {
    MyRequestHandler requestHandler = MyRequestHandler.newContentCloseException();
    Context ctx = Context.newPendingRequest(requestHandler);
    ContentChannel requestContent = ctx.request.connect(MyResponseHandler.newEagerCompletion());
    try {
        requestContent.close(null);
        fail();
    } catch (MyException e) {
    // ignore
    }
    ctx.request.release();
    requestHandler.respond().close(null);
    assertTrue(ctx.shutdown());
    assertTrue(ctx.driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Test(org.junit.Test)

Example 12 with ContentChannel

use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.

the class ContainerShutdownTestCase method requireThatRequestContentWriteExceptionWithCompletionDoesNotBlockTermination.

@Test
public void requireThatRequestContentWriteExceptionWithCompletionDoesNotBlockTermination() {
    MyRequestHandler requestHandler = MyRequestHandler.newContentWriteExceptionWithEagerCompletion();
    Context ctx = Context.newPendingRequest(requestHandler);
    ContentChannel requestContent = ctx.request.connect(MyResponseHandler.newEagerCompletion());
    try {
        requestContent.write(ByteBuffer.allocate(69), MyCompletion.newInstance());
        fail();
    } catch (MyException e) {
    // ignore
    }
    requestContent.close(null);
    ctx.request.release();
    requestHandler.respond().close(null);
    assertTrue(ctx.shutdown());
    assertTrue(ctx.driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Test(org.junit.Test)

Example 13 with ContentChannel

use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.

the class TimeoutManagerImplTestCase method requireThatTimeoutOccursAtExpectedTime.

@Test
public void requireThatTimeoutOccursAtExpectedTime() throws InterruptedException {
    final Context ctx = new Context(MyRequestHandler.newInstance());
    final MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    ctx.forwardToTime(100);
    new RequestDispatch() {

        @Override
        protected Request newRequest() {
            Request request = new Request(ctx.driver, URI.create(REQUEST_URI));
            request.setTimeout(300, TimeUnit.MILLISECONDS);
            return request;
        }

        @Override
        public ContentChannel handleResponse(Response response) {
            return responseHandler.handleResponse(response);
        }
    }.dispatch();
    ctx.forwardToTime(300);
    assertFalse(responseHandler.await(100, TimeUnit.MILLISECONDS));
    ctx.forwardToTime(400);
    assertTrue(responseHandler.await(600, TimeUnit.SECONDS));
    Response response = responseHandler.response.get();
    assertNotNull(response);
    assertEquals(Response.Status.GATEWAY_TIMEOUT, response.getStatus());
    assertTrue(ctx.close());
}
Also used : Response(com.yahoo.jdisc.Response) RequestDispatch(com.yahoo.jdisc.handler.RequestDispatch) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) NonWorkingRequest(com.yahoo.jdisc.test.NonWorkingRequest) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Example 14 with ContentChannel

use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.

the class TimeoutManagerImplTestCase method requireThatManagedHandlerForwardsAllCalls.

@Test
public void requireThatManagedHandlerForwardsAllCalls() throws InterruptedException {
    Request request = NonWorkingRequest.newInstance(REQUEST_URI);
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    TimeoutManagerImpl timeoutManager = new TimeoutManagerImpl(Executors.defaultThreadFactory(), new SystemTimer());
    RequestHandler managedHandler = timeoutManager.manageHandler(requestHandler);
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    ContentChannel requestContent = managedHandler.handleRequest(request, responseHandler);
    assertNotNull(requestContent);
    ByteBuffer buf = ByteBuffer.allocate(69);
    requestContent.write(buf, null);
    assertSame(buf, requestHandler.content.buf);
    MyCompletion writeCompletion = new MyCompletion();
    requestContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
    assertSame(buf, requestHandler.content.buf);
    requestHandler.content.writeCompletion.completed();
    assertTrue(writeCompletion.completed.await(600, TimeUnit.SECONDS));
    MyCompletion closeCompletion = new MyCompletion();
    requestContent.close(closeCompletion);
    requestHandler.content.closeCompletion.completed();
    assertTrue(closeCompletion.completed.await(600, TimeUnit.SECONDS));
    managedHandler.release();
    assertTrue(requestHandler.destroyed);
    Response response = new Response(Response.Status.OK);
    ContentChannel responseContent = requestHandler.responseHandler.handleResponse(response);
    assertNotNull(responseContent);
    responseContent.write(buf = ByteBuffer.allocate(69), null);
    assertSame(buf, responseHandler.content.buf);
    responseContent.write(buf = ByteBuffer.allocate(69), writeCompletion = new MyCompletion());
    assertSame(buf, responseHandler.content.buf);
    responseHandler.content.writeCompletion.completed();
    assertTrue(writeCompletion.completed.await(600, TimeUnit.SECONDS));
    responseContent.close(closeCompletion = new MyCompletion());
    responseHandler.content.closeCompletion.completed();
    assertTrue(closeCompletion.completed.await(600, TimeUnit.SECONDS));
    assertSame(response, responseHandler.response.get());
}
Also used : Response(com.yahoo.jdisc.Response) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) NonWorkingRequest(com.yahoo.jdisc.test.NonWorkingRequest) Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 15 with ContentChannel

use of com.yahoo.jdisc.handler.ContentChannel in project vespa by vespa-engine.

the class TimeoutManagerImplTestCase method requireThatResponseHandlerIsWellBehavedAfterTimeout.

@Test
public void requireThatResponseHandlerIsWellBehavedAfterTimeout() throws InterruptedException {
    Context ctx = new Context(MyRequestHandler.newInstance());
    assertEquals(Response.Status.GATEWAY_TIMEOUT, ctx.awaitResponse(69L, MyResponseHandler.newInstance()));
    ContentChannel content = ctx.requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK));
    assertNotNull(content);
    content.write(ByteBuffer.allocate(69), null);
    MyCompletion completion = new MyCompletion();
    content.write(ByteBuffer.allocate(69), completion);
    assertTrue(completion.completed.await(600, TimeUnit.SECONDS));
    completion = new MyCompletion();
    content.close(completion);
    assertTrue(completion.completed.await(600, TimeUnit.SECONDS));
    assertTrue(ctx.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Test(org.junit.Test)

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