summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/federation
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-08-15 13:04:53 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-08-15 13:04:53 +0200
commit5533fcc881d516bf8e67ea6492ad6dc2174c6dd8 (patch)
tree5180634be83903a4e2c08b28a478151b0768be64 /container-search/src/test/java/com/yahoo/search/federation
parentbf6ffad296a00eb5e0d130d798d799de28c69b1e (diff)
Source deduplication test
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/federation')
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/test/DuplicateSourceTestCase.java68
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java15
2 files changed, 73 insertions, 10 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/federation/test/DuplicateSourceTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/test/DuplicateSourceTestCase.java
new file mode 100644
index 00000000000..c092a795c12
--- /dev/null
+++ b/container-search/src/test/java/com/yahoo/search/federation/test/DuplicateSourceTestCase.java
@@ -0,0 +1,68 @@
+package com.yahoo.search.federation.test;
+
+import com.google.common.collect.ImmutableList;
+import com.yahoo.component.ComponentId;
+import com.yahoo.component.chain.Chain;
+import com.yahoo.prelude.IndexFacts;
+import com.yahoo.search.Query;
+import com.yahoo.search.Result;
+import com.yahoo.search.Searcher;
+import com.yahoo.search.federation.FederationSearcher;
+import com.yahoo.search.federation.sourceref.SearchChainResolver;
+import com.yahoo.search.searchchain.Execution;
+import com.yahoo.search.searchchain.SearchChainRegistry;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests that sources representing document types which resolve to the same actual source
+ * are only included once.
+ *
+ * @author bratseth
+ */
+public class DuplicateSourceTestCase {
+
+ @Test
+ public void testDuplicateSource() {
+ // Set up a single cluster and chain (chain1), containing a MockBackendSearcher and having 2 doc types (doc1, doc2)
+ MockBackendSearcher mockBackendSearcher = new MockBackendSearcher();
+ SearchChainRegistry searchChains = new SearchChainRegistry();
+ searchChains.register(new Chain<>("chain1", mockBackendSearcher));
+ IndexFacts indexFacts = new IndexFacts();
+ Map<String, List<String>> clusters = new HashMap<>();
+ clusters.put("chain1", ImmutableList.of("doc1", "doc2"));
+ indexFacts.setClusters(clusters);
+ SearchChainResolver resolver = new SearchChainResolver.Builder()
+ .addSearchChain(new ComponentId("chain1"), ImmutableList.of("doc1", "doc2"))
+ .build();
+ FederationSearcher searcher = new FederationSearcher(new ComponentId("test"), resolver);
+
+ Result result = searcher.search(new Query("?query=test&sources=doc1%2cdoc2"),
+ new Execution(Execution.Context.createContextStub(searchChains, indexFacts)));
+
+ assertNull(result.hits().getError());
+ assertEquals(1, mockBackendSearcher.getInvocationCount());
+ }
+
+ private static final class MockBackendSearcher extends Searcher {
+
+ private final AtomicInteger invocationCount = new AtomicInteger(0);
+
+ @Override
+ public Result search(Query query, Execution execution) {
+ invocationCount.incrementAndGet();
+ return new Result(query);
+ }
+
+ public int getInvocationCount() { return invocationCount.get(); }
+
+ }
+
+}
diff --git a/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java
index 1899d1130e1..e4176bb6679 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/test/FederationSearcherTestCase.java
@@ -204,15 +204,10 @@ public class FederationSearcherTestCase {
public void testPropertyPropagation() {
Result result = searchWithPropertyPropagation(PropagateSourceProperties.ALL);
- assertEquals("source:mySource1", result.hits().get(0).getId()
- .stringValue());
- assertEquals("source:mySource2", result.hits().get(1).getId()
- .stringValue());
- assertEquals("nalle", result.hits().get(0).getQuery().getPresentation()
- .getSummary());
- assertNull(result.hits().get(1).getQuery().getPresentation()
- .getSummary());
-
+ assertEquals("source:mySource1", result.hits().get(0).getId().stringValue());
+ assertEquals("source:mySource2", result.hits().get(1).getId().stringValue());
+ assertEquals("nalle", result.hits().get(0).getQuery().getPresentation().getSummary());
+ assertNull(result.hits().get(1).getQuery().getPresentation().getSummary());
}
private Result searchWithPropertyPropagation(PropagateSourceProperties.Enum propagateSourceProperties) {
@@ -233,7 +228,7 @@ public class FederationSearcherTestCase {
assertNull(result.hits().get(0).getQuery().getPresentation().getSummary());
}
-
+
@Test
public void testNoCloning() {
String sourceName = "cloningcheck";