Search in sources :

Example 11 with Request

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

the class ContainerSnapshotTestCase method requireThatClientBindingsAreUsed.

@Test
public void requireThatClientBindingsAreUsed() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.clientBindings().bind("http://host/path", MyRequestHandler.newInstance());
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://host/path"));
    assertNull(request.container().resolveHandler(request));
    request.setServerRequest(false);
    assertNotNull(request.container().resolveHandler(request));
    request.release();
    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)

Example 12 with Request

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

the class ContainerSnapshotTestCase method requireThatBindingMatchIsSetByResolveHandler.

@Test
public void requireThatBindingMatchIsSetByResolveHandler() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://*/*", MyRequestHandler.newInstance());
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://localhost:69/status.html"));
    assertNotNull(request.container().resolveHandler(request));
    BindingMatch<RequestHandler> match = request.getBindingMatch();
    assertNotNull(match);
    assertEquals(3, match.groupCount());
    assertEquals("localhost", match.group(0));
    assertEquals("69", match.group(1));
    assertEquals("status.html", match.group(2));
    request.release();
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 13 with Request

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

the class ContainerSnapshotTestCase method requireThatNewRequestHasSameSnapshot.

@Test
public void requireThatNewRequestHasSameSnapshot() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    driver.activateContainer(driver.newContainerBuilder());
    Request foo = new Request(driver, URI.create("http://host/foo"));
    Request bar = new Request(foo, URI.create("http://host/bar"));
    assertSame(foo.container(), bar.container());
    foo.release();
    bar.release();
    assertTrue(driver.close());
}
Also used : Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 14 with Request

use of com.yahoo.jdisc.Request 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)

Example 15 with Request

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

the class NonWorkingRequest method newInstance.

/**
 * <p>Factory method to create a {@link Request} without an associated {@link Container}. The design of jDISC does
 * not allow this, so this method internally creates TestDriver, activates a Container, and creates a new Request
 * from that Container. Before returning, this method {@link Request#release() closes} the Request, and calls {@link
 * TestDriver#close()} on the TestDriver. This means that you MUST NOT attempt to access any Container features
 * through the created Request. This factory is only for directed feature tests that require a non-null
 * Request.</p>
 *
 * @param uri          The URI string to assign to the Request.
 * @param guiceModules The guice modules to inject into the {@link Application}.
 * @return A non-working Request.
 */
public static Request newInstance(String uri, Module... guiceModules) {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(guiceModules);
    driver.activateContainer(driver.newContainerBuilder());
    Request request = new Request(driver, URI.create(uri));
    request.release();
    driver.close();
    return request;
}
Also used : Request(com.yahoo.jdisc.Request)

Aggregations

Request (com.yahoo.jdisc.Request)44 Test (org.junit.Test)31 TestDriver (com.yahoo.jdisc.test.TestDriver)22 Response (com.yahoo.jdisc.Response)17 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)16 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)10 ByteBuffer (java.nio.ByteBuffer)7 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)4 RequestDispatch (com.yahoo.jdisc.handler.RequestDispatch)3 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)3 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 Callable (java.util.concurrent.Callable)3 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)2 HttpRequest (com.yahoo.jdisc.http.HttpRequest)2 URI (java.net.URI)2 Executor (java.util.concurrent.Executor)2 Test (org.testng.annotations.Test)2 AbstractModule (com.google.inject.AbstractModule)1 ResourceReference (com.yahoo.jdisc.ResourceReference)1