Search in sources :

Example 21 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatRequestHandlerIsProxied.

@Test
public void requireThatRequestHandlerIsProxied() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
    Request request = newRequest(driver, requestHandler);
    RequestHandler resolvedHandler = new ProxyRequestHandler(request.container().resolveHandler(request));
    MyResponseHandler responseHandler = MyResponseHandler.newEagerCompletion();
    resolvedHandler.handleRequest(request, responseHandler).close(null);
    request.release();
    assertNotNull(requestHandler.handler);
    resolvedHandler.handleTimeout(request, responseHandler);
    assertTrue(requestHandler.timeout);
    requestHandler.respond();
    requestHandler.release();
    final ResourceReference resolvedHandlerReference = resolvedHandler.refer();
    // release installed ref
    assertTrue(driver.close());
    assertFalse(requestHandler.destroyed);
    resolvedHandlerReference.close();
    assertTrue(requestHandler.destroyed);
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 22 with TestDriver

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

the class ResourcePoolTestCase method requireThatAddReturnsArgument.

@Test
public void requireThatAddReturnsArgument() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyResource foo = new MyResource();
    assertSame(foo, new ResourcePool(driver.newContainerBuilder()).add(foo));
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 23 with TestDriver

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

the class ResourcePoolTestCase method requireThatGetReturnsBoundInstance.

@Test
public void requireThatGetReturnsBoundInstance() {
    final MyResource foo = new MyResource();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

        @Override
        protected void configure() {
            bind(MyResource.class).toInstance(foo);
        }
    });
    ResourcePool pool = new ResourcePool(driver.newContainerBuilder());
    assertSame(foo, pool.get(MyResource.class));
    assertSame(foo, pool.get(Key.get(MyResource.class)));
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 24 with TestDriver

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

the class ResourcePoolTestCase method requireThatRetainReturnsArgument.

@Test
public void requireThatRetainReturnsArgument() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyResource foo = new MyResource();
    assertSame(foo, new ResourcePool(driver.newContainerBuilder()).retain(foo));
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 25 with TestDriver

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

the class ResourcePoolTestCase method requireThatGetDoesNotRetainArgument.

@Test
public void requireThatGetDoesNotRetainArgument() {
    final MyResource foo = new MyResource();
    assertEquals(1, foo.retainCount());
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

        @Override
        protected void configure() {
            bind(MyResource.class).toInstance(foo);
        }
    });
    ResourcePool pool = new ResourcePool(driver.newContainerBuilder());
    pool.get(MyResource.class);
    assertEquals(1, foo.retainCount());
    pool.get(Key.get(MyResource.class));
    assertEquals(1, foo.retainCount());
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) AbstractModule(com.google.inject.AbstractModule) 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