Search in sources :

Example 6 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class DocumentRetrieverTest method testDocumentNotFound.

@Test
public void testDocumentNotFound() throws DocumentRetrieverException {
    ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setPrintIdsOnly(true).build();
    when(mockedSession.syncSend(any())).thenReturn(new GetDocumentReply(null));
    DocumentRetriever documentRetriever = createDocumentRetriever(params);
    documentRetriever.retrieveDocuments();
    verify(mockedSession, times(1)).syncSend(any());
    assertEquals(outContent.toString(), "Document not found.\n");
}
Also used : GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 7 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class DocumentRetrieverTest method testHandlingErrorFromMessageBus.

@Test
public void testHandlingErrorFromMessageBus() throws DocumentRetrieverException {
    ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).build();
    Reply r = new GetDocumentReply(null);
    r.addError(new Error(0, "Error message"));
    when(mockedSession.syncSend(any())).thenReturn(r);
    DocumentRetriever documentRetriever = createDocumentRetriever(params);
    documentRetriever.retrieveDocuments();
    assertTrue(errContent.toString().contains("Request failed"));
}
Also used : Reply(com.yahoo.messagebus.Reply) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Error(com.yahoo.messagebus.Error) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 8 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class GetSearcherTestCase method testDocumentFieldRawWithContentOverride.

@Test
public void testDocumentFieldRawWithContentOverride() throws Exception {
    byte[] contentBytes = new byte[] { 0, -128, 127 };
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:123:456"));
    doc1.setFieldValue("foo", new Raw(ByteBuffer.wrap(contentBytes)));
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:123:456&field=foo&contenttype=text/fancy"));
    assertNull(result.hits().getErrorHit());
    assertEquals("text/fancy", result.getTemplating().getTemplates().getMimeType());
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    SearchRendererAdaptor.callRender(stream, result);
    stream.flush();
    byte[] resultBytes = stream.toByteArray();
    assertEquals(contentBytes.length, resultBytes.length);
    for (int i = 0; i < resultBytes.length; ++i) {
        assertEquals(contentBytes[i], resultBytes[i]);
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Searcher(com.yahoo.search.Searcher) Raw(com.yahoo.document.datatypes.Raw) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 9 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class GetSearcherTestCase method testDocumentFieldNotReachableWithHeadersOnly.

@Test
public void testDocumentFieldNotReachableWithHeadersOnly() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:5:1"));
    doc1.setFieldValue("name", "asdf");
    // don't set body fields
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:5:1&field=description&headersonly=true"));
    assertNotNull(result.hits().getErrorHit());
    assertEquals(1, result.hits().size());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"4\" message=\"Invalid query parameter: " + "Field 'description' is located in document body, but headersonly " + "prevents it from being retrieved in userdoc:kittens:5:1\"/>\n" + "</errors>\n" + "</result>\n", result);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Searcher(com.yahoo.search.Searcher) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 10 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class GetSearcherTestCase method testConsistentResultOrdering.

@Test
public void testConsistentResultOrdering() throws Exception {
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(new Document(docType, new DocumentId("userdoc:kittens:1:2"))), new GetDocumentReply(new Document(docType, new DocumentId("userdoc:kittens:7:8"))), new GetDocumentReply(new Document(docType, new DocumentId("userdoc:kittens:555:123"))) };
    // Use a predefined reply list to ensure messages are answered out of order
    DocumentSessionFactory factory = new DocumentSessionFactory(docType, null, false, replies);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:555:123&id[1]=userdoc:kittens:1:2&id[2]=userdoc:kittens:7:8"));
    assertEquals(3, factory.messages.size());
    assertEquals(3, result.hits().size());
    // Hits must be in the same order as their document IDs in the query
    assertHits(result.hits(), "userdoc:kittens:555:123", "userdoc:kittens:1:2", "userdoc:kittens:7:8");
    assertEquals(0, ((DocumentHit) result.hits().get(0)).getIndex());
    assertEquals(1, ((DocumentHit) result.hits().get(1)).getIndex());
    assertEquals(2, ((DocumentHit) result.hits().get(2)).getIndex());
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

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