Search in sources :

Example 41 with ContainerBuilder

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

the class ActiveContainerTestCase method requireThatClientBindingAccessorWorks.

@Test
public void requireThatClientBindingAccessorWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    RequestHandler foo = new NonWorkingRequestHandler();
    RequestHandler bar = new NonWorkingRequestHandler();
    builder.clientBindings().bind("http://host/foo", foo);
    builder.clientBindings("bar").bind("http://host/bar", bar);
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.clientBindings();
    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.serverBindings());
    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 42 with ContainerBuilder

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

the class ActiveContainerTestCase method requireThatDefaultBindingsAreAlwaysCreated.

@Test
public void requireThatDefaultBindingsAreAlwaysCreated() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.serverBindings();
    assertNotNull(bindings);
    assertEquals(1, bindings.size());
    BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
    assertFalse(set.iterator().hasNext());
    driver.close();
}
Also used : BindingSet(com.yahoo.jdisc.application.BindingSet) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 43 with ContainerBuilder

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

the class ApplicationEnvironmentModuleTestCase method requireThatContainerBuilderCanBeInjected.

@Test
public void requireThatContainerBuilderCanBeInjected() {
    ApplicationLoader loader = new ApplicationLoader(new NonWorkingOsgiFramework(), Collections.<Module>emptyList());
    assertNotNull(new ApplicationEnvironmentModule(loader).containerBuilder());
    assertNotNull(Guice.createInjector(new ApplicationEnvironmentModule(loader)).getInstance(ContainerBuilder.class));
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) NonWorkingOsgiFramework(com.yahoo.jdisc.test.NonWorkingOsgiFramework) Test(org.junit.Test)

Example 44 with ContainerBuilder

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

the class ThreadedRequestHandlerTestCase method requireThatThreadedRequestHandlerRetainsTheRequestUntilHandlerIsRun.

@Test
public void requireThatThreadedRequestHandlerRetainsTheRequestUntilHandlerIsRun() throws Exception {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    final AtomicInteger baseRetainCount = new AtomicInteger();
    builder.serverBindings().bind("http://localhost/base", new AbstractRequestHandler() {

        @Override
        public ContentChannel handleRequest(Request request, ResponseHandler handler) {
            baseRetainCount.set(request.retainCount());
            handler.handleResponse(new Response(Response.Status.OK)).close(null);
            return null;
        }
    });
    final CountDownLatch entryLatch = new CountDownLatch(1);
    final CountDownLatch exitLatch = new CountDownLatch(1);
    final AtomicInteger testRetainCount = new AtomicInteger();
    builder.serverBindings().bind("http://localhost/test", new ThreadedRequestHandler(newExecutor()) {

        @Override
        public void handleRequest(Request request, ReadableContentChannel requestContent, ResponseHandler responseHandler) {
            try {
                entryLatch.await(600, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                return;
            }
            testRetainCount.set(request.retainCount());
            responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
            // drain content to call completion handlers
            requestContent.read();
            exitLatch.countDown();
        }
    });
    driver.activateContainer(builder);
    dispatchRequest(driver, "http://localhost/base");
    dispatchRequest(driver, "http://localhost/test");
    entryLatch.countDown();
    exitLatch.await(600, TimeUnit.SECONDS);
    assertEquals(baseRetainCount.get(), testRetainCount.get());
    assertTrue(driver.close());
}
Also used : Request(com.yahoo.jdisc.Request) CountDownLatch(java.util.concurrent.CountDownLatch) TestDriver(com.yahoo.jdisc.test.TestDriver) Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 45 with ContainerBuilder

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

the class ThreadedRequestHandlerTestCase method newTestDriver.

private static TestDriver newTestDriver(String uri, RequestHandler requestHandler) {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind(uri, requestHandler);
    driver.activateContainer(builder);
    return driver;
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver)

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