Search in sources :

Example 51 with TestDriver

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

the class CallableRequestDispatchTestCase method requireThatDispatchIsCalled.

@Test
public void requireThatDispatchIsCalled() throws Exception {
    final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    Response response = new Response(Response.Status.OK);
    builder.serverBindings().bind("http://host/path", new MyRequestHandler(response));
    driver.activateContainer(builder);
    assertSame(response, new CallableRequestDispatch() {

        @Override
        protected Request newRequest() {
            return new Request(driver, URI.create("http://host/path"));
        }
    }.call());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 52 with TestDriver

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

the class RequestDeniedTestCase method requireThatRequestDeniedIsThrown.

@Test
public void requireThatRequestDeniedIsThrown() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    RequestHandler requestHandler = new MyRequestHandler();
    builder.serverBindings().bind("http://host/path", requestHandler);
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://host/path"));
    try {
        request.connect(new MyResponseHandler());
        fail();
    } catch (RequestDeniedException e) {
        assertSame(request, e.request());
    }
    request.release();
    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)

Example 53 with TestDriver

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

the class RequestDeniedTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    driver.activateContainer(driver.newContainerBuilder());
    Request request = new Request(driver, URI.create("http://host/path"));
    RequestDeniedException e = new RequestDeniedException(request);
    assertSame(request, e.request());
    request.release();
    driver.close();
}
Also used : Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 54 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 {
    MyRequestHandler requestHandler = new MyRequestHandler(newExecutor());
    TestDriver driver = newTestDriver("http://localhost/", requestHandler);
    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(600, TimeUnit.SECONDS));
    assertSame(request, requestHandler.request);
    assertSame(buf, requestHandler.content.read());
    assertNull(requestHandler.content.read());
    assertTrue(responseHandler.latch.await(600, TimeUnit.SECONDS));
    assertSame(requestHandler.response, responseHandler.response);
    assertNull(responseHandler.content.read());
    assertTrue(driver.close());
}
Also used : Request(com.yahoo.jdisc.Request) ByteBuffer(java.nio.ByteBuffer) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 55 with TestDriver

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

the class ThreadedRequestHandlerTestCase method requireThatHandlerSetsRequestTimeout.

@Test
public void requireThatHandlerSetsRequestTimeout() throws InterruptedException {
    MyRequestHandler requestHandler = new MyRequestHandler(newExecutor());
    requestHandler.setTimeout(600, TimeUnit.SECONDS);
    TestDriver driver = newTestDriver("http://localhost/", requestHandler);
    MyResponseHandler responseHandler = new MyResponseHandler();
    driver.dispatchRequest("http://localhost/", responseHandler);
    requestHandler.entryLatch.countDown();
    assertTrue(requestHandler.exitLatch.await(600, TimeUnit.SECONDS));
    assertNull(requestHandler.content.read());
    assertNotNull(requestHandler.request.getTimeout(TimeUnit.MILLISECONDS));
    assertTrue(responseHandler.latch.await(600, TimeUnit.SECONDS));
    assertNull(responseHandler.content.read());
    assertTrue(driver.close());
}
Also used : 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