Search in sources :

Example 1 with PutDocumentMessage

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

the class MockDispatchDocproc method process.

@Override
public Progress process(Processing processing) {
    for (DocumentOperation op : processing.getDocumentOperations()) {
        PutDocumentMessage message = new PutDocumentMessage((DocumentPut) op);
        ListenableFuture<Response> future = createRequest(message).dispatch();
        try {
            responses.add(future.get());
        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    return Progress.DONE;
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) Response(com.yahoo.jdisc.Response) DocumentOperation(com.yahoo.document.DocumentOperation) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with PutDocumentMessage

use of com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage 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 3 with PutDocumentMessage

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

the class DummyVisitorSession method addDocumentReply.

public void addDocumentReply(String docId) {
    Document replyDoc = new Document(documentType, docId);
    autoReplyMessages.add(new PutDocumentMessage(new DocumentPut(replyDoc)));
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Example 4 with PutDocumentMessage

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

the class DumpVisitorDataHandler method onMessage.

@Override
public void onMessage(Message m, AckToken token) {
    if (m instanceof PutDocumentMessage) {
        PutDocumentMessage pm = (PutDocumentMessage) m;
        onDocument(pm.getDocumentPut().getDocument(), pm.getTimestamp());
    } else if (m instanceof RemoveDocumentMessage) {
        RemoveDocumentMessage rm = (RemoveDocumentMessage) m;
        onRemove(rm.getDocumentId());
    } else {
        throw new UnsupportedOperationException("Received unsupported message " + m.toString() + " to dump visitor data handler. This handler only accepts Put and Remove");
    }
    ack(token);
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)

Example 5 with PutDocumentMessage

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

the class SingleSender method put.

@Override
public void put(Document doc, TestAndSetCondition condition) {
    PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(doc));
    message.setCondition(condition);
    send(message);
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) DocumentPut(com.yahoo.document.DocumentPut)

Aggregations

PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)16 DocumentPut (com.yahoo.document.DocumentPut)5 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)5 Message (com.yahoo.messagebus.Message)5 Test (org.junit.Test)5 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 Reply (com.yahoo.messagebus.Reply)3 Document (com.yahoo.document.Document)2 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)2 Splitter (com.google.common.base.Splitter)1 Tuple2 (com.yahoo.collections.Tuple2)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 SessionCache (com.yahoo.container.jdisc.messagebus.SessionCache)1 AccessLog (com.yahoo.container.logging.AccessLog)1 DataType (com.yahoo.document.DataType)1 DocumentOperation (com.yahoo.document.DocumentOperation)1 DocumentType (com.yahoo.document.DocumentType)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1