Search in sources :

Example 31 with TestDriver

use of com.yahoo.jdisc.test.TestDriver 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 32 with TestDriver

use of com.yahoo.jdisc.test.TestDriver 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 33 with TestDriver

use of com.yahoo.jdisc.test.TestDriver 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)

Example 34 with TestDriver

use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.

the class ContainerResourceTestCase method requireThatServerProvidersAreRetainedOnActivate.

@Test
public void requireThatServerProvidersAreRetainedOnActivate() {
    MyServerProvider foo = new MyServerProvider();
    MyServerProvider bar = new MyServerProvider();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverProviders().install(foo);
    builder.serverProviders().install(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 35 with TestDriver

use of com.yahoo.jdisc.test.TestDriver in project vespa by vespa-engine.

the class ContainerSnapshotTestCase method requireThatServerHandlerCanBeResolved.

@Test
public void requireThatServerHandlerCanBeResolved() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://foo/*", MyRequestHandler.newInstance());
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://foo/"));
    assertNotNull(request.container().resolveHandler(request));
    assertNotNull(request.getBindingMatch());
    request.release();
    request = new Request(driver, URI.create("http://foo/"));
    request.setServerRequest(false);
    assertNull(request.container().resolveHandler(request));
    assertNull(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)

Aggregations

TestDriver (com.yahoo.jdisc.test.TestDriver)134 Test (org.junit.Test)128 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)39 Request (com.yahoo.jdisc.Request)22 Bundle (org.osgi.framework.Bundle)14 AbstractModule (com.google.inject.AbstractModule)13 ByteBuffer (java.nio.ByteBuffer)12 Response (com.yahoo.jdisc.Response)10 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)10 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)6 Executor (java.util.concurrent.Executor)6 LinkedList (java.util.LinkedList)5 BundleContext (org.osgi.framework.BundleContext)4 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ServerProvider (com.yahoo.jdisc.service.ServerProvider)3 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BundleException (org.osgi.framework.BundleException)3 Module (com.google.inject.Module)2