Search in sources :

Example 51 with ContainerBuilder

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

the class ContainerResourceTestCase method requireThatBoundRequestHandlersAreReleasedOnTermination.

@Test
public void requireThatBoundRequestHandlersAreReleasedOnTermination() {
    MyRequestHandler handler = new MyRequestHandler();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", handler);
    driver.activateContainer(builder);
    Container container = driver.newReference(URI.create("http://localhost/"));
    assertEquals(1, handler.retainCnt.get());
    driver.activateContainer(null);
    assertEquals(1, handler.retainCnt.get());
    container.release();
    assertEquals(0, handler.retainCnt.get());
    assertTrue(driver.close());
}
Also used : Container(com.yahoo.jdisc.Container) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 52 with ContainerBuilder

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

Example 53 with ContainerBuilder

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

the class TestDriver method newInstance.

public static TestDriver newInstance(Class<? extends JettyHttpServer> serverClass, RequestHandler requestHandler, Module testConfig) throws IOException {
    com.yahoo.jdisc.test.TestDriver driver = com.yahoo.jdisc.test.TestDriver.newSimpleApplicationInstance(testConfig);
    ContainerBuilder builder = driver.newContainerBuilder();
    JettyHttpServer server = builder.getInstance(serverClass);
    builder.serverProviders().install(server);
    builder.serverBindings().bind("*://*/*", requestHandler);
    driver.activateContainer(builder);
    server.start();
    SimpleHttpClient client = new SimpleHttpClient(newSslContext(builder), server.getListenPort(), false);
    return new TestDriver(driver, server, client);
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder)

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