Search in sources :

Example 71 with TestDriver

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

the class ThreadedRequestHandlerTestCase method requireThatRequestAndResponseReachHandlers.

@Test
public void requireThatRequestAndResponseReachHandlers() throws InterruptedException {
    Executor executor = Executors.newSingleThreadExecutor();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    MyRequestHandler requestHandler = MyRequestHandler.newInstance(executor);
    builder.serverBindings().bind("http://localhost/", requestHandler);
    driver.activateContainer(builder);
    MyResponseHandler responseHandler = new MyResponseHandler();
    Request request = new Request(driver, URI.create("http://localhost/"));
    ContentChannel requestContent = request.connect(responseHandler);
    ByteBuffer buf = ByteBuffer.allocate(69);
    requestContent.write(buf, null);
    requestContent.close(null);
    request.release();
    requestHandler.entryLatch.countDown();
    assertTrue(requestHandler.exitLatch.await(60, TimeUnit.SECONDS));
    assertSame(request, requestHandler.request);
    assertSame(buf, requestHandler.content.read());
    assertNull(requestHandler.content.read());
    assertTrue(responseHandler.latch.await(60, TimeUnit.SECONDS));
    assertSame(requestHandler.response, responseHandler.response);
    assertNull(responseHandler.content.read());
    assertTrue(driver.close());
}
Also used : Executor(java.util.concurrent.Executor) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 72 with TestDriver

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

the class ThreadedRequestHandlerTestCase method requireThatRequestContentIsClosedIfHandlerIgnoresIt.

@Test
public void requireThatRequestContentIsClosedIfHandlerIgnoresIt() throws InterruptedException {
    Executor executor = Executors.newSingleThreadExecutor();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    MyRequestHandler requestHandler = MyRequestHandler.newIgnoreContent(executor);
    builder.serverBindings().bind("http://localhost/", requestHandler);
    driver.activateContainer(builder);
    MyResponseHandler responseHandler = new MyResponseHandler();
    ContentChannel content = driver.connectRequest("http://localhost/", responseHandler);
    MyCompletion writeCompletion = new MyCompletion();
    content.write(ByteBuffer.allocate(69), writeCompletion);
    MyCompletion closeCompletion = new MyCompletion();
    content.close(closeCompletion);
    requestHandler.entryLatch.countDown();
    assertTrue(requestHandler.exitLatch.await(60, TimeUnit.SECONDS));
    assertTrue(writeCompletion.latch.await(60, TimeUnit.SECONDS));
    assertTrue(writeCompletion.completed);
    assertTrue(closeCompletion.latch.await(60, TimeUnit.SECONDS));
    assertTrue(writeCompletion.completed);
    assertTrue(responseHandler.latch.await(60, TimeUnit.SECONDS));
    assertSame(requestHandler.response, responseHandler.response);
    assertNull(responseHandler.content.read());
    assertTrue(driver.close());
}
Also used : Executor(java.util.concurrent.Executor) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 73 with TestDriver

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

the class Main method startContainer.

public static TestDriver startContainer(final String configId) {
    System.setProperty("config.id", configId);
    @SuppressWarnings("unused") TestDriver driver = TestDriver.newInjectedApplicationInstance(ConfiguredApplication.class, new AbstractModule() {

        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named("configId")).toInstance(configId);
        }
    });
    return driver;
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) AbstractModule(com.google.inject.AbstractModule)

Example 74 with TestDriver

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

the class AbstractServerProviderTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    MyServerProvider server = builder.getInstance(MyServerProvider.class);
    assertNotNull(server.container());
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 75 with TestDriver

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

the class ConnectToHandlerTestCase method requireThatNullResponseHandlerThrowsException.

@Test
public void requireThatNullResponseHandlerThrowsException() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    driver.activateContainer(driver.newContainerBuilder());
    Request request = new Request(driver, URI.create("http://host/path"));
    try {
        request.connect(null);
        fail();
    } catch (NullPointerException e) {
    // expected
    }
    request.release();
    driver.close();
}
Also used : 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