diff options
Diffstat (limited to 'container-search/src/test/java')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java | 35 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java (renamed from container-search/src/test/java/com/yahoo/search/dispatch/rpc/FillTestCase.java) | 17 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/MockClient.java (renamed from container-search/src/test/java/com/yahoo/search/dispatch/rpc/MockClient.java) | 25 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java | 95 |
4 files changed, 17 insertions, 155 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java index 0cc58801298..708caafa3f5 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java @@ -2,10 +2,8 @@ package com.yahoo.search.dispatch; import com.yahoo.prelude.fastsearch.FS4InvokerFactory; -import com.yahoo.prelude.fastsearch.VespaBackEndSearcher; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.Query; -import com.yahoo.search.dispatch.rpc.RpcInvokerFactory; import com.yahoo.search.dispatch.searchcluster.Node; import com.yahoo.search.dispatch.searchcluster.SearchCluster; import com.yahoo.vespa.config.search.DispatchConfig; @@ -38,7 +36,7 @@ public class DispatcherTest { builder.useMultilevelDispatch(true); DispatchConfig dc = new DispatchConfig(builder); - Dispatcher disp = new Dispatcher(cl, dc, new MockFS4InvokerFactory(cl), new MockRpcInvokerFactory()); + Dispatcher disp = new Dispatcher(cl, dc); assertThat(disp.getSearchInvoker(query(), null).isPresent(), is(false)); } @@ -47,13 +45,13 @@ public class DispatcherTest { SearchCluster cl = new MockSearchCluster("1", 2, 2); Query q = query(); q.getModel().setSearchPath("1/0"); // second node in first group + Dispatcher disp = new Dispatcher(cl, createDispatchConfig()); MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (nodes, a) -> { assertThat(nodes.size(), is(1)); assertThat(nodes.get(0).key(), is(2)); return true; }); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, new MockRpcInvokerFactory()); - Optional<SearchInvoker> invoker = disp.getSearchInvoker(q, null); + Optional<SearchInvoker> invoker = disp.getSearchInvoker(q, invokerFactory); assertThat(invoker.isPresent(), is(true)); invokerFactory.verifyAllEventsProcessed(); } @@ -66,9 +64,9 @@ public class DispatcherTest { return Optional.of(new Node(1, "test", 123, 1)); } }; + Dispatcher disp = new Dispatcher(cl, createDispatchConfig()); MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (n, a) -> true); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, new MockRpcInvokerFactory()); - Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), null); + Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), invokerFactory); assertThat(invoker.isPresent(), is(true)); invokerFactory.verifyAllEventsProcessed(); } @@ -77,6 +75,7 @@ public class DispatcherTest { public void requireThatInvokerConstructionIsRetriedAndLastAcceptsAnyCoverage() { SearchCluster cl = new MockSearchCluster("1", 2, 1); + Dispatcher disp = new Dispatcher(cl, createDispatchConfig()); MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (n, acceptIncompleteCoverage) -> { assertThat(acceptIncompleteCoverage, is(false)); return false; @@ -84,8 +83,7 @@ public class DispatcherTest { assertThat(acceptIncompleteCoverage, is(true)); return true; }); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, new MockRpcInvokerFactory()); - Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), null); + Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), invokerFactory); assertThat(invoker.isPresent(), is(true)); invokerFactory.verifyAllEventsProcessed(); } @@ -94,9 +92,9 @@ public class DispatcherTest { public void requireThatInvokerConstructionDoesNotRepeatGroups() { SearchCluster cl = new MockSearchCluster("1", 2, 1); + Dispatcher disp = new Dispatcher(cl, createDispatchConfig()); MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (n, a) -> false, (n, a) -> false); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, null); - Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), null); + Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), invokerFactory); assertThat(invoker.isPresent(), is(false)); invokerFactory.verifyAllEventsProcessed(); } @@ -110,13 +108,12 @@ public class DispatcherTest { private int step = 0; public MockFS4InvokerFactory(SearchCluster cl, FactoryStep... events) { - super(null, cl); + super(null, cl, null); this.events = events; } @Override - public Optional<SearchInvoker> createSearchInvoker(VespaBackEndSearcher searcher, Query query, OptionalInt groupId, - List<Node> nodes, boolean acceptIncompleteCoverage) { + public Optional<SearchInvoker> getSearchInvoker(Query query, OptionalInt groupId, List<Node> nodes, boolean acceptIncompleteCoverage) { if (step >= events.length) { throw new RuntimeException("Was not expecting more calls to getSearchInvoker"); } @@ -133,14 +130,4 @@ public class DispatcherTest { assertThat(step, is(events.length)); } } - - public class MockRpcInvokerFactory extends RpcInvokerFactory { - public MockRpcInvokerFactory() { - super(null, null); - } - - @Override - public void release() { - } - } } diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/FillTestCase.java b/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java index 2adbd12a2aa..173b2de494f 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/FillTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java @@ -1,5 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.dispatch.rpc; +package com.yahoo.search.dispatch; import com.yahoo.prelude.fastsearch.DocsumDefinition; import com.yahoo.prelude.fastsearch.DocsumDefinitionSet; @@ -8,9 +8,6 @@ import com.yahoo.prelude.fastsearch.DocumentDatabase; import com.yahoo.prelude.fastsearch.FastHit; import com.yahoo.search.Query; import com.yahoo.search.Result; -import com.yahoo.search.dispatch.rpc.Client; -import com.yahoo.search.dispatch.rpc.RpcInvokerFactory; -import com.yahoo.search.dispatch.rpc.RpcResourcePool; import org.junit.Test; import java.util.ArrayList; @@ -39,7 +36,6 @@ public class FillTestCase { nodes.put(1, client.createConnection("host1", 123)); nodes.put(2, client.createConnection("host2", 123)); RpcResourcePool rpcResourcePool = new RpcResourcePool(client, nodes); - RpcInvokerFactory factory = new RpcInvokerFactory(rpcResourcePool, null); Query query = new Query(); Result result = new Result(query); @@ -55,7 +51,7 @@ public class FillTestCase { client.setDocsumReponse("host2", 3, "summaryClass1", map("field1", "s.2.3", "field2", 3)); client.setDocsumReponse("host0", 4, "summaryClass1", map("field1", "s.0.4", "field2", 4)); - factory.createFillInvoker(db()).fill(result, "summaryClass1"); + rpcResourcePool.getFillInvoker(db()).fill(result, "summaryClass1"); assertEquals("s.0.0", result.hits().get("hit:0").getField("field1").toString()); assertEquals("s.2.1", result.hits().get("hit:1").getField("field1").toString()); @@ -76,7 +72,6 @@ public class FillTestCase { nodes.put(1, client.createConnection("host1", 123)); nodes.put(2, client.createConnection("host2", 123)); RpcResourcePool rpcResourcePool = new RpcResourcePool(client, nodes); - RpcInvokerFactory factory = new RpcInvokerFactory(rpcResourcePool, null); Query query = new Query(); Result result = new Result(query); @@ -92,7 +87,7 @@ public class FillTestCase { client.setDocsumReponse("host2", 3, "summaryClass1", map("field1", "s.2.3", "field2", 3)); client.setDocsumReponse("host0", 4, "summaryClass1",new HashMap<>()); - factory.createFillInvoker(db()).fill(result, "summaryClass1"); + rpcResourcePool.getFillInvoker(db()).fill(result, "summaryClass1"); assertEquals("s.0.0", result.hits().get("hit:0").getField("field1").toString()); assertEquals("s.2.1", result.hits().get("hit:1").getField("field1").toString()); @@ -116,13 +111,12 @@ public class FillTestCase { Map<Integer, Client.NodeConnection> nodes = new HashMap<>(); nodes.put(0, client.createConnection("host0", 123)); RpcResourcePool rpcResourcePool = new RpcResourcePool(client, nodes); - RpcInvokerFactory factory = new RpcInvokerFactory(rpcResourcePool, null); Query query = new Query(); Result result = new Result(query); result.hits().add(createHit(0, 0)); - factory.createFillInvoker(db()).fill(result, "summaryClass1"); + rpcResourcePool.getFillInvoker(db()).fill(result, "summaryClass1"); assertEquals("Malfunctioning", result.hits().getError().getDetailedMessage()); } @@ -134,7 +128,6 @@ public class FillTestCase { Map<Integer, Client.NodeConnection> nodes = new HashMap<>(); nodes.put(0, client.createConnection("host0", 123)); RpcResourcePool rpcResourcePool = new RpcResourcePool(client, nodes); - RpcInvokerFactory factory = new RpcInvokerFactory(rpcResourcePool, null); Query query = new Query(); Result result = new Result(query); @@ -142,7 +135,7 @@ public class FillTestCase { result.hits().add(createHit(1, 1)); - factory.createFillInvoker(db()).fill(result, "summaryClass1"); + rpcResourcePool.getFillInvoker(db()).fill(result, "summaryClass1"); assertEquals("Could not fill hits from unknown node 1", result.hits().getError().getDetailedMessage()); } diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/MockClient.java b/container-search/src/test/java/com/yahoo/search/dispatch/MockClient.java index f9b628e594a..a4cb8ae641c 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/MockClient.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/MockClient.java @@ -1,15 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.dispatch.rpc; +package com.yahoo.search.dispatch; import com.yahoo.compress.CompressionType; import com.yahoo.compress.Compressor; import com.yahoo.document.GlobalId; import com.yahoo.document.idstring.IdIdString; import com.yahoo.prelude.fastsearch.FastHit; -import com.yahoo.search.Result; -import com.yahoo.search.dispatch.rpc.Client; -import com.yahoo.search.dispatch.rpc.RpcFillInvoker; -import com.yahoo.search.dispatch.rpc.RpcSearchInvoker; import com.yahoo.slime.ArrayTraverser; import com.yahoo.slime.BinaryFormat; import com.yahoo.slime.Cursor; @@ -29,7 +25,6 @@ public class MockClient implements Client { private final Map<DocsumKey, Map<String, Object>> docsums = new HashMap<>(); private final Compressor compressor = new Compressor(); private boolean malfunctioning = false; - private Result searchResult; /** Set to true to cause this to produce an error instead of a regular response */ public void setMalfunctioning(boolean malfunctioning) { this.malfunctioning = malfunctioning; } @@ -77,24 +72,6 @@ public class MockClient implements Client { responseReceiver.receive(GetDocsumsResponseOrError.fromResponse(response)); } - @Override - public void search(NodeConnection node, CompressionType compression, int uncompressedLength, byte[] compressedPayload, - RpcSearchInvoker responseReceiver, double timeoutSeconds) { - if (malfunctioning) { - responseReceiver.receive(SearchResponseOrError.fromError("Malfunctioning")); - return; - } - - if(searchResult == null) { - responseReceiver.receive(SearchResponseOrError.fromError("No result defined")); - return; - } - var payload = ProtobufSerialization.serializeResult(searchResult); - var compressionResult = compressor.compress(compression, payload); - var response = new SearchResponse(compressionResult.type().getCode(), payload.length, compressionResult.data()); - responseReceiver.receive(SearchResponseOrError.fromResponse(response)); - } - public void setDocsumReponse(String nodeId, int docId, String docsumClass, Map<String, Object> docsumValues) { docsums.put(new DocsumKey(nodeId, globalIdFrom(docId), docsumClass), docsumValues); } 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 deleted file mode 100644 index 4792b45281f..00000000000 --- a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java +++ /dev/null @@ -1,95 +0,0 @@ -// 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"); - } - }; - } -} |