Search in sources :

Example 6 with Reply

use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.

the class SimpleFeederTest method requireThatAsyncFailuresThrowInMainThread.

@Test
public void requireThatAsyncFailuresThrowInMainThread() throws Throwable {
    TestDriver driver = new TestDriver(new FeederParams(), "<vespafeed><document documenttype='simple' documentid='doc:scheme:0'/></vespafeed>", new MessageHandler() {

        @Override
        public void handleMessage(Message msg) {
            Reply reply = new EmptyReply();
            reply.swapState(msg);
            reply.addError(new Error(ErrorCode.APP_FATAL_ERROR + 6, "foo"));
            reply.addError(new Error(ErrorCode.APP_FATAL_ERROR + 9, "bar"));
            reply.popHandler().handleReply(reply);
        }
    });
    try {
        driver.run();
        fail();
    } catch (IOException e) {
        assertMatches("com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage@.+\n" + "\\[UNKNOWN\\(250006\\) @ .+\\]: foo\n" + "\\[UNKNOWN\\(250009\\) @ .+\\]: bar\n", e.getMessage());
    }
    assertTrue(driver.close());
}
Also used : MessageHandler(com.yahoo.messagebus.MessageHandler) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) IOException(java.io.IOException) EmptyReply(com.yahoo.messagebus.EmptyReply) Test(org.junit.Test)

Example 7 with Reply

use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.

the class MbusRequestHandlerTestCase method requireThatHandlerCanRespondInSameThread.

@Test
public void requireThatHandlerCanRespondInSameThread() throws Exception {
    TestDriver driver = newTestDriver(SameThreadReplier.INSTANCE);
    Response response = dispatchMessage(driver, new SimpleMessage("msg")).get(60, TimeUnit.SECONDS);
    assertTrue(response instanceof MbusResponse);
    assertEquals(Response.Status.OK, response.getStatus());
    Reply reply = ((MbusResponse) response).getReply();
    assertTrue(reply instanceof EmptyReply);
    assertFalse(reply.hasErrors());
    assertTrue(driver.close());
}
Also used : Response(com.yahoo.jdisc.Response) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) TestDriver(com.yahoo.jdisc.test.TestDriver) EmptyReply(com.yahoo.messagebus.EmptyReply) Test(org.junit.Test)

Example 8 with Reply

use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.

the class BucketStatsRetriever method sendMessage.

private <T extends Reply> T sendMessage(DocumentMessage msg, Class<T> expectedReply) throws BucketStatsException {
    setRoute(msg, route);
    Reply reply = session.syncSend(msg);
    return validateReply(reply, expectedReply);
}
Also used : Reply(com.yahoo.messagebus.Reply) GetBucketListReply(com.yahoo.documentapi.messagebus.protocol.GetBucketListReply) StatBucketReply(com.yahoo.documentapi.messagebus.protocol.StatBucketReply)

Example 9 with Reply

use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.

the class DummySessionFactory method sendReply.

public void sendReply(Message m, Error error) {
    MyContext ctxt = (MyContext) m.getContext();
    Reply r = new EmptyReply();
    r.setMessage(m);
    r.setContext(ctxt.oldContext);
    if (error != null) {
        r.addError(error);
    }
    ctxt.handler.handleReply(r);
}
Also used : Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 10 with Reply

use of com.yahoo.messagebus.Reply in project vespa by vespa-engine.

the class DocumentProtocol method merge.

/**
 * This method implements the common way to merge document replies for whatever routing policy. In case of an error
 * in any of the replies, it will prepare an EmptyReply() and add all errors to it. If there are no errors, this
 * method will use the first reply in the list and transfer whatever feed answers might exist in the replies to it.
 *
 * @param ctx  The context whose children to merge.
 * @param mask The indexes of the children to skip.
 */
public static void merge(RoutingContext ctx, Set<Integer> mask) {
    List<Reply> replies = new LinkedList<>();
    for (RoutingNodeIterator it = ctx.getChildIterator(); it.isValid(); it.next()) {
        Reply ref = it.getReplyRef();
        replies.add(ref);
    }
    Tuple2<Integer, Reply> tuple = merge(replies, mask);
    if (tuple.first != null) {
        ctx.getChildIterator().skip(tuple.first).removeReply();
    }
    ctx.setReply(tuple.second);
}
Also used : RoutingNodeIterator(com.yahoo.messagebus.routing.RoutingNodeIterator) Reply(com.yahoo.messagebus.Reply) LinkedList(java.util.LinkedList)

Aggregations

Reply (com.yahoo.messagebus.Reply)39 EmptyReply (com.yahoo.messagebus.EmptyReply)18 Message (com.yahoo.messagebus.Message)14 Error (com.yahoo.messagebus.Error)9 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)7 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)7 Test (org.junit.Test)7 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)6 BatchDocumentUpdateMessage (com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage)5 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)5 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 Response (com.yahoo.jdisc.Response)3 RoutingNode (com.yahoo.messagebus.routing.RoutingNode)3 RoutingNodeIterator (com.yahoo.messagebus.routing.RoutingNodeIterator)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 Version (com.yahoo.component.Version)2 Document (com.yahoo.document.Document)2 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)2 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)2