Search in sources :

Example 26 with Request

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

the class RequestHandlerTestDriver method sendRequest.

public MockResponseHandler sendRequest(String uri, HttpRequest.Method method, ByteBuffer body) {
    responseHandler = new MockResponseHandler();
    Request request = HttpRequest.newServerRequest(driver, URI.create(uri), method);
    // TODO: Add a method for accepting a Request instead
    request.context().put("contextVariable", 37);
    ContentChannel requestContent = request.connect(responseHandler);
    requestContent.write(body, null);
    requestContent.close(null);
    request.release();
    return responseHandler;
}
Also used : ContentChannel(com.yahoo.jdisc.handler.ContentChannel) ReadableContentChannel(com.yahoo.jdisc.handler.ReadableContentChannel) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request)

Example 27 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 {
    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 28 with Request

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

Example 29 with Request

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

the class ConnectToHandlerTestCase method requireThatConnectToHandlerWorks.

@Test
public void requireThatConnectToHandlerWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = new MyRequestHandler(new MyContent());
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://host/*", requestHandler);
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://host/path"));
    MyResponseHandler responseHandler = new MyResponseHandler();
    ContentChannel content = request.connect(responseHandler);
    request.release();
    assertNotNull(content);
    content.close(null);
    assertNotNull(requestHandler.handler);
    assertSame(request, requestHandler.request);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    driver.close();
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 30 with Request

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

the class ServerProviderConformanceTest method testRequestNondeterministicExceptionWithAsyncHandleResponse.

private <T extends ServerProvider, U, V> void testRequestNondeterministicExceptionWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
    runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {

        @Override
        public ContentChannel handle(final Request request, final ResponseHandler handler) {
            callInOtherThread(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    try {
                        final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
                        closeResponse(out);
                    } catch (Throwable ignored) {
                    }
                    return null;
                }
            });
            throw new ConformanceException();
        }
    });
}
Also used : Response(com.yahoo.jdisc.Response) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) Callable(java.util.concurrent.Callable)

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