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