Search in sources :

Example 11 with ContainerBuilder

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

the class ActiveContainerTestCase method requireThatServerBindingAccessorWorks.

@Test
public void requireThatServerBindingAccessorWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    RequestHandler foo = new NonWorkingRequestHandler();
    RequestHandler bar = new NonWorkingRequestHandler();
    builder.serverBindings().bind("http://host/foo", foo);
    builder.serverBindings("bar").bind("http://host/bar", bar);
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.serverBindings();
    assertNotNull(bindings);
    assertEquals(2, bindings.size());
    BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
    assertNotNull(set);
    Iterator<Map.Entry<UriPattern, RequestHandler>> it = set.iterator();
    assertNotNull(it);
    assertTrue(it.hasNext());
    Map.Entry<UriPattern, RequestHandler> entry = it.next();
    assertNotNull(entry);
    assertEquals(new UriPattern("http://host/foo"), entry.getKey());
    assertSame(foo, entry.getValue());
    assertFalse(it.hasNext());
    assertNotNull(set = bindings.get("bar"));
    assertNotNull(it = set.iterator());
    assertTrue(it.hasNext());
    assertNotNull(entry = it.next());
    assertEquals(new UriPattern("http://host/bar"), entry.getKey());
    assertSame(bar, entry.getValue());
    assertFalse(it.hasNext());
    assertNotNull(bindings = container.clientBindings());
    assertEquals(1, bindings.size());
    assertNotNull(set = bindings.get(BindingSet.DEFAULT));
    assertNotNull(it = set.iterator());
    assertFalse(it.hasNext());
    driver.close();
}
Also used : BindingSet(com.yahoo.jdisc.application.BindingSet) UriPattern(com.yahoo.jdisc.application.UriPattern) TestDriver(com.yahoo.jdisc.test.TestDriver) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) Map(java.util.Map) Test(org.junit.Test)

Example 12 with ContainerBuilder

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

the class ActiveContainerTestCase method requireThatServerAccessorWorks.

@Test
public void requireThatServerAccessorWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ServerProvider foo = new NonWorkingServerProvider();
    builder.serverProviders().install(foo);
    ServerProvider bar = new NonWorkingServerProvider();
    builder.serverProviders().install(bar);
    ActiveContainer container = new ActiveContainer(builder);
    Iterator<ServerProvider> it = container.serverProviders().iterator();
    assertTrue(it.hasNext());
    assertSame(foo, it.next());
    assertTrue(it.hasNext());
    assertSame(bar, it.next());
    assertFalse(it.hasNext());
    driver.close();
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) NonWorkingServerProvider(com.yahoo.jdisc.test.NonWorkingServerProvider) ServerProvider(com.yahoo.jdisc.service.ServerProvider) NonWorkingServerProvider(com.yahoo.jdisc.test.NonWorkingServerProvider) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 13 with ContainerBuilder

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

the class ApplicationRestartTestCase method assertGracefulStop.

private static void assertGracefulStop(ApplicationLoader loader) throws Exception {
    MyRequestHandler requestHandler = new MyRequestHandler();
    ContainerBuilder builder = loader.newContainerBuilder();
    builder.serverBindings().bind("http://host/path", requestHandler);
    loader.activateContainer(builder);
    MyResponseHandler responseHandler = new MyResponseHandler();
    Request request = new Request(loader, URI.create("http://host/path"));
    request.connect(responseHandler).close(null);
    request.release();
    StopTask task = new StopTask(loader);
    task.start();
    assertFalse(task.latch.await(100, TimeUnit.MILLISECONDS));
    requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(task.latch.await(600, TimeUnit.SECONDS));
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request)

Example 14 with ContainerBuilder

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

the class ContainerResourceTestCase method requireThatBoundRequestHandlersAreRetainedOnActivate.

@Test
public void requireThatBoundRequestHandlersAreRetainedOnActivate() {
    MyRequestHandler foo = new MyRequestHandler();
    MyRequestHandler bar = new MyRequestHandler();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings("foo").bind("http://foo/", foo);
    builder.serverBindings("bar").bind("http://bar/", bar);
    assertEquals(0, foo.retainCnt.get());
    assertEquals(0, bar.retainCnt.get());
    driver.activateContainer(builder);
    assertEquals(1, foo.retainCnt.get());
    assertEquals(1, bar.retainCnt.get());
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 15 with ContainerBuilder

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

the class ContainerResourceTestCase method requireThatServerProvidersAreReleasedOnTermination.

@Test
public void requireThatServerProvidersAreReleasedOnTermination() {
    MyServerProvider server = new MyServerProvider();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverProviders().install(server);
    driver.activateContainer(builder);
    Container container = driver.newReference(URI.create("http://localhost/"));
    assertEquals(1, server.retainCnt.get());
    driver.activateContainer(null);
    assertEquals(1, server.retainCnt.get());
    container.release();
    assertEquals(0, server.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)

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