Search in sources :

Example 26 with ContainerBuilder

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

the class CallableRequestDispatchTestCase method requireThatDispatchIsCalled.

@Test
public void requireThatDispatchIsCalled() throws Exception {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    Response response = new Response(Response.Status.OK);
    builder.serverBindings().bind("http://host/path", new MyRequestHandler(response));
    driver.activateContainer(builder);
    assertSame(response, new CallableRequestDispatch() {

        @Override
        protected Request newRequest() {
            return new Request(driver, URI.create("http://host/path"));
        }
    }.call());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 27 with ContainerBuilder

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

the class RequestDeniedTestCase method requireThatRequestDeniedIsThrown.

@Test
public void requireThatRequestDeniedIsThrown() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    RequestHandler requestHandler = new MyRequestHandler();
    builder.serverBindings().bind("http://host/path", requestHandler);
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://host/path"));
    try {
        request.connect(new MyResponseHandler());
        fail();
    } catch (RequestDeniedException e) {
        assertSame(request, e.request());
    }
    request.release();
    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 28 with ContainerBuilder

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

the class TestDriverTestCase method requireThatDispatchRequestWorks.

@Test
public void requireThatDispatchRequestWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = new MyRequestHandler(new MyContentChannel());
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("scheme://host/path", requestHandler);
    driver.activateContainer(builder);
    driver.dispatchRequest("scheme://host/path", new MyResponseHandler());
    assertNotNull(requestHandler.handler);
    assertTrue(requestHandler.content.closed);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Test(org.junit.Test)

Example 29 with ContainerBuilder

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

the class TestDriverTestCase method requireThatConnectRequestWorks.

@Test
public void requireThatConnectRequestWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = new MyRequestHandler(new MyContentChannel());
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("scheme://host/path", requestHandler);
    driver.activateContainer(builder);
    ContentChannel content = driver.connectRequest("scheme://host/path", new MyResponseHandler());
    assertNotNull(content);
    content.close(null);
    assertNotNull(requestHandler.handler);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Test(org.junit.Test)

Example 30 with ContainerBuilder

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

the class TestDriverTestCase method requireThatFailedRequestConnectDoesNotBlockClose.

@Test
public void requireThatFailedRequestConnectDoesNotBlockClose() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("scheme://host/path", new MyRequestHandler(null));
    driver.activateContainer(builder);
    try {
        driver.connectRequest("scheme://host/path", new MyResponseHandler());
        fail();
    } catch (RequestDeniedException e) {
    }
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) Test(org.junit.Test)

Aggregations

ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)53 Test (org.junit.Test)41 TestDriver (com.yahoo.jdisc.test.TestDriver)40 Request (com.yahoo.jdisc.Request)16 Response (com.yahoo.jdisc.Response)12 ByteBuffer (java.nio.ByteBuffer)7 Executor (java.util.concurrent.Executor)6 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)4 AbstractModule (com.google.inject.AbstractModule)3 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)3 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)3 Container (com.yahoo.jdisc.Container)2 UriPattern (com.yahoo.jdisc.application.UriPattern)2 Map (java.util.Map)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Module (com.google.inject.Module)1 Pair (com.yahoo.collections.Pair)1