use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.
the class GetSearcherTestCase method testQueryPassThroughAndGet.
/* Test that a query will contain both document hits and hits from a searcher
* further down the chain, iff the searcher returns a DocumentHit.
*/
@Test
public void testQueryPassThroughAndGet() throws Exception {
Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:1234:foo"));
doc1.setFieldValue("name", new StringFieldValue("megacat"));
doc1.setFieldValue("description", new StringFieldValue("supercat"));
doc1.setFieldValue("fluffiness", new IntegerFieldValue(10000));
GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
DocumentSessionFactory factory = new DocumentSessionFactory(docType, null, false, replies);
GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
DocumentHit backendHit = new DocumentHit(new Document(docType, new DocumentId("userdoc:kittens:5678:bar")), 5);
Chain<Searcher> searchChain = new Chain<>(searcher, new MockBackend(backendHit));
Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?query=flarn&id=userdoc:kittens:1234:foo"));
assertEquals(1, factory.messages.size());
assertEquals(2, result.hits().size());
assertNotNull(result.hits().get("userdoc:kittens:5678:bar"));
assertNotNull(result.hits().get("userdoc:kittens:1234:foo"));
}
use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.
the class GetSearcherTestCase method testDocumentFieldNotSet.
@Test
public void testDocumentFieldNotSet() throws Exception {
Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:5:1"));
doc1.setFieldValue("name", "asdf");
doc1.setFieldValue("description", "fdsafsdf");
doc1.setFieldValue("fluffiness", 10);
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=image"));
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=\"16\" message=\"Resource not found.: " + "Field 'image' found in document type, but had no content 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 testResultWithMultipleErrors.
@Test
public void testResultWithMultipleErrors() throws Exception {
Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:77:88"));
Document doc2 = new Document(docType, new DocumentId("userdoc:kittens:99:111"));
GetDocumentReply errorReply1 = new GetDocumentReply(doc1);
errorReply1.addError(new com.yahoo.messagebus.Error(123, "userdoc:kittens:77:88 had fleas."));
GetDocumentReply errorReply2 = new GetDocumentReply(doc2);
errorReply2.addError(new com.yahoo.messagebus.Error(456, "userdoc:kittens:99:111 shredded the curtains."));
GetDocumentReply[] replies = new GetDocumentReply[] { errorReply1, errorReply2 };
Chain<Searcher> searchChain = createSearcherChain(replies);
Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:77:88&id[1]=userdoc:kittens:99:111"));
assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"messagebus\" code=\"123\" message=\"userdoc:kittens:77:88 had fleas.\"/>\n" + "<error type=\"messagebus\" code=\"456\" message=\"userdoc:kittens:99:111 shredded the curtains.\"/>\n" + "</errors>\n" + "</result>\n", result);
}
use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.
the class GetSearcherTestCase method testVespaXMLTemplate.
@Test
public void testVespaXMLTemplate() throws Exception {
Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:3:4"));
doc1.setFieldValue("name", "mittens");
doc1.setFieldValue("description", "it's a cat");
doc1.setFieldValue("fluffiness", 8);
Document doc2 = new Document(docType, new DocumentId("userdoc:kittens:1:2"));
doc2.setFieldValue("name", "garfield");
doc2.setFieldValue("description", "preliminary research indicates <em>hatred</em> of mondays. caution advised");
doc2.setFieldValue("fluffiness", 2);
Document doc3 = new Document(docType, new DocumentId("userdoc:kittens:77:88"));
GetDocumentReply errorReply = new GetDocumentReply(doc3);
errorReply.addError(new com.yahoo.messagebus.Error(123, "userdoc:kittens:77:88 lost in a <ni!>\"shrubbery\"</ni!>"));
GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1), new GetDocumentReply(doc2), errorReply };
// Use a predefined reply list to ensure messages are answered out of order
Chain<Searcher> searchChain = createSearcherChain(replies);
Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(// TODO!
newQuery("?id[0]=userdoc:kittens:77:88&id[1]=userdoc:kittens:1:2&id[2]=userdoc:kittens:3:4"));
assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"messagebus\" code=\"123\" message=\"userdoc:kittens:77:88 lost in a <ni!>"shrubbery"</ni!>\"/>\n" + "</errors>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:kittens:1:2\">\n" + " <name>garfield</name>\n" + " <description>preliminary research indicates <em>hatred</em> of mondays. caution advised</description>\n" + " <fluffiness>2</fluffiness>\n" + "</document>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:kittens:3:4\">\n" + " <name>mittens</name>\n" + " <description>it's a cat</description>\n" + " <fluffiness>8</fluffiness>\n" + "</document>\n" + "</result>\n", result);
}
use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.
the class GetSearcherTestCase method testDocumentFieldEscapeXML.
@Test
public void testDocumentFieldEscapeXML() throws Exception {
Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:5:1"));
doc1.setFieldValue("name", "asfd");
doc1.setFieldValue("description", "<script type=\"evil/madness\">horror & screams</script>");
doc1.setFieldValue("fluffiness", 0);
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"));
assertNull(result.hits().getErrorHit());
assertEquals("text/xml", result.getTemplating().getTemplates().getMimeType());
assertEquals("UTF-8", result.getTemplating().getTemplates().getEncoding());
assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result><script type=\"evil/madness\">horror & screams</script></result>\n", result);
}
Aggregations