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());
}
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();
}
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;
}
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());
}
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;
}
Aggregations