Search in sources :

Example 1 with NullFeedMetric

use of com.yahoo.feedhandler.NullFeedMetric in project vespa by vespa-engine.

the class FeedTesterV3 method setupFeederHandler.

FeedHandlerV3 setupFeederHandler() throws Exception {
    Executor threadPool = Executors.newCachedThreadPool();
    DocumentmanagerConfig docMan = new DocumentmanagerConfig(new DocumentmanagerConfig.Builder().enablecompression(true));
    FeedHandlerV3 feedHandlerV3 = new FeedHandlerV3(new FeedHandlerV3.Context(threadPool, AccessLog.voidAccessLog(), new NullFeedMetric()), docMan, null, /* session cache */
    null, /* thread pool config */
    new DocumentApiMetrics(MetricReceiver.nullImplementation, "test")) {

        @Override
        protected ReferencedResource<SharedSourceSession> retainSource(SessionCache sessionCache, SourceSessionParams sessionParams) {
            SharedSourceSession sharedSourceSession = mock(SharedSourceSession.class);
            try {
                Mockito.stub(sharedSourceSession.sendMessageBlocking(anyObject())).toAnswer((Answer) invocation -> {
                    Object[] args = invocation.getArguments();
                    PutDocumentMessage putDocumentMessage = (PutDocumentMessage) args[0];
                    ReplyContext replyContext = (ReplyContext) putDocumentMessage.getContext();
                    replyContext.feedReplies.add(new OperationStatus("message", replyContext.docId, ErrorCode.OK, false, "trace"));
                    Result result = mock(Result.class);
                    when(result.isAccepted()).thenReturn(true);
                    return result;
                });
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Result result = mock(Result.class);
            when(result.isAccepted()).thenReturn(true);
            ReferencedResource<SharedSourceSession> refSharedSessopn = new ReferencedResource<>(sharedSourceSession, () -> {
            });
            return refSharedSessopn;
        }
    };
    feedHandlerV3.injectDocumentManangerForTests(createDoctypeManager());
    return feedHandlerV3;
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) DataType(com.yahoo.document.DataType) ReplyContext(com.yahoo.vespa.http.server.ReplyContext) DocumentType(com.yahoo.document.DocumentType) OperationStatus(com.yahoo.vespa.http.client.core.OperationStatus) Assert.assertThat(org.junit.Assert.assertThat) Answer(org.mockito.stubbing.Answer) ByteArrayInputStream(java.io.ByteArrayInputStream) SharedSourceSession(com.yahoo.messagebus.shared.SharedSourceSession) ErrorCode(com.yahoo.vespa.http.client.core.ErrorCode) Matchers.anyObject(org.mockito.Matchers.anyObject) SessionCache(com.yahoo.container.jdisc.messagebus.SessionCache) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) MetricReceiver(com.yahoo.metrics.simple.MetricReceiver) Splitter(com.google.common.base.Splitter) FeedHandlerV3(com.yahoo.vespa.http.server.FeedHandlerV3) Executor(java.util.concurrent.Executor) Utf8(com.yahoo.text.Utf8) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) AccessLog(com.yahoo.container.logging.AccessLog) HttpRequest(com.yahoo.container.jdisc.HttpRequest) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ReferencedResource(com.yahoo.jdisc.ReferencedResource) Executors(java.util.concurrent.Executors) Result(com.yahoo.messagebus.Result) DocumentApiMetrics(com.yahoo.documentapi.metrics.DocumentApiMetrics) Mockito(org.mockito.Mockito) Headers(com.yahoo.vespa.http.client.core.Headers) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) HttpResponse(com.yahoo.container.jdisc.HttpResponse) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) ReferencedResource(com.yahoo.jdisc.ReferencedResource) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) SharedSourceSession(com.yahoo.messagebus.shared.SharedSourceSession) Result(com.yahoo.messagebus.Result) FeedHandlerV3(com.yahoo.vespa.http.server.FeedHandlerV3) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) Executor(java.util.concurrent.Executor) DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) DocumentApiMetrics(com.yahoo.documentapi.metrics.DocumentApiMetrics) OperationStatus(com.yahoo.vespa.http.client.core.OperationStatus) ReplyContext(com.yahoo.vespa.http.server.ReplyContext) SessionCache(com.yahoo.container.jdisc.messagebus.SessionCache) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric)

