Search in sources :

Example 86 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatNullResponseContentIsProxied.

@Test
public void requireThatNullResponseContentIsProxied() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
    Request request = newRequest(driver, requestHandler);
    ResponseHandler responseHandler = new ResponseHandler() {

        @Override
        public ContentChannel handleResponse(Response response) {
            return null;
        }
    };
    request.connect(responseHandler).close(null);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    request.release();
    assertTrue(driver.close());
}
Also used : ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 87 with TestDriver

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

the class ProxyRequestHandlerTestCase method requireThatResponseContentCompletedIsProxied.

@Test
public void requireThatResponseContentCompletedIsProxied() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
    Request request = newRequest(driver, requestHandler);
    MyResponseHandler responseHandler = MyResponseHandler.newInstance();
    request.connect(responseHandler).close(null);
    request.release();
    Response response = new Response(Response.Status.OK);
    ContentChannel resolvedContent = requestHandler.handler.handleResponse(response);
    assertSame(response, responseHandler.response);
    ByteBuffer buf = ByteBuffer.allocate(69);
    resolvedContent.write(buf, null);
    assertSame(buf, responseHandler.content.writeBuf);
    responseHandler.content.writeCompletion.completed();
    MyCompletion writeCompletion = new MyCompletion();
    resolvedContent.write(buf = ByteBuffer.allocate(69), writeCompletion);
    assertSame(buf, responseHandler.content.writeBuf);
    assertFalse(writeCompletion.completed);
    assertNull(writeCompletion.failed);
    responseHandler.content.writeCompletion.completed();
    assertTrue(writeCompletion.completed);
    assertNull(writeCompletion.failed);
    MyCompletion closeCompletion = new MyCompletion();
    resolvedContent.close(closeCompletion);
    assertTrue(responseHandler.content.closed);
    assertFalse(closeCompletion.completed);
    assertNull(closeCompletion.failed);
    responseHandler.content.closeCompletion.completed();
    assertTrue(closeCompletion.completed);
    assertNull(closeCompletion.failed);
    assertTrue(driver.close());
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 88 with TestDriver

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

the class AbstractRequestHandlerTestCase method requireThatEchoWorks.

@Test
public void requireThatEchoWorks() throws InterruptedException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", new EchoHandler());
    driver.activateContainer(builder);
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        MyResponseHandler responseHandler = new MyResponseHandler();
        RequestDispatch dispatch = driver.newRequestDispatch("http://localhost/", responseHandler);
        FastContentWriter requestContent = dispatch.connectFastWriter();
        ByteBuffer buf = ByteBuffer.allocate(69);
        requestContent.write(buf);
        requestContent.close();
        assertSame(buf, responseHandler.content.read());
        assertNull(responseHandler.content.read());
    }
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 89 with TestDriver

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

the class AbstractRequestHandlerTestCase method requireThatHelloWorldWorks.

@Test
public void requireThatHelloWorldWorks() throws InterruptedException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", new HelloWorldHandler());
    driver.activateContainer(builder);
    for (int i = 0; i < NUM_REQUESTS; ++i) {
        MyResponseHandler responseHandler = new MyResponseHandler();
        driver.newRequestDispatch("http://localhost/", responseHandler).dispatch();
        ByteBuffer buf = responseHandler.content.read();
        assertNotNull(buf);
        assertEquals("Hello World!", new String(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), UTF8));
        assertNull(responseHandler.content.read());
    }
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 90 with TestDriver

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

the class ResourcePoolTestCase method requireThatResourcesAreReleasedOnDestroy.

@Test
public void requireThatResourcesAreReleasedOnDestroy() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ResourcePool pool = new ResourcePool(driver.newContainerBuilder());
    MyResource foo = pool.add(new MyResource());
    MyResource bar = pool.add(new MyResource());
    MyResource baz = pool.add(new MyResource());
    assertEquals(1, pool.retainCount());
    assertEquals(1, foo.retainCount());
    assertEquals(1, bar.retainCount());
    assertEquals(1, baz.retainCount());
    final ResourceReference secondPoolReference = pool.refer();
    assertEquals(2, pool.retainCount());
    assertEquals(1, foo.retainCount());
    assertEquals(1, bar.retainCount());
    assertEquals(1, baz.retainCount());
    secondPoolReference.close();
    assertEquals(1, pool.retainCount());
    assertEquals(1, foo.retainCount());
    assertEquals(1, bar.retainCount());
    assertEquals(1, baz.retainCount());
    pool.release();
    assertEquals(0, pool.retainCount());
    assertEquals(0, foo.retainCount());
    assertEquals(0, bar.retainCount());
    assertEquals(0, baz.retainCount());
    assertTrue(driver.close());
}
Also used : ResourceReference(com.yahoo.jdisc.ResourceReference) 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