Search in sources :

Example 36 with ContainerBuilder

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

the class AbstractServerProviderTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    MyServerProvider server = builder.getInstance(MyServerProvider.class);
    assertNotNull(server.container());
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 37 with ContainerBuilder

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

the class ConnectToHandlerTestCase method requireThatConnectToHandlerWorks.

@Test
public void requireThatConnectToHandlerWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = new MyRequestHandler(new MyContent());
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://host/*", requestHandler);
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://host/path"));
    MyResponseHandler responseHandler = new MyResponseHandler();
    ContentChannel content = request.connect(responseHandler);
    request.release();
    assertNotNull(content);
    content.close(null);
    assertNotNull(requestHandler.handler);
    assertSame(request, requestHandler.request);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    driver.close();
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 38 with ContainerBuilder

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

the class ProxyRequestHandlerTestCase method newRequest.

private static Request newRequest(TestDriver driver, RequestHandler requestHandler) {
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://host/path", requestHandler);
    driver.activateContainer(builder);
    return new Request(driver, URI.create("http://host/path"));
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder)

Example 39 with ContainerBuilder

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

the class AbstractRequestHandlerTestCase method requireThatEchoWorks.

@Test
public void requireThatEchoWorks() throws InterruptedException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", new EchoHandler());
    driver.activateContainer(builder);
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        MyResponseHandler responseHandler = new MyResponseHandler();
        RequestDispatch dispatch = driver.newRequestDispatch("http://localhost/", responseHandler);
        FastContentWriter requestContent = dispatch.connectFastWriter();
        ByteBuffer buf = ByteBuffer.allocate(69);
        requestContent.write(buf);
        requestContent.close();
        assertSame(buf, responseHandler.content.read());
        assertNull(responseHandler.content.read());
    }
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 40 with ContainerBuilder

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

the class AbstractRequestHandlerTestCase method requireThatHelloWorldWorks.

@Test
public void requireThatHelloWorldWorks() throws InterruptedException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", new HelloWorldHandler());
    driver.activateContainer(builder);
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        MyResponseHandler responseHandler = new MyResponseHandler();
        driver.newRequestDispatch("http://localhost/", responseHandler).dispatch();
        ByteBuffer buf = responseHandler.content.read();
        assertNotNull(buf);
        assertEquals("Hello World!", new String(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), UTF8));
        assertNull(responseHandler.content.read());
    }
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) 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