Search in sources :

Example 31 with ContentChannel

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

Example 32 with ContentChannel

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

Example 33 with ContentChannel

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

Example 34 with ContentChannel

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

Example 35 with ContentChannel

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