Search in sources :

Example 21 with Request

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

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

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

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

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

the class HttpRequest method createRequest.

/**
 * Create a new HTTP request from an URI.
 *
 * @param container the current container instance
 * @param uri the request parameters
 * @param method GET, POST, etc
 * @param requestData the associated data stream, may be null
 * @param properties a set of properties to set in the request in addition to the implicit ones from the URI
 * @return a new HTTP request
 */
public static HttpRequest createRequest(CurrentContainer container, URI uri, Method method, InputStream requestData, Map<String, String> properties) {
    com.yahoo.jdisc.http.HttpRequest clientRequest = com.yahoo.jdisc.http.HttpRequest.newClientRequest(new Request(container, uri), uri, method);
    setProperties(clientRequest, properties);
    return new HttpRequest(clientRequest, requestData);
}
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