Search in sources :

Example 41 with TestDriver

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

the class ApplicationLoaderTestCase method requireThatApplicationDestroyIsCalledAfterContainerTermination.

@Test
public void requireThatApplicationDestroyIsCalledAfterContainerTermination() throws InterruptedException {
    MyApplication app = MyApplication.newInstance();
    TestDriver driver = TestDriver.newInjectedApplicationInstance(app);
    ContainerBuilder builder = driver.newContainerBuilder();
    MyRequestHandler requestHandler = new MyRequestHandler();
    builder.serverBindings().bind("scheme://host/path", requestHandler);
    driver.activateContainer(builder);
    driver.dispatchRequest("scheme://host/path", new MyResponseHandler());
    driver.scheduleClose();
    assertFalse(app.destroy.await(100, TimeUnit.MILLISECONDS));
    requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(app.destroy.await(600, TimeUnit.SECONDS));
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 42 with TestDriver

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

the class ApplicationLoaderTestCase method requireThatContainerActivatorReturnsPrev.

@Test
public void requireThatContainerActivatorReturnsPrev() throws Exception {
    TestDriver driver = TestDriver.newInjectedApplicationInstance(MyApplication.newInstance());
    assertNull(driver.activateContainer(driver.newContainerBuilder()));
    assertNotNull(driver.activateContainer(null));
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 43 with TestDriver

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

the class RequestDispatchTestCase method requireThatCancelIsUnsupported.

@Test
public void requireThatCancelIsUnsupported() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    RequestDispatch dispatch = driver.newRequestDispatch("http://localhost/", new FutureResponse());
    assertFalse(dispatch.isCancelled());
    try {
        dispatch.cancel(true);
        fail();
    } catch (UnsupportedOperationException e) {
    }
    assertFalse(dispatch.isCancelled());
    try {
        dispatch.cancel(false);
        fail();
    } catch (UnsupportedOperationException e) {
    }
    assertFalse(dispatch.isCancelled());
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 44 with TestDriver

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

the class RequestDispatchTestCase method requireThatStreamCanBeConnected.

@Test
public void requireThatStreamCanBeConnected() throws IOException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ReadableContentChannel content = new ReadableContentChannel();
    MyRequestHandler requestHandler = new MyRequestHandler(content, new Response(Response.Status.OK));
    builder.serverBindings().bind("http://localhost/", requestHandler);
    driver.activateContainer(builder);
    OutputStream out = new FastContentOutputStream(driver.newRequestDispatch("http://localhost/", new FutureResponse()).connect());
    out.write(6);
    out.write(9);
    out.close();
    InputStream in = content.toStream();
    assertEquals(6, in.read());
    assertEquals(9, in.read());
    assertEquals(-1, in.read());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 45 with TestDriver

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

the class RequestDispatchTestCase method requireThatDispatchHandlesConnectException.

@Test
public void requireThatDispatchHandlesConnectException() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://localhost/", new AbstractRequestHandler() {

        @Override
        public ContentChannel handleRequest(Request request, ResponseHandler handler) {
            throw new RuntimeException();
        }
    });
    driver.activateContainer(builder);
    try {
        driver.newRequestDispatch("http://localhost/", new FutureResponse()).dispatch();
        fail();
    } catch (RuntimeException e) {
    }
    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