Search in sources :

Example 51 with Response

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

the class RequestDispatchTestCase method requireThatDispatchHandlesCloseException.

@Test
public void requireThatDispatchHandlesCloseException() {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    Response response = new Response(Response.Status.OK);
    builder.serverBindings().bind("http://localhost/", new MyRequestHandler(new ContentChannel() {

        @Override
        public void write(ByteBuffer buf, CompletionHandler handler) {
            handler.completed();
        }

        @Override
        public void close(CompletionHandler handler) {
            throw new RuntimeException();
        }
    }, response));
    driver.activateContainer(builder);
    try {
        new RequestDispatch() {

            @Override
            protected Request newRequest() {
                return new Request(driver, URI.create("http://localhost/"));
            }

            @Override
            protected Iterable<ByteBuffer> requestContent() {
                return Arrays.asList(ByteBuffer.allocate(69));
            }
        }.dispatch();
        fail();
    } catch (RuntimeException e) {
    }
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 52 with Response

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

the class RequestDispatchTestCase method requireThatDispatchHandlesWriteException.

@Test
public void requireThatDispatchHandlesWriteException() {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    Response response = new Response(Response.Status.OK);
    builder.serverBindings().bind("http://localhost/", new MyRequestHandler(new ContentChannel() {

        @Override
        public void write(ByteBuffer buf, CompletionHandler handler) {
            throw new RuntimeException();
        }

        @Override
        public void close(CompletionHandler handler) {
            handler.completed();
        }
    }, response));
    driver.activateContainer(builder);
    try {
        new RequestDispatch() {

            @Override
            protected Request newRequest() {
                return new Request(driver, URI.create("http://localhost/"));
            }

            @Override
            protected Iterable<ByteBuffer> requestContent() {
                return Arrays.asList(ByteBuffer.allocate(69));
            }
        }.dispatch();
        fail();
    } catch (RuntimeException e) {
    }
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

Response (com.yahoo.jdisc.Response)52 Test (org.junit.Test)39 Request (com.yahoo.jdisc.Request)17 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)14 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)11 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)11 TestDriver (com.yahoo.jdisc.test.TestDriver)10 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)7 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)6 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 ByteBuffer (java.nio.ByteBuffer)6 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)5 Chain (com.yahoo.component.chain.Chain)3 HttpRequest (com.yahoo.jdisc.http.HttpRequest)3 HttpResponse (com.yahoo.jdisc.http.HttpResponse)3 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)3 Reply (com.yahoo.messagebus.Reply)3 Processor (com.yahoo.processing.Processor)3 Callable (java.util.concurrent.Callable)3 Test (org.testng.annotations.Test)3