Search in sources :

Example 11 with Response

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

the class TimeoutManagerImplTestCase method requireThatResponseHandlerIsWellBehavedAfterTimeout.

@Test
public void requireThatResponseHandlerIsWellBehavedAfterTimeout() throws InterruptedException {
    Context ctx = new Context(MyRequestHandler.newInstance());
    assertEquals(Response.Status.GATEWAY_TIMEOUT, ctx.awaitResponse(69L, MyResponseHandler.newInstance()));
    ContentChannel content = ctx.requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK));
    assertNotNull(content);
    content.write(ByteBuffer.allocate(69), null);
    MyCompletion completion = new MyCompletion();
    content.write(ByteBuffer.allocate(69), completion);
    assertTrue(completion.completed.await(600, TimeUnit.SECONDS));
    completion = new MyCompletion();
    content.close(completion);
    assertTrue(completion.completed.await(600, TimeUnit.SECONDS));
    assertTrue(ctx.close());
}
Also used : Response(com.yahoo.jdisc.Response) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Test(org.junit.Test)

Example 12 with Response

use of com.yahoo.jdisc.Response 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 13 with Response

use of com.yahoo.jdisc.Response 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 14 with Response

use of com.yahoo.jdisc.Response 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 15 with Response

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

the class ApplicationLoaderTestCase method requireThatApplicationDestroyIsCalledAfterContainerTermination.

@Test
public void requireThatApplicationDestroyIsCalledAfterContainerTermination() throws InterruptedException {
    MyApplication app = MyApplication.newInstance();
    TestDriver driver = TestDriver.newInjectedApplicationInstance(app);
    ContainerBuilder builder = driver.newContainerBuilder();
    MyRequestHandler requestHandler = new MyRequestHandler();
    builder.serverBindings().bind("scheme://host/path", requestHandler);
    driver.activateContainer(builder);
    driver.dispatchRequest("scheme://host/path", new MyResponseHandler());
    driver.scheduleClose();
    assertFalse(app.destroy.await(100, TimeUnit.MILLISECONDS));
    requestHandler.responseHandler.handleResponse(new Response(Response.Status.OK)).close(null);
    assertTrue(app.destroy.await(600, TimeUnit.SECONDS));
}
Also used : Response(com.yahoo.jdisc.Response) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

Response (com.yahoo.jdisc.Response)52 Test (org.junit.Test)39 Request (com.yahoo.jdisc.Request)17 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)14 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)11 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)11 TestDriver (com.yahoo.jdisc.test.TestDriver)10 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)7 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)6 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 ByteBuffer (java.nio.ByteBuffer)6 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)5 Chain (com.yahoo.component.chain.Chain)3 HttpRequest (com.yahoo.jdisc.http.HttpRequest)3 HttpResponse (com.yahoo.jdisc.http.HttpResponse)3 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)3 Reply (com.yahoo.messagebus.Reply)3 Processor (com.yahoo.processing.Processor)3 Callable (java.util.concurrent.Callable)3 Test (org.testng.annotations.Test)3