summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java')
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java77
1 files changed, 50 insertions, 27 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java
index affa6161440..ff91f346195 100644
--- a/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java
@@ -9,7 +9,7 @@ import com.yahoo.container.handler.ClustersStatus;
import com.yahoo.container.handler.VipStatus;
import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig;
import com.yahoo.prelude.fastsearch.FastHit;
-import com.yahoo.prelude.fastsearch.VespaBackEndSearcher;
+import com.yahoo.prelude.fastsearch.VespaBackend;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.config.ClusterConfig;
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -38,7 +39,6 @@ import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -51,21 +51,6 @@ public class ClusterSearcherTestCase {
private static final double DELTA = 0.0000000000000001;
- @Test
- void testNoBackends() {
- ClusterSearcher cluster = new ClusterSearcher(createSchemaInfo(), Set.of("dummy"));
- try {
- Execution execution = new Execution(cluster, Execution.Context.createContextStub());
- Query query = new Query("query=hello");
- query.setHits(10);
- com.yahoo.search.Result result = execution.search(query);
- assertNotNull(result.hits().getError());
- assertEquals("No backends in service. Try later", result.hits().getError().getMessage());
- } finally {
- cluster.deconstruct();
- }
- }
-
private static SchemaInfo createSchemaInfo() {
var schemas = Stream.of("type1", "type2", "type3", "type4", "type5", "type6")
.map(name -> new Schema.Builder(name).build()).toList();
@@ -89,10 +74,11 @@ public class ClusterSearcherTestCase {
@Test
void testThatDocumentTypesAreResolved() {
+ var backend = new MyMockBackend(false);
SchemaInfo schemaInfo = createSchemaInfo();
- ClusterSearcher cluster1 = new ClusterSearcher(schemaInfo, Set.of("type1", "type2", "type3"));
+ ClusterSearcher cluster1 = new ClusterSearcher(schemaInfo, Map.of("type1", backend, "type2", backend, "type3", backend));
try {
- ClusterSearcher type1 = new ClusterSearcher(schemaInfo, Set.of("type6"));
+ ClusterSearcher type1 = new ClusterSearcher(schemaInfo, Map.of("type6", backend));
try {
assertEquals(Set.of("type1", "type2", "type3"), resolve(cluster1, ""));
assertEquals(Set.of("type6"), resolve(type1, ""));
@@ -129,10 +115,11 @@ public class ClusterSearcherTestCase {
@Test
void testThatDocumentTypesAreResolvedTODO_REMOVE() {
+ var backend = new MyMockBackend(false);
SchemaInfo schemaInfo = createSchemaInfo();
- ClusterSearcher cluster1 = new ClusterSearcher(schemaInfo, Set.of("type1", "type2", "type3"));
+ ClusterSearcher cluster1 = new ClusterSearcher(schemaInfo, Map.of("type1", backend, "type2", backend, "type3", backend));
try {
- ClusterSearcher type1 = new ClusterSearcher(schemaInfo, Set.of("type6"));
+ ClusterSearcher type1 = new ClusterSearcher(schemaInfo, Map.of("type6", backend));
try {
assertEquals(Set.of(), resolve(cluster1, "&sources=cluster2"));
} finally {
@@ -143,13 +130,38 @@ public class ClusterSearcherTestCase {
}
}
- private static class MyMockSearcher extends VespaBackEndSearcher {
+ @Test
+ void testThatMultipleBackendsAreUsed() {
+ var backendA = new MyMockBackend(false);
+ var backendB = new MyMockBackend(false);
+ SchemaInfo schemaInfo = createSchemaInfo();
+ var cluster1 = new ClusterSearcher(schemaInfo, Map.of("type1", backendA, "type2", backendB, "type3", backendA),
+ new InThreadExecutorService());
+ try {
+ Execution execution = new Execution(cluster1, Execution.Context.createContextStub());
+ execution.search(new Query("?query=hello"));
+ assertEquals(2, backendA.queries().size());
+ assertEquals(1, backendB.queries().size());
+ execution.search(new Query("?query=hello&restrict=type1"));
+ assertEquals(3, backendA.queries().size());
+ assertEquals(1, backendB.queries().size());
+ execution.search(new Query("?query=hello&restrict=type2,type3"));
+ assertEquals(4, backendA.queries().size());
+ assertEquals(2, backendB.queries().size());
+ } finally {
+ cluster1.deconstruct();
+ }
+ }
+
+ private static class MyMockBackend extends VespaBackend {
private final String type1 = "type1";
private final String type2 = "type2";
private final String type3 = "type3";
private final Map<String, List<Hit>> results = new LinkedHashMap<>();
private final boolean expectAttributePrefetch;
+
+ private final List<Query> queries = new ArrayList<>();
static final String ATTRIBUTE_PREFETCH = "attributeprefetch";
private String getId(String type, int i) {
@@ -200,7 +212,7 @@ public class ClusterSearcherTestCase {
createHit(getId(type3, 2), 5)));
}
- MyMockSearcher(boolean expectAttributePrefetch) {
+ MyMockBackend(boolean expectAttributePrefetch) {
this.expectAttributePrefetch = expectAttributePrefetch;
init();
}
@@ -210,8 +222,11 @@ public class ClusterSearcherTestCase {
return null; // search() is overriden, this should never be called
}
+ List<Query> queries() { return queries; }
+
@Override
public com.yahoo.search.Result search(String schema, Query query) {
+ queries.add(query);
com.yahoo.search.Result result = new com.yahoo.search.Result(query);
List<Hit> hits = getHits(query);
if (hits != null) {
@@ -267,10 +282,14 @@ public class ClusterSearcherTestCase {
}
private Execution createExecution(List<String> docTypesList, boolean expectAttributePrefetch) {
+ var backend = new MyMockBackend(expectAttributePrefetch);
+ Map<String, VespaBackend> searchers = new HashMap<>();
+ for(String schema : docTypesList) {
+ searchers.put(schema, backend);
+ }
Set<String> documentTypes = new LinkedHashSet<>(docTypesList);
ClusterSearcher cluster = new ClusterSearcher(toSchemaInfo(documentTypes, "mycluster"),
- documentTypes,
- new MyMockSearcher(expectAttributePrefetch),
+ searchers,
new InThreadExecutorService());
try {
List<Schema> schemas = new ArrayList<>();
@@ -428,7 +447,7 @@ public class ClusterSearcherTestCase {
assertResult(6, List.of(7.0, 9.0), getResult(3, 2, extra, ex));
assertResult(6, List.of(9.0, 10.0), getResult(4, 2, extra, ex));
assertResult(6, List.of(10.0), getResult(5, 2, extra, ex));
- assertResult(6, List.of(), getResult(6, 2, extra, ex));
+ assertResult(6, List.of(), getResult(6, 2, extra, ex));
}
private static ClusterSearcher createSearcher(String clusterName, Double maxQueryTimeout, Double maxQueryCacheTimeout,
@@ -449,7 +468,11 @@ public class ClusterSearcherTestCase {
clusterConfig.maxQueryCacheTimeout(maxQueryCacheTimeout);
DocumentdbInfoConfig.Builder documentDbConfig = new DocumentdbInfoConfig.Builder();
- documentDbConfig.documentdb(new DocumentdbInfoConfig.Documentdb.Builder().name("type1"));
+ documentDbConfig.documentdb(new DocumentdbInfoConfig.Documentdb.Builder()
+ .name("type1")
+ .mode(streamingMode
+ ? DocumentdbInfoConfig.Documentdb.Mode.Enum.STREAMING
+ : DocumentdbInfoConfig.Documentdb.Mode.Enum.INDEX));
var schema = new Schema.Builder("type1");
DispatchConfig dispatchConfig = new DispatchConfig.Builder().build();