Search in sources :

Example 41 with Request

use of com.yahoo.jdisc.Request 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 42 with Request

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

the class RequestDispatchTestCase method requireThatDispatchCanBeListenedTo.

@Test
public void requireThatDispatchCanBeListenedTo() throws InterruptedException {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ReadableContentChannel requestContent = new ReadableContentChannel();
    MyRequestHandler requestHandler = new MyRequestHandler(requestContent, null);
    builder.serverBindings().bind("http://localhost/", requestHandler);
    driver.activateContainer(builder);
    RunnableLatch listener = new RunnableLatch();
    new RequestDispatch() {

        @Override
        protected Request newRequest() {
            return new Request(driver, URI.create("http://localhost/"));
        }
    }.dispatch().addListener(listener, MoreExecutors.directExecutor());
    assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
    ContentChannel responseContent = ResponseDispatch.newInstance(Response.Status.OK).connect(requestHandler.responseHandler);
    assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
    assertNull(requestContent.read());
    assertTrue(listener.await(600, TimeUnit.SECONDS));
    responseContent.close(null);
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 43 with Request

use of com.yahoo.jdisc.Request 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)

Example 44 with Request

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

the class ContainerSnapshotTestCase method requireThatClientHandlerCanBeResolved.

@Test
public void requireThatClientHandlerCanBeResolved() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.clientBindings().bind("http://foo/*", MyRequestHandler.newInstance());
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://foo/"));
    assertNull(request.container().resolveHandler(request));
    assertNull(request.getBindingMatch());
    request.release();
    request = new Request(driver, URI.create("http://foo/"));
    request.setServerRequest(false);
    assertNotNull(request.container().resolveHandler(request));
    assertNotNull(request.getBindingMatch());
    request.release();
    request = new Request(driver, URI.create("http://bar/"));
    assertNull(request.container().resolveHandler(request));
    assertNull(request.getBindingMatch());
    request.release();
    request = new Request(driver, URI.create("http://bar/"));
    request.setServerRequest(false);
    assertNull(request.container().resolveHandler(request));
    assertNull(request.getBindingMatch());
    request.release();
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

Request (com.yahoo.jdisc.Request)44 Test (org.junit.Test)31 TestDriver (com.yahoo.jdisc.test.TestDriver)22 Response (com.yahoo.jdisc.Response)17 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)16 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)10 ByteBuffer (java.nio.ByteBuffer)7 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)4 RequestDispatch (com.yahoo.jdisc.handler.RequestDispatch)3 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)3 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 Callable (java.util.concurrent.Callable)3 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)2 HttpRequest (com.yahoo.jdisc.http.HttpRequest)2 URI (java.net.URI)2 Executor (java.util.concurrent.Executor)2 Test (org.testng.annotations.Test)2 AbstractModule (com.google.inject.AbstractModule)1 ResourceReference (com.yahoo.jdisc.ResourceReference)1