diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2019-03-12 15:44:04 +0100 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2019-03-12 15:44:04 +0100 |
commit | 66ec8a5349ac6e81148ba7556ce4d056e55b7bd6 (patch) | |
tree | 9aafa6b50a54850f4b6a696b2df12a2679388faa /container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java | |
parent | 91dd5bc9eb95701aeb3110fd402257084634aa73 (diff) |
Protobuf object coversion moved to separate class. RPC classes moved to subpackage
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java new file mode 100644 index 00000000000..4792b45281f --- /dev/null +++ b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java @@ -0,0 +1,95 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.search.dispatch.rpc; + +import ai.vespa.searchlib.searchprotocol.protobuf.Search; +import com.google.common.collect.ImmutableMap; +import com.yahoo.compress.CompressionType; +import com.yahoo.fs4.QueryPacket; +import com.yahoo.prelude.fastsearch.FastHit; +import com.yahoo.prelude.fastsearch.VespaBackEndSearcher; +import com.yahoo.search.Query; +import com.yahoo.search.Result; +import com.yahoo.search.dispatch.rpc.Client; +import com.yahoo.search.dispatch.rpc.RpcResourcePool; +import com.yahoo.search.dispatch.rpc.RpcSearchInvoker; +import com.yahoo.search.dispatch.rpc.RpcFillInvoker.GetDocsumsResponseReceiver; +import com.yahoo.search.dispatch.searchcluster.Node; +import com.yahoo.search.searchchain.Execution; +import org.junit.Test; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +/** + * @author ollivir + */ +public class RpcSearchInvokerTest { + @Test + public void testProtobufSerialization() throws IOException { + var compressionTypeHolder = new AtomicReference<CompressionType>(); + var payloadHolder = new AtomicReference<byte[]>(); + var lengthHolder = new AtomicInteger(); + var mockClient = parameterCollectorClient(compressionTypeHolder, payloadHolder, lengthHolder); + var mockPool = new RpcResourcePool(mockClient, ImmutableMap.of(7, () -> {})); + @SuppressWarnings("resource") + var invoker = new RpcSearchInvoker(mockSearcher(), new Node(7, "seven", 77, 1), mockPool); + + Query q = new Query("search/?query=test&hits=10&offset=3"); + invoker.sendSearchRequest(q, null); + + var bytes = mockPool.compressor().decompress(payloadHolder.get(), compressionTypeHolder.get(), lengthHolder.get()); + var request = Search.Request.newBuilder().mergeFrom(bytes).build(); + + assertThat(request.getHits(), equalTo(10)); + assertThat(request.getOffset(), equalTo(3)); + assertThat(request.getQueryTreeBlob().size(), greaterThan(0)); + } + + private Client parameterCollectorClient(AtomicReference<CompressionType> compressionTypeHolder, AtomicReference<byte[]> payloadHolder, + AtomicInteger lengthHolder) { + return new Client() { + @Override + public void search(NodeConnection node, CompressionType compression, int uncompressedLength, byte[] compressedPayload, + RpcSearchInvoker responseReceiver, double timeoutSeconds) { + compressionTypeHolder.set(compression); + payloadHolder.set(compressedPayload); + lengthHolder.set(uncompressedLength); + } + + @Override + public void getDocsums(List<FastHit> hits, NodeConnection node, CompressionType compression, int uncompressedLength, + byte[] compressedSlime, GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) { + fail("Unexpected call"); + } + + @Override + public NodeConnection createConnection(String hostname, int port) { + fail("Unexpected call"); + return null; + } + }; + } + + private VespaBackEndSearcher mockSearcher() { + return new VespaBackEndSearcher() { + @Override + protected Result doSearch2(Query query, QueryPacket queryPacket, Execution execution) { + fail("Unexpected call"); + return null; + } + + @Override + protected void doPartialFill(Result result, String summaryClass) { + fail("Unexpected call"); + } + }; + } +} |