aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java')
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java141
1 files changed, 87 insertions, 54 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java
index 4fffc450e74..156a0dcbb3e 100644
--- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java
@@ -31,12 +31,9 @@ import com.yahoo.search.searchchain.Execution;
import com.yahoo.search.searchchain.SearchChain;
import com.yahoo.search.searchchain.SearchChainRegistry;
import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests the BlendingSearcher class
@@ -125,7 +122,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testitTwoPhase() {
+ void testitTwoPhase() {
DocumentSourceSearcher chain1 = new DocumentSourceSearcher();
DocumentSourceSearcher chain2 = new DocumentSourceSearcher();
DocumentSourceSearcher chain3 = new DocumentSourceSearcher();
@@ -137,27 +134,63 @@ public class BlendingSearcherTestCase {
Result r3 = new Result(q);
r1.setTotalHitCount(13);
- r1.hits().add(new Hit("http://host1.com", 101){{setSource("one");}});
- r1.hits().add(new Hit("http://host2.com", 102){{setSource("one");}});
- r1.hits().add(new Hit("http://host3.com", 103){{setSource("one");}});
+ r1.hits().add(new Hit("http://host1.com", 101){
+ {
+ setSource("one");
+ }
+ });
+ r1.hits().add(new Hit("http://host2.com", 102){
+ {
+ setSource("one");
+ }
+ });
+ r1.hits().add(new Hit("http://host3.com", 103){
+ {
+ setSource("one");
+ }
+ });
chain1.addResult(q, r1);
r2.setTotalHitCount(17);
- r2.hits().add(new Hit("http://host1.com", 101){{setSource("two");}});
- r2.hits().add(new Hit("http://host2.com", 102){{setSource("two");}});
- r2.hits().add(new Hit("http://host4.com", 104){{setSource("two");}});
+ r2.hits().add(new Hit("http://host1.com", 101){
+ {
+ setSource("two");
+ }
+ });
+ r2.hits().add(new Hit("http://host2.com", 102){
+ {
+ setSource("two");
+ }
+ });
+ r2.hits().add(new Hit("http://host4.com", 104){
+ {
+ setSource("two");
+ }
+ });
chain2.addResult(q, r2);
r3.setTotalHitCount(37);
- r3.hits().add(new Hit("http://host5.com", 100){{setSource("three");}});
- r3.hits().add(new Hit("http://host6.com", 106){{setSource("three");}});
- r3.hits().add(new Hit("http://host7.com", 105){{setSource("three");}});
+ r3.hits().add(new Hit("http://host5.com", 100){
+ {
+ setSource("three");
+ }
+ });
+ r3.hits().add(new Hit("http://host6.com", 106){
+ {
+ setSource("three");
+ }
+ });
+ r3.hits().add(new Hit("http://host7.com", 105){
+ {
+ setSource("three");
+ }
+ });
chain3.addResult(q, r3);
BlendingSearcherWrapper blender1 = new BlendingSearcherWrapper();
blender1.addSource("one", chain1);
blender1.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result br1 = new Execution(blender1, Execution.Context.createContextStub()).search(q);
assertEquals(3, br1.getHitCount());
assertEquals(13, br1.getTotalHitCount());
@@ -167,7 +200,7 @@ public class BlendingSearcherTestCase {
blender2.addSource("two", chain1);
blender2.addSource("three", chain2);
blender2.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result br2 = new Execution(blender2, Execution.Context.createContextStub()).search(q);
assertEquals(6, br2.getHitCount());
assertEquals(30, br2.getTotalHitCount());
@@ -178,28 +211,28 @@ public class BlendingSearcherTestCase {
blender3.addSource("five", chain2);
blender3.addSource("six", chain3);
blender3.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result br3 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
assertEquals(9, br3.getHitCount());
assertEquals(67, br3.getTotalHitCount());
assertEquals("http://host6.com/", br3.hits().get(0).getId().toString());
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result br4 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
assertEquals(9, br4.getHitCount());
assertEquals("http://host6.com/", br4.hits().get(0).getId().toString());
- q.setWindow( 3, 10);
+ q.setWindow(3, 10);
Result br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
assertEquals(6, br5.getHitCount());
assertEquals("http://host3.com/", br5.hits().get(0).getId().toString());
- q.setWindow( 3, 10);
+ q.setWindow(3, 10);
br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
assertEquals(6, br5.getHitCount());
assertEquals("http://host3.com/", br5.hits().get(0).getId().toString());
- q.setWindow( 3, 10);
+ q.setWindow(3, 10);
br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
assertEquals(6, br5.getHitCount());
assertEquals("http://host3.com/", br5.hits().get(0).getId().toString());
@@ -207,7 +240,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testMultipleBackendsWithDuplicateRemoval() {
+ void testMultipleBackendsWithDuplicateRemoval() {
DocumentSourceSearcher docSource1 = new DocumentSourceSearcher();
DocumentSourceSearcher docSource2 = new DocumentSourceSearcher();
Query q = new Query("/search?query=hannibal&search=a,b");
@@ -225,14 +258,14 @@ public class BlendingSearcherTestCase {
blender.addSource(new Chain<>("a", new FillSearcher(), docSource1));
blender.addSource(new Chain<>("b", new FillSearcher(), docSource2));
blender.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q);
assertEquals(1, cr.getHitCount());
assertEquals(101, ((int) cr.hits().get(0).getRelevance().getScore()));
}
@Test
- public void testMultipleBackendsWithErrorMerging() {
+ void testMultipleBackendsWithErrorMerging() {
DocumentSourceSearcher docSource1 = new DocumentSourceSearcher();
DocumentSourceSearcher docSource2 = new DocumentSourceSearcher();
Query q = new Query("/search?query=hannibal&search=a,b");
@@ -249,25 +282,25 @@ public class BlendingSearcherTestCase {
blender.addSource(new Chain<>("a", new FillSearcher(), docSource1));
blender.addSource(new Chain<>("b", new FillSearcher(), docSource2));
blender.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q);
assertEquals(2, cr.getHitCount());
assertEquals(1, cr.getConcreteHitCount());
com.yahoo.search.result.ErrorHit errorHit = cr.hits().getErrorHit();
Iterator errorIterator = errorHit.errorIterator();
List<String> errorList = Arrays.asList("Source 'a': No backends in service. Try later",
- "Source 'b': 2: Request too large");
+ "Source 'b': 2: Request too large");
String a = errorIterator.next().toString();
- assertTrue(a, errorList.contains(a));
+ assertTrue(errorList.contains(a), a);
String b = errorIterator.next().toString();
- assertTrue(a, errorList.contains(b));
+ assertTrue(errorList.contains(b), a);
assertFalse(errorIterator.hasNext());
assertEquals(102, ((int) cr.hits().get(1).getRelevance().getScore()));
assertEquals(com.yahoo.container.protect.Error.NO_BACKENDS_IN_SERVICE.code, cr.hits().getError().getCode());
}
@Test
- public void testBlendingWithSortSpec() {
+ void testBlendingWithSortSpec() {
DocumentSourceSearcher docSource1 = new DocumentSourceSearcher();
DocumentSourceSearcher docSource2 = new DocumentSourceSearcher();
@@ -310,7 +343,7 @@ public class BlendingSearcherTestCase {
blender.addSource(new Chain<>("a", new FillSearcher(), docSource1));
blender.addSource(new Chain<>("b", new FillSearcher(), docSource2));
blender.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result br = new Execution(blender, Execution.Context.createContextStub()).search(q);
assertEquals(202, ((int) br.hits().get(0).getRelevance().getScore()));
assertEquals(103, ((int) br.hits().get(1).getRelevance().getScore()));
@@ -326,7 +359,7 @@ public class BlendingSearcherTestCase {
* But are we sure fsearch handles this case correctly?
*/
@Test
- public void testBlendingWithSortSpecAnd2Phase() {
+ void testBlendingWithSortSpecAnd2Phase() {
DocumentSourceSearcher docSource1 = new DocumentSourceSearcher();
DocumentSourceSearcher docSource2 = new DocumentSourceSearcher();
@@ -362,7 +395,7 @@ public class BlendingSearcherTestCase {
blender.addSource("chainedone", docSource1);
blender.addSource("chainedtwo", docSource2);
blender.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result br = new Execution(blender, Execution.Context.createContextStub()).search(q);
assertEquals(202, ((int) br.hits().get(0).getRelevance().getScore()));
assertEquals(103, ((int) br.hits().get(1).getRelevance().getScore()));
@@ -400,7 +433,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testOnlyFirstBackend() {
+ void testOnlyFirstBackend() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first");
@@ -410,7 +443,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testOnlySecondBackend() {
+ void testOnlySecondBackend() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=second");
@@ -421,7 +454,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testBothBackendsExplicitly() {
+ void testBothBackendsExplicitly() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first,second");
@@ -433,7 +466,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testBothBackendsImplicitly() {
+ void testBothBackendsImplicitly() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana");
@@ -445,7 +478,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testNonexistingBackendCausesError() {
+ void testNonexistingBackendCausesError() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=nonesuch");
@@ -459,7 +492,7 @@ public class BlendingSearcherTestCase {
}
@Test
- public void testNonexistingBackendsCausesErrorOnFirst() {
+ void testNonexistingBackendsCausesErrorOnFirst() {
// Feel free to change to include all in the detail message...
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=nonesuch,orsuch");
@@ -471,11 +504,11 @@ public class BlendingSearcherTestCase {
assertEquals("Invalid query parameter", e.getMessage());
//TODO: Do not depend on sources order
assertEquals("4: Invalid query parameter: Could not resolve source ref 'nonesuch'. Could not resolve source ref 'orsuch'. Valid source refs are first, second.",
- e.toString());
+ e.toString());
}
@Test
- public void testExistingAndNonExistingBackendCausesBothErrorAndResult() {
+ void testExistingAndNonExistingBackendCausesBothErrorAndResult() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first,nonesuch,second");
@@ -488,11 +521,11 @@ public class BlendingSearcherTestCase {
ErrorMessage e = result.hits().getError();
//TODO: Do not depend on sources order
assertEquals("Could not resolve source ref 'nonesuch'. Valid source refs are first, second.",
- e.getDetailedMessage());
+ e.getDetailedMessage());
}
@Test
- public void testBlendingFederationWithGrouping() {
+ void testBlendingFederationWithGrouping() {
DocumentSourceSearcher docSource1 = new DocumentSourceSearcher();
DocumentSourceSearcher docSource2 = new DocumentSourceSearcher();
@@ -528,22 +561,22 @@ public class BlendingSearcherTestCase {
blender.addSource(new Chain<>("a", new FillSearcher(), docSource1));
blender.addSource(new Chain<>("b", new FillSearcher(), docSource2));
blender.initialize();
- q.setWindow( 0, 10);
+ q.setWindow(0, 10);
Result result = new Execution(blender, Execution.Context.createContextStub()).search(q);
assertEquals(2, result.hits().size());
assertTrue(result.hits().get(0) instanceof RootGroup);
- RootGroup resultRoot1 = (RootGroup)result.hits().get(0);
+ RootGroup resultRoot1 = (RootGroup) result.hits().get(0);
assertEquals(1, resultRoot1.asList().size());
assertTrue(result.hits().get(1) instanceof RootGroup);
- RootGroup resultRoot2 = (RootGroup)result.hits().get(1);
+ RootGroup resultRoot2 = (RootGroup) result.hits().get(1);
assertEquals(2, resultRoot2.asList().size());
}
/** Multiple document types in the same cluster are returned without a top level group representing each */
@Test
- public void testBlendingMultipleDocumentTypesWithGrouping() {
+ void testBlendingMultipleDocumentTypesWithGrouping() {
DocumentSourceSearcher docSource = new DocumentSourceSearcher();
Query q = new Query("/search?query=test");
@@ -574,23 +607,23 @@ public class BlendingSearcherTestCase {
docSource.addResult(q, r);
Chain<Searcher> chain = new Chain<>("main",
- new FillSearcher(),
- new BlendingSearcher(ComponentId.fromString("test"), new QrSearchersConfig.Builder().build()),
- docSource);
- q.setWindow( 0, 10);
+ new FillSearcher(),
+ new BlendingSearcher(ComponentId.fromString("test"), new QrSearchersConfig.Builder().build()),
+ docSource);
+ q.setWindow(0, 10);
Result result = new Execution(chain, Execution.Context.createContextStub()).search(q);
assertEquals(3, result.hits().size());
assertTrue(result.hits().get(0) instanceof Group);
- Group resultSubGroup1 = (Group)result.hits().get(0);
+ Group resultSubGroup1 = (Group) result.hits().get(0);
assertEquals(4, resultSubGroup1.asList().size());
assertTrue(result.hits().get(1) instanceof Group);
- Group resultSubGroup2 = (Group)result.hits().get(1);
+ Group resultSubGroup2 = (Group) result.hits().get(1);
assertEquals(3, resultSubGroup2.asList().size());
assertTrue(result.hits().get(2) instanceof Group);
- Group resultSubGroup3 = (Group)result.hits().get(2);
+ Group resultSubGroup3 = (Group) result.hits().get(2);
assertEquals(2, resultSubGroup3.asList().size());
}