Search in sources :

Example 26 with Response

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

the class ResponseMerger method handleResponse.

@Override
public ContentChannel handleResponse(Response response) {
    synchronized (this) {
        if (response instanceof MbusResponse) {
            Reply reply = ((MbusResponse) response).getReply();
            requestTrace.addChild(reply.getTrace().getRoot());
            replies.add(reply);
        }
        if (--numPending != 0) {
            return null;
        }
    }
    requestMsg.getTrace().getRoot().addChild(requestTrace);
    Reply reply = DocumentProtocol.merge(replies);
    Response mbusResponse = new MbusResponse(StatusCodes.fromMbusReply(reply), reply);
    ResponseDispatch.newInstance(mbusResponse).dispatch(responseHandler);
    return null;
}
Also used : Response(com.yahoo.jdisc.Response) MbusResponse(com.yahoo.messagebus.jdisc.MbusResponse) Reply(com.yahoo.messagebus.Reply) MbusResponse(com.yahoo.messagebus.jdisc.MbusResponse)

Example 27 with Response

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

the class AbstractRequestHandlerTestCase method requireThatHandleTimeoutIsImplemented.

@Test
public void requireThatHandleTimeoutIsImplemented() throws Exception {
    FutureResponse handler = new FutureResponse();
    new AbstractRequestHandler() {

        @Override
        public ContentChannel handleRequest(Request request, ResponseHandler handler) {
            return null;
        }
    }.handleTimeout(NonWorkingRequest.newInstance("http://localhost/"), handler);
    Response response = handler.get(600, TimeUnit.SECONDS);
    assertNotNull(response);
    assertEquals(Response.Status.GATEWAY_TIMEOUT, response.getStatus());
}
Also used : Response(com.yahoo.jdisc.Response) NonWorkingRequest(com.yahoo.jdisc.test.NonWorkingRequest) Request(com.yahoo.jdisc.Request) Test(org.junit.Test)

Example 28 with Response

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

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

the class ResponseDispatchTestCase method requireThatStreamCanBeConnected.

@Test
public void requireThatStreamCanBeConnected() throws IOException {
    ReadableContentChannel responseContent = new ReadableContentChannel();
    OutputStream out = new FastContentOutputStream(new ResponseDispatch() {

        @Override
        protected Response newResponse() {
            return new Response(Response.Status.OK);
        }
    }.connect(new MyResponseHandler(responseContent)));
    out.write(6);
    out.write(9);
    out.close();
    InputStream in = responseContent.toStream();
    assertEquals(6, in.read());
    assertEquals(9, in.read());
    assertEquals(-1, in.read());
}
Also used : Response(com.yahoo.jdisc.Response) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 30 with Response

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

the class ResponseDispatchTestCase method requireThatResponseCanBeDispatched.

@Test
public void requireThatResponseCanBeDispatched() throws Exception {
    final Response response = new Response(Response.Status.OK);
    final List<ByteBuffer> writtenContent = Arrays.asList(ByteBuffer.allocate(6), ByteBuffer.allocate(9));
    ResponseDispatch dispatch = new ResponseDispatch() {

        @Override
        protected Response newResponse() {
            return response;
        }

        @Override
        protected Iterable<ByteBuffer> responseContent() {
            return writtenContent;
        }
    };
    ReadableContentChannel receivedContent = new ReadableContentChannel();
    MyResponseHandler responseHandler = new MyResponseHandler(receivedContent);
    dispatch.dispatch(responseHandler);
    assertFalse(dispatch.isDone());
    assertSame(response, responseHandler.response);
    assertSame(writtenContent.get(0), receivedContent.read());
    assertFalse(dispatch.isDone());
    assertSame(writtenContent.get(1), receivedContent.read());
    assertFalse(dispatch.isDone());
    assertNull(receivedContent.read());
    assertTrue(dispatch.isDone());
    assertTrue(dispatch.get(600, TimeUnit.SECONDS));
    assertTrue(dispatch.get());
}
Also used : Response(com.yahoo.jdisc.Response) ByteBuffer(java.nio.ByteBuffer) 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