Example 2 with NullFeedMetric

use of com.yahoo.feedhandler.NullFeedMetric in project vespa by vespa-engine.

the class GetSearcherTestCase method testQueryOverridesDefaults.

@Test
public void testQueryOverridesDefaults() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    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:1:2&id[1]=userdoc:kittens:3:4&priority=LOW_2&route=highwaytohell&timeout=58"));
    assertEquals(2, factory.messages.size());
    long lastTimeout = 58000;
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:1:2", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(DocumentProtocol.Priority.LOW_2, gdm.getPriority());
        assertEquals(Route.parse("highwaytohell"), gdm.getRoute());
        assertTrue(lastTimeout >= gdm.getTimeRemaining());
        lastTimeout = gdm.getTimeRemaining();
    }
    {
        Message m = factory.messages.get(1);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:3:4", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(DocumentProtocol.Priority.LOW_2, gdm.getPriority());
        assertEquals(Route.parse("highwaytohell"), gdm.getRoute());
        assertTrue(lastTimeout >= gdm.getTimeRemaining());
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

Example 3 with NullFeedMetric

use of com.yahoo.feedhandler.NullFeedMetric in project vespa by vespa-engine.

the class GetSearcherTestCase method testGetSingleDocumentQuery.

@Test
public void testGetSingleDocumentQuery() throws Exception {
    // Needs auto-reply
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    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=userdoc:kittens:1:2"));
    System.out.println("HTTP request is " + result.getQuery().getHttpRequest());
    assertEquals(1, factory.messages.size());
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:1:2", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
    }
    assertEquals(1, result.hits().size());
    assertHits(result.hits(), "userdoc:kittens:1:2");
    // By default, document hit should not have its hit fields set
    DocumentHit hit = (DocumentHit) result.hits().get(0);
    assertEquals(0, hit.fieldKeys().size());
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

Example 4 with NullFeedMetric

use of com.yahoo.feedhandler.NullFeedMetric in project vespa by vespa-engine.

the class GetSearcherTestCase method testDocumentFieldWithDocumentNotFound.

@Test
public void testDocumentFieldWithDocumentNotFound() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType, null, true);
    factory.setNullReply(true);
    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=userdoc:kittens:1:2&field=name"));
    assertNotNull(result.hits().getErrorHit());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"16\" message=\"Resource not found.: " + "Document not found, could not return field 'name'\"/>\n" + "</errors>\n" + "</result>\n", result);
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) Searcher(com.yahoo.search.Searcher) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 5 with NullFeedMetric

use of com.yahoo.feedhandler.NullFeedMetric in project vespa by vespa-engine.

the class GetSearcherTestCase method testGetMultipleDocumentsQuery.

@Test
public void testGetMultipleDocumentsQuery() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Query query = newQuery("?id[0]=userdoc:kittens:1:2&id[1]=userdoc:kittens:3:4");
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(query);
    assertEquals(2, factory.messages.size());
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:1:2", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
    }
    {
        Message m = factory.messages.get(1);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:3:4", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
    }
    assertEquals(2, result.hits().size());
    assertNull(result.hits().getErrorHit());
    assertHits(result.hits(), "userdoc:kittens:1:2", "userdoc:kittens:3:4");
    assertEquals(2, query.getHits());
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Query(com.yahoo.search.Query) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

Aggregations

NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)25 FeedContext (com.yahoo.feedapi.FeedContext)24 ClusterList (com.yahoo.vespaclient.ClusterList)24 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)23 Test (org.junit.Test)22 Chain (com.yahoo.component.chain.Chain)21 Searcher (com.yahoo.search.Searcher)20 Execution (com.yahoo.search.searchchain.Execution)20 Result (com.yahoo.search.Result)19 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)7 Message (com.yahoo.messagebus.Message)7 Query (com.yahoo.search.Query)4 FeederConfig (com.yahoo.vespaclient.config.FeederConfig)4 ClusterListConfig (com.yahoo.cloud.config.ClusterListConfig)2 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)2 Hit (com.yahoo.search.result.Hit)2 HitGroup (com.yahoo.search.result.HitGroup)2 LoadTypeConfig (com.yahoo.vespa.config.content.LoadTypeConfig)2 Splitter (com.google.common.base.Splitter)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1