Search in sources :

Example 26 with Reply

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

the class DocumentProcessingHandlerBasicTestCase method testPut.

@Test
public void testPut() throws InterruptedException {
    Document document = new Document(getType(), "doc:yalla:balla");
    document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
    PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(document));
    assertTrue(sendMessage("foobar", message));
    Message msg = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(msg);
    remoteServer.ackMessage(msg);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertThat((msg instanceof PutDocumentMessage), is(true));
    PutDocumentMessage put = (PutDocumentMessage) msg;
    Document outDoc = put.getDocumentPut().getDocument();
    assertThat(document, equalTo(outDoc));
    assertFalse(reply.hasErrors());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) Message(com.yahoo.messagebus.Message) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) Reply(com.yahoo.messagebus.Reply) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 27 with Reply

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

the class MessageBusSyncSession method update.

@Override
public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) {
    UpdateDocumentMessage msg = new UpdateDocumentMessage(update);
    msg.setPriority(pri);
    Reply reply = syncSend(msg);
    if (reply.hasErrors()) {
        throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply), reply.getErrorCodes());
    }
    if (reply.getType() != DocumentProtocol.REPLY_UPDATEDOCUMENT) {
        throw new DocumentAccessException("Received unknown response: " + reply);
    }
    return ((UpdateDocumentReply) reply).wasFound();
}
Also used : UpdateDocumentReply(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply) Reply(com.yahoo.messagebus.Reply) RemoveDocumentReply(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply) UpdateDocumentReply(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 28 with Reply

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

the class MessageBusSyncSession method get.

@Override
public Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority pri, Duration timeout) {
    GetDocumentMessage msg = new GetDocumentMessage(id, fieldSet);
    msg.setPriority(pri);
    Reply reply = syncSend(msg, timeout != null ? timeout : defaultTimeout);
    if (reply.hasErrors()) {
        throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply));
    }
    if (reply.getType() != DocumentProtocol.REPLY_GETDOCUMENT) {
        throw new DocumentAccessException("Received unknown response: " + reply);
    }
    GetDocumentReply docReply = ((GetDocumentReply) reply);
    Document doc = docReply.getDocument();
    if (doc != null) {
        doc.setLastModified(docReply.getLastModified());
    }
    return doc;
}
Also used : GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Reply(com.yahoo.messagebus.Reply) RemoveDocumentReply(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply) UpdateDocumentReply(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Document(com.yahoo.document.Document) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 29 with Reply

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

the class StoragePolicyTestEnvironment method sendToCorrectNode.

protected void sendToCorrectNode(String cluster, int correctNode) {
    RoutingNode target = select();
    target.handleReply(new EmptyReply());
    Reply reply = frame.getReceptor().getReply(60);
    assertNotNull(reply);
    assertFalse(reply.hasErrors());
    assertEquals(reply.getTrace().toString(), "storage/cluster." + cluster + "/distributor/" + correctNode, target.getRoute().getHop(0).toString());
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 30 with Reply

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

the class MbusClient method sendMessage.

private boolean sendMessage(final MbusRequest request) {
    Error error;
    final Long millis = request.timeRemaining(TimeUnit.MILLISECONDS);
    if (millis != null && millis <= 0) {
        error = new Error(ErrorCode.TIMEOUT, request.getTimeout(TimeUnit.MILLISECONDS) + " millis");
    } else if (request.isCancelled()) {
        error = new Error(ErrorCode.APP_FATAL_ERROR, "request cancelled");
    } else {
        try {
            error = session.sendMessage(request.getMessage()).getError();
        } catch (final Exception e) {
            error = new Error(ErrorCode.FATAL_ERROR, e.toString());
        }
    }
    if (error == null) {
        return true;
    }
    if (error.isFatal()) {
        final Reply reply = new EmptyReply();
        reply.swapState(request.getMessage());
        reply.addError(error);
        reply.popHandler().handleReply(reply);
        return true;
    }
    return false;
}
Also used : Error(com.yahoo.messagebus.Error) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) EmptyReply(com.yahoo.messagebus.EmptyReply)

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