use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.
the class DocumentRetriever method printReply.
private void printReply(Reply reply) {
Trace trace = reply.getTrace();
if (!trace.getRoot().isEmpty()) {
System.out.println(trace);
}
if (reply.hasErrors()) {
System.err.print("Request failed: ");
for (int i = 0; i < reply.getNumErrors(); i++) {
System.err.printf("\n %s", reply.getError(i));
}
System.err.println();
return;
}
if (!(reply instanceof GetDocumentReply)) {
System.err.printf("Unexpected reply %s: '%s'\n", reply.getType(), reply.toString());
return;
}
GetDocumentReply documentReply = (GetDocumentReply) reply;
Document document = documentReply.getDocument();
if (document == null) {
System.out.println("Document not found.");
return;
}
if (params.showDocSize) {
System.out.printf("Document size: %d bytes.\n", document.getSerializedSize());
}
if (params.printIdsOnly) {
System.out.println(document.getId());
} else {
if (params.jsonOutput) {
System.out.print(Utf8.toString(JsonWriter.toByteArray(document)));
} else {
System.out.print(document.toXML(" "));
}
}
}
use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.
the class DocumentRetrieverTest method testShowDocSize.
@Test
public void testShowDocSize() throws DocumentRetrieverException {
ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setShowDocSize(true).build();
Document document = new Document(DataType.DOCUMENT, new DocumentId(DOC_ID_1));
when(mockedSession.syncSend(any())).thenReturn(new GetDocumentReply(document));
DocumentRetriever documentRetriever = createDocumentRetriever(params);
documentRetriever.retrieveDocuments();
assertTrue(outContent.toString().contains(String.format("Document size: %d bytes", document.getSerializedSize())));
}
use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.
the class DocumentRetrieverTest method testTrace.
@Test
public void testTrace() throws DocumentRetrieverException {
final int traceLevel = 9;
ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setTraceLevel(traceLevel).build();
GetDocumentReply reply = new GetDocumentReply(new Document(DataType.DOCUMENT, new DocumentId(DOC_ID_1)));
reply.getTrace().getRoot().addChild("childnode");
when(mockedSession.syncSend(any())).thenReturn(reply);
DocumentRetriever documentRetriever = createDocumentRetriever(params);
documentRetriever.retrieveDocuments();
verify(mockedSession, times(1)).setTraceLevel(traceLevel);
assertTrue(outContent.toString().contains("<trace>"));
}
use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply 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;
}
Aggregations