Search in sources :

Example 6 with Request

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

the class CurrentContainerTestCase method requireThatNewRequestsCreateSnapshot.

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

Example 7 with Request

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

the class ServerProviderConformanceTest method testRequestExceptionAfterResponseWriteWithAsyncHandleResponse.

private <T extends ServerProvider, U, V> void testRequestExceptionAfterResponseWriteWithAsyncHandleResponse(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 {
                    final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
                    writeResponse(out);
                    closeResponse(out);
                    return null;
                }
            });
            responseWritten.await();
            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)

Example 8 with Request

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

the class LatencyTestCase method measureLatency.

private static TimeFrame measureLatency(CurrentContainer container, MyRequestHandler requestHandler) {
    TimeFrame frame = new TimeFrame();
    Request request = null;
    ContentChannel requestContent = null;
    MyResponseHandler responseHandler = new MyResponseHandler();
    try {
        URI uri = URI.create(requestHandler.uri);
        request = new Request(container, uri);
        frame.handleRequestBegin = System.nanoTime();
        requestContent = request.connect(responseHandler);
        frame.handleRequestEnd = requestHandler.handleTime;
    } finally {
        if (request != null) {
            request.release();
        }
    }
    ByteBuffer buf = ByteBuffer.allocate(69);
    MyCompletion requestWrite = new MyCompletion();
    frame.requestWriteBegin = System.nanoTime();
    requestContent.write(buf, requestWrite);
    frame.requestWriteEnd = requestHandler.requestContent.writeTime;
    frame.requestWriteCompletionBegin = System.nanoTime();
    requestHandler.requestContent.writeCompletion.completed();
    frame.requestWriteCompletionEnd = requestWrite.completedTime;
    MyCompletion requestClose = new MyCompletion();
    frame.requestCloseBegin = System.nanoTime();
    requestContent.close(requestClose);
    frame.requestCloseEnd = requestHandler.requestContent.closeTime;
    frame.requestCloseCompletionBegin = System.nanoTime();
    requestHandler.requestContent.closeCompletion.completed();
    frame.requestCloseCompletionEnd = requestClose.completedTime;
    Response response = new Response(Response.Status.OK);
    frame.handleResponseBegin = System.nanoTime();
    ContentChannel responseContent = requestHandler.responseHandler.handleResponse(response);
    frame.handleResponseEnd = responseHandler.handleTime;
    MyCompletion responseWrite = new MyCompletion();
    frame.responseWriteBegin = System.nanoTime();
    responseContent.write(buf, responseWrite);
    frame.responseWriteEnd = responseHandler.responseContent.writeTime;
    frame.responseWriteCompletionBegin = System.nanoTime();
    responseHandler.responseContent.writeCompletion.completed();
    frame.responseWriteCompletionEnd = responseWrite.completedTime;
    MyCompletion responseClose = new MyCompletion();
    frame.responseCloseBegin = System.nanoTime();
    responseContent.close(responseClose);
    frame.responseCloseEnd = responseHandler.responseContent.closeTime;
    frame.responseCloseCompletionBegin = System.nanoTime();
    responseHandler.responseContent.closeCompletion.completed();
    frame.responseCloseCompletionEnd = responseClose.completedTime;
    return frame;
}
Also used : Response(com.yahoo.jdisc.Response) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) URI(java.net.URI) ByteBuffer(java.nio.ByteBuffer)

Example 9 with Request

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

the class ApplicationRestartTestCase method assertGracefulStop.

private static void assertGracefulStop(ApplicationLoader loader) throws Exception {
    MyRequestHandler requestHandler = new MyRequestHandler();
    ContainerBuilder builder = loader.newContainerBuilder();
    builder.serverBindings().bind("http://host/path", requestHandler);
    loader.activateContainer(builder);
    MyResponseHandler responseHandler = new MyResponseHandler();
    Request request = new Request(loader, URI.create("http://host/path"));
    request.connect(responseHandler).close(null);
    request.release();
    StopTask task = new StopTask(loader);
    task.start();
    assertFalse(task.latch.await(100, TimeUnit.MILLISECONDS));
    requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(task.latch.await(600, TimeUnit.SECONDS));
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request)

Example 10 with Request

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

the class ContainerSnapshotTestCase method requireThatServerHandlerCanBeResolved.

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

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