Search in sources :

Example 16 with GetDocumentReply

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("  "));
        }
    }
}
Also used : Trace(com.yahoo.messagebus.Trace) Document(com.yahoo.document.Document) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)

Example 17 with GetDocumentReply

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())));
}
Also used : DocumentId(com.yahoo.document.DocumentId) Document(com.yahoo.document.Document) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 18 with GetDocumentReply

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>"));
}
Also used : DocumentId(com.yahoo.document.DocumentId) Document(com.yahoo.document.Document) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 19 with GetDocumentReply

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

Aggregations

GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)19 Test (org.junit.Test)17 Result (com.yahoo.search.Result)13 Searcher (com.yahoo.search.Searcher)13 Execution (com.yahoo.search.searchchain.Execution)13 Document (com.yahoo.document.Document)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 Chain (com.yahoo.component.chain.Chain)2 DocumentId (com.yahoo.document.DocumentId)2 Raw (com.yahoo.document.datatypes.Raw)2 FeedContext (com.yahoo.feedapi.FeedContext)2 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)2 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)2 Reply (com.yahoo.messagebus.Reply)2 ClusterList (com.yahoo.vespaclient.ClusterList)2 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)1 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)1 RemoveDocumentReply (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply)1 UpdateDocumentReply (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply)1