Search in sources :

Example 36 with ContentChannel

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

Example 37 with ContentChannel

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

Example 38 with ContentChannel

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

Example 39 with ContentChannel

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

Example 40 with ContentChannel

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());
}
Also used : 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