diff options
Diffstat (limited to 'container-search/src/test/java')
70 files changed, 454 insertions, 3838 deletions
diff --git a/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java b/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java index 9b1517454a9..54512e727c2 100644 --- a/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java +++ b/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java @@ -50,7 +50,7 @@ public class GetDocSumsPacketTestCase { @Test public void requireThatSessionIdIsEncodedAsPropertyWhenUsingSearchSession() throws BufferTooSmallException { Result result = new Result(new Query("?query=foo")); - SessionId sessionId = result.getQuery().getSessionId(true); // create session id. + SessionId sessionId = result.getQuery().getSessionId("node-0"); result.getQuery().getRanking().setQueryCache(true); FastHit hit = new FastHit(); result.hits().add(hit); diff --git a/container-search/src/test/java/com/yahoo/fs4/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/fs4/test/QueryTestCase.java index 78b2f65305a..e2ce26cb908 100644 --- a/container-search/src/test/java/com/yahoo/fs4/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/fs4/test/QueryTestCase.java @@ -12,6 +12,7 @@ import com.yahoo.prelude.query.PhraseSegmentItem; import com.yahoo.prelude.query.WeightedSetItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.search.Query; +import com.yahoo.search.query.ranking.SoftTimeout; import org.junit.Test; import java.nio.ByteBuffer; @@ -52,6 +53,8 @@ public class QueryTestCase { @Test public void testEncodeQueryPacketWithSomeAdditionalFeatures() { Query query = new Query("/?query=chain&dataset=10&type=phrase&timeout=0"); + query.properties().set(SoftTimeout.enableProperty, false); + // Because the rank mapping now needs config and a searcher, // we do the sledgehammer dance: query.getRanking().setProfile("two"); @@ -79,7 +82,7 @@ public class QueryTestCase { "&ranking.features.query(foo)=30.3&ranking.features.query(bar)=0" + "&ranking.properties.property.p1=v1&ranking.properties.property.p2=v2" + "&pos.ll=S22.4532;W123.9887&pos.radius=3&pos.attribute=place&ranking.freshness=37" + - "&model.searchPath=7/3"); + "&model.searchPath=7/3&ranking.softtimeout.enable=false"); query.getRanking().setFreshness(new Freshness("123456")); query.getRanking().setSorting("+field1 -field2"); query.getRanking().setProfile("two"); @@ -105,7 +108,7 @@ public class QueryTestCase { "&ranking.features.query(foo)=30.3&ranking.features.query(bar)=0" + "&ranking.properties.property.p1=v1&ranking.properties.property.p2=v2" + "&pos.ll=S22.4532;W123.9887&pos.radius=3&pos.attribute=place&ranking.freshness=37" + - "&model.searchPath=7/3"); + "&model.searchPath=7/3&ranking.softtimeout.enable=false"); query.getRanking().setFreshness("123456"); query.getRanking().setSorting("+field1 -field2"); query.getRanking().setProfile("two"); @@ -127,6 +130,7 @@ public class QueryTestCase { @Test public void testEncodeQueryPacketWithLabelsConnectivityAndSignificance() { Query query = new Query(); + query.properties().set(SoftTimeout.enableProperty, false); AndItem and = new AndItem(); WeightedSetItem taggable1 = new WeightedSetItem("field1"); taggable1.setLabel("foo"); 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 646c466eba9..25d6a6e9777 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 @@ -6,7 +6,6 @@ import com.yahoo.component.ComponentId; import com.yahoo.container.QrConfig; import com.yahoo.container.QrSearchersConfig; import com.yahoo.container.search.Fs4Config; -import com.yahoo.container.search.LegacyEmulationConfig; import com.yahoo.fs4.QueryPacket; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.IndexModel; @@ -540,7 +539,6 @@ public class ClusterSearcherTestCase { qrSearchersConfig.build(), clusterConfig.build(), documentDbConfig.build(), - new LegacyEmulationConfig.Builder().build(), new QrMonitorConfig.Builder().build(), new DispatchConfig.Builder().build(), createClusterInfoConfig(), @@ -555,7 +553,7 @@ public class ClusterSearcherTestCase { clusterInfoConfigBuilder.nodeCount(1); return new ClusterInfoConfig(clusterInfoConfigBuilder); } - + private static class QueryTimeoutFixture { ClusterSearcher searcher; Execution exec; diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java index 81f16f7f261..ad4d0cf82e5 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.prelude.fastsearch; import com.google.common.collect.ImmutableSet; import com.yahoo.config.subscription.ConfigGetter; -import com.yahoo.container.search.LegacyEmulationConfig; import com.yahoo.prelude.hitfield.RawData; import com.yahoo.prelude.hitfield.XMLString; import com.yahoo.prelude.hitfield.JSONString; @@ -66,33 +65,6 @@ public class SlimeSummaryTestCase { } @Test - public void testDecodingEmptyWithLegacyEmulation() { - LegacyEmulationConfig emulationConfig = new LegacyEmulationConfig(new LegacyEmulationConfig.Builder().forceFillEmptyFields(true)); - DocsumDefinitionSet docsum = createDocsumDefinitionSet(summary_cf, emulationConfig); - FastHit hit = new FastHit(); - assertNull(docsum.lazyDecode("default", emptySummary(), hit)); - assertEquals(NanNumber.NaN, hit.getField("integer_field")); - assertEquals(NanNumber.NaN, hit.getField("short_field")); - assertEquals(NanNumber.NaN, hit.getField("byte_field")); - assertEquals(NanNumber.NaN, hit.getField("float_field")); - assertEquals(NanNumber.NaN, hit.getField("double_field")); - assertEquals(NanNumber.NaN, hit.getField("int64_field")); - assertEquals("", hit.getField("string_field")); - assertEquals(RawData.class, hit.getField("data_field").getClass()); - assertEquals("", hit.getField("data_field").toString()); - assertEquals("", hit.getField("longstring_field")); - assertEquals(RawData.class, hit.getField("longdata_field").getClass()); - assertEquals("", hit.getField("longdata_field").toString()); - assertEquals(XMLString.class, hit.getField("xmlstring_field").getClass()); - assertEquals("", hit.getField("xmlstring_field").toString()); - // assertEquals(hit.getField("jsonstring_field"), instanceOf(JSONString.class)); - assertEquals("", hit.getField("jsonstring_field").toString()); - // Empty tensors are represented by null because we don't have type information here to create the right empty tensor - assertNull(hit.getField("tensor_field1")); - assertNull(hit.getField("tensor_field2")); - } - - @Test public void testTimeout() { DocsumDefinitionSet docsum = createDocsumDefinitionSet(summary_cf); FastHit hit = new FastHit(); @@ -424,11 +396,6 @@ public class SlimeSummaryTestCase { return new DocsumDefinitionSet(config.documentdb(0)); } - private DocsumDefinitionSet createDocsumDefinitionSet(String configID, LegacyEmulationConfig legacyEmulationConfig) { - DocumentdbInfoConfig config = new ConfigGetter<>(DocumentdbInfoConfig.class).getConfig(configID); - return new DocsumDefinitionSet(config.documentdb(0), legacyEmulationConfig); - } - private static class Utf8FieldTraverser implements Hit.RawUtf8Consumer { private Map<String, Object> traversed; diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java index c4d32111124..fd01fb9a740 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java @@ -153,7 +153,7 @@ public class FastSearcherTestCase { } { // direct.summaries due to query cache - String query = "?query=sddocname:a&ranking.queryCache"; + String query = "?query=sddocname:a&ranking.queryCache&timeout=5000ms"; Result result = doSearch(fastSearcher, new Query(query), 0, 10); doFill(fastSearcher, result); ErrorMessage error = result.hits().getError(); @@ -162,7 +162,7 @@ public class FastSearcherTestCase { } { // direct.summaries due to no summary features - String query = "?query=sddocname:a&dispatch.summaries&summary=simple&ranking=simpler"; + String query = "?query=sddocname:a&dispatch.summaries&summary=simple&ranking=simpler&timeout=5000ms"; Result result = doSearch(fastSearcher, new Query(query), 0, 10); doFill(fastSearcher, result); ErrorMessage error = result.hits().getError(); @@ -185,6 +185,7 @@ public class FastSearcherTestCase { documentdbConfigWithOneDb); Query query = new Query("?query=foo&model.restrict=testDb"); + query.getRanking().getSoftTimeout().setEnable(false); query.prepare(); doSearch(fastSearcher, query, 0, 10); @@ -330,7 +331,7 @@ public class FastSearcherTestCase { byte[] actual = new byte[buf.remaining()]; buf.get(actual); - SessionId sessionId = query.getSessionId(false); + SessionId sessionId = query.getSessionId(); byte IGNORE = 69; ByteBuffer answer = ByteBuffer.allocate(1024); answer.put(new byte[] { 0, 0, 0, (byte)(141+sessionId.asUtf8String().getByteLength()), 0, 0, 0, -37, 0, 0, 16, 17, 0, 0, 0, 0, diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/TestLinguistics.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/TestLinguistics.java index db5397e5292..b697841a969 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/TestLinguistics.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/TestLinguistics.java @@ -60,12 +60,6 @@ public class TestLinguistics implements Linguistics { return linguistics.getCharacterClasses(); } - @Override - @Deprecated - public Tuple2<String, Version> getVersion(Linguistics.Component component) { - return linguistics.getVersion(component); - } - } diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/indexcombinator.cfg b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/indexcombinator.cfg deleted file mode 100644 index a8790cc4051..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/indexcombinator.cfg +++ /dev/null @@ -1,29 +0,0 @@ -indexinfo[1] -indexinfo[0].name combinedattributeandindexsearch -indexinfo[0].command[12] -indexinfo[0].command[0].indexname sddocname -indexinfo[0].command[0].command index -indexinfo[0].command[1].indexname index1 -indexinfo[0].command[1].command index -indexinfo[0].command[2].indexname default -indexinfo[0].command[2].command index -indexinfo[0].command[3].indexname index1 -indexinfo[0].command[3].command stem -indexinfo[0].command[4].indexname default -indexinfo[0].command[4].command stem -indexinfo[0].command[5].indexname index1 -indexinfo[0].command[5].command index1 -indexinfo[0].command[5].command normalize -indexinfo[0].command[6].indexname default -indexinfo[0].command[6].command normalize -indexinfo[0].command[7].indexname attribute1 -indexinfo[0].command[7].command index -indexinfo[0].command[8].indexname attribute1 -indexinfo[0].command[8].command attribute -indexinfo[0].command[9].indexname attribute2 -indexinfo[0].command[9].command attribute -indexinfo[0].command[10].indexname default -indexinfo[0].command[10].command "match-group default attribute1 attribute2" -indexinfo[0].command[11].indexname ranklog -indexinfo[0].command[11].command xmlstring - 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 fae869c5235..47009eb703b 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 @@ -51,20 +51,20 @@ public class BlendingSearcherTestCase { private final Map<String, Searcher> searchers = new HashMap<>(); private SearchChainRegistry chainRegistry; - private final String blendingDocumentId; + private final String blendingField; public BlendingSearcherWrapper() { - blendingDocumentId = null; + blendingField = null; } - public BlendingSearcherWrapper(String blendingDocumentId) { - this.blendingDocumentId = blendingDocumentId; + public BlendingSearcherWrapper(String blendingField) { + this.blendingField = blendingField; } @SuppressWarnings("serial") public BlendingSearcherWrapper(QrSearchersConfig cfg) { QrSearchersConfig.Com.Yahoo.Prelude.Searcher.BlendingSearcher s = cfg.com().yahoo().prelude().searcher().BlendingSearcher(); - blendingDocumentId = s.docid().length() > 0 ? s.docid() : null; + blendingField = s.docid().length() > 0 ? s.docid() : null; } public boolean addChained(Searcher searcher, String sourceName) { @@ -109,7 +109,7 @@ public class BlendingSearcherTestCase { FederationSearcher fedSearcher = new FederationSearcher(new FederationConfig(builder), contracts, new ComponentRegistry<>()); - BlendingSearcher blendingSearcher = new BlendingSearcher(blendingDocumentId); + BlendingSearcher blendingSearcher = new BlendingSearcher(blendingField); blendingChain = new SearchChain(ComponentId.createAnonymousComponentId("blendingChain"), blendingSearcher, fedSearcher); return true; } @@ -217,7 +217,7 @@ public class BlendingSearcherTestCase { r2.setTotalHitCount(1); chain2.addResult(q, r2); - BlendingSearcherWrapper blender = new BlendingSearcherWrapper("uri"); + BlendingSearcherWrapper blender = new BlendingSearcherWrapper("[id]"); blender.addChained(new FillSearcher(chain1), "a"); blender.addChained(new FillSearcher(chain2), "b"); blender.initialize(); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java index bf86ca4544b..4875121a501 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java @@ -336,11 +336,6 @@ public class FieldCollapsingSearcherTestCase { assertHit("http://acme.org/h.html", 6,1,r.hits().get(1)); } - // This test depends on DocumentSourceSearcher filling the hits - // with whatever data it got, ignoring actual summary arguments - // in the fill call, then saying the hits are filled for the - // ignored argument. Rewrite to contain different summaries if - // DocumentSourceSearcher gets extended. @Test public void testFieldCollapsingTwoPhaseSelectSummary() { // Set up diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java index 9f4a12d24e6..24af91cb5c0 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java @@ -47,7 +47,7 @@ public class JuniperSearcherTestCase { DocumentSourceSearcher docsource = new DocumentSourceSearcher(); addResult(new Query("?query=12"), sdName, content, docsource); addResult(new Query("?query=12&bolding=false"), sdName, content, docsource); - return new Chain<Searcher>(searcher, docsource); + return new Chain<>(searcher, docsource); } private void addResult(Query query, String sdName, String content, DocumentSourceSearcher docsource) { diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java deleted file mode 100644 index 7b92e2c1a7c..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.searcher.test; - -import com.google.common.util.concurrent.MoreExecutors; -import com.yahoo.component.chain.Chain; -import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.Searcher; -import com.yahoo.search.rendering.RendererRegistry; -import com.yahoo.search.result.Hit; -import com.yahoo.prelude.searcher.QuerySnapshotSearcher; -import com.yahoo.search.searchchain.Execution; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * @author bratseth - */ -public class QuerySnapshotSearcherTestCase { - - @Test - public void test() { - Searcher searcher=new QuerySnapshotSearcher(); - Result result = doSearch(searcher, new Query(), 0,10); - Hit hit=result.hits().get(0); - assertEquals(String.valueOf(Double.POSITIVE_INFINITY), - hit.getRelevance().toString()); - } - - private Result doSearch(Searcher searcher, Query query, int offset, int hits) { - query.setOffset(offset); - query.setHits(hits); - return createExecution(searcher).search(query); - } - - private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); - return new Execution(chainedAsSearchChain(searcher), context); - } - - private Chain<Searcher> chainedAsSearchChain(Searcher topOfChain) { - List<Searcher> searchers = new ArrayList<>(); - searchers.add(topOfChain); - return new Chain<>(searchers); - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java deleted file mode 100644 index 3967ac63e36..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.searcher.test; - -import com.google.common.util.concurrent.MoreExecutors; -import com.yahoo.component.chain.Chain; -import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.search.rendering.RendererRegistry; -import com.yahoo.search.result.Hit; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.Searcher; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; -import com.yahoo.prelude.searcher.QueryValidatingSearcher; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * Tests correct denial of query. - * - * @author Steinar Knutsen - */ -public class QueryValidatingSearcherTestCase { - - @Test - public void testBasic() { - // Setup - Map<Searcher, Searcher> chained = new HashMap<>(); - Query query = new Query("?query=test"); - - Result result = new Result(query); - result.hits().add(new Hit("ymail://1111111111/AQAAAP7JgwEAj6XjQQAAAO/+ggA=",950)); - - Searcher validator = new QueryValidatingSearcher(); - DocumentSourceSearcher source = new DocumentSourceSearcher(); - chained.put(validator, source); - source.addResult(query, result); - - // Exercise - Result returnedResult = doSearch(validator, query, 0, 10, chained); - - // Validate - assertEquals(1, returnedResult.getHitCount()); - assertNull(returnedResult.hits().getError()); - - returnedResult = doSearch(validator, query, 0, 1001, chained); - assertEquals(0, returnedResult.getConcreteHitCount()); - assertEquals(4, returnedResult.hits().getError().getCode()); - - returnedResult = doSearch(validator, query, 1001, 10, chained); - assertEquals(0, returnedResult.getConcreteHitCount()); - assertEquals(4, returnedResult.hits().getError().getCode()); - } - - private Result doSearch(Searcher searcher, Query query, int offset, int hits, Map<Searcher, Searcher> chained) { - query.setOffset(offset); - query.setHits(hits); - return createExecution(searcher, chained).search(query); - } - - private Chain<Searcher> chainedAsSearchChain(Searcher topOfChain, Map<Searcher, Searcher> chained) { - List<Searcher> searchers = new ArrayList<>(); - for (Searcher current = topOfChain; current != null; current = chained.get(current)) { - searchers.add(current); - } - return new Chain<>(searchers); - } - - private Execution createExecution(Searcher searcher, Map<Searcher, Searcher> chained) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); - return new Execution(chainedAsSearchChain(searcher, chained), context); - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/BoomTemplate.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/BoomTemplate.java deleted file mode 100644 index 0bbc5151b40..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/BoomTemplate.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.templates.test; - -import java.io.IOException; -import java.io.Writer; - -import com.yahoo.prelude.templates.Context; -import com.yahoo.prelude.templates.UserTemplate; - -/** - * Test template which throws a runtime exception in its footer. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -@SuppressWarnings("rawtypes") -public class BoomTemplate extends UserTemplate { - public BoomTemplate(String name, String mimeType, String encoding) { - super(name, mimeType, encoding); - } - - @Override - public void error(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void footer(Context context, Writer writer) throws IOException { - throw new RuntimeException("Boom!"); - } - - @Override - public void header(Context context, Writer writer) throws IOException { - writer.write("header"); - } - - @Override - public void hit(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void hitFooter(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void noHits(Context context, Writer writer) throws IOException { - // NOP - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java deleted file mode 100644 index 07d5dcc9e2d..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.templates.test; - -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.result.Hit; -import com.yahoo.search.result.HitGroup; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Tests composition of grouped results using the HitGroup class - * - * @author bratseth - */ -public class GroupedResultTestCase { - - @Test - public void testGroupedResult() { - Result result=new Result(new Query("?query=foo")); - HitGroup hitGroup1=new HitGroup("group1",300); - hitGroup1.add(new Hit("group1.1",200)); - HitGroup hitGroup2=new HitGroup("group2",600); - Hit topLevelHit1=new Hit("toplevel.1",500); - Hit topLevelHit2=new Hit("toplevel.2",700); - result.hits().add(hitGroup1); - result.hits().add(topLevelHit1); - result.hits().add(hitGroup2); - result.hits().add(topLevelHit2); - hitGroup1.add(new Hit("group1.2",800)); - hitGroup2.add(new Hit("group2.1",800)); - hitGroup2.add(new Hit("group2.2",300)); - hitGroup2.add(new Hit("group2.3",500)); - - // Should have 7 concrete hits, ordered as - // toplevel.2 - // group2 - // group2.1 - // group2.3 - // group2.2 - // toplevel.1 - // group1 - // group1.2 - // group1.1 - // Assert this: - - assertEquals(7,result.getConcreteHitCount()); - assertEquals(4,result.getHitCount()); - - Hit topLevel2=result.hits().get(0); - assertEquals("toplevel.2",topLevel2.getId().stringValue()); - - HitGroup returnedGroup2=(HitGroup)result.hits().get(1); - assertEquals(3,returnedGroup2.getConcreteSize()); - assertEquals(3,returnedGroup2.size()); - assertEquals("group2.1",returnedGroup2.get(0).getId().stringValue()); - assertEquals("group2.3",returnedGroup2.get(1).getId().stringValue()); - assertEquals("group2.2",returnedGroup2.get(2).getId().stringValue()); - - Hit topLevel1=result.hits().get(2); - assertEquals("toplevel.1",topLevel1.getId().stringValue()); - - HitGroup returnedGroup1=(HitGroup)result.hits().get(3); - assertEquals(2,returnedGroup1.getConcreteSize()); - assertEquals(2,returnedGroup1.size()); - assertEquals("group1.2",returnedGroup1.get(0).getId().stringValue()); - assertEquals("group1.1",returnedGroup1.get(1).getId().stringValue()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/HitContextTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/HitContextTestCase.java deleted file mode 100644 index 6ff8c2f9d6c..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/HitContextTestCase.java +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.templates.test; - -import static org.junit.Assert.assertEquals; - -import java.lang.reflect.Method; -import java.util.List; - -import org.junit.Test; - -import com.yahoo.prelude.templates.HitContext; -import com.yahoo.protect.ClassValidator; - -/** - * Check the entire Context class is correctly masked. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class HitContextTestCase { - - @Test - public void checkMethods() { - List<Method> unmasked = ClassValidator.unmaskedMethodsFromSuperclass(HitContext.class); - assertEquals("Unmasked methods from superclass: " + unmasked, 0, unmasked.size()); - } -} diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java deleted file mode 100644 index 6f49ebbdee0..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.templates.test; - -import java.io.ByteArrayOutputStream; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; - -import com.yahoo.io.ByteWriter; -import com.yahoo.prelude.templates.UserTemplate; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author Steinar Knutsen - */ -public class TemplateTestCase { - - private CharsetEncoder encoder; - private ByteArrayOutputStream stream; - - public TemplateTestCase () { - Charset cs = Charset.forName("UTF-8"); - encoder = cs.newEncoder(); - stream = new ByteArrayOutputStream(); - } - - @Test - public void testASCIIQuoting() throws java.io.IOException { - stream.reset(); - byte[] c = new byte[] { 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; - ByteWriter bw = new ByteWriter(stream, encoder); - UserTemplate.dumpAndXMLQuoteUTF8(bw, c); - bw.close(); - String res = stream.toString("UTF-8"); - String correct = "abc\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\t\n\\u000B\\u000C\r\\u000E\\u000F\\u0010\\u0011"; - assertEquals(correct, res); - - } - - @Test - public void testXMLQuoting() throws java.io.IOException { - stream.reset(); - // c = <s>> - byte[] c = new byte[] { 60, 115, 62, 38, 103, 116, 59 }; - ByteWriter bw = new ByteWriter(stream, encoder); - UserTemplate.dumpAndXMLQuoteUTF8(bw, c); - bw.close(); - String res = stream.toString("UTF-8"); - String correct = "<s>&gt;"; - assertEquals(correct, res); - - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/TestTemplate.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/TestTemplate.java deleted file mode 100644 index 0f5e126dae8..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/TestTemplate.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.templates.test; - -import java.io.IOException; -import java.io.Writer; - -import com.yahoo.prelude.templates.Context; -import com.yahoo.prelude.templates.UserTemplate; - -/** - * Test basic UserTemplate functionality of detecting - * overridden group rendering methods. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -@SuppressWarnings("rawtypes") -public class TestTemplate extends UserTemplate { - - public TestTemplate(String name, String mimeType, String encoding) { - super(name, mimeType, encoding); - } - - @Override - public void error(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void footer(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void header(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void hit(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void hitFooter(Context context, Writer writer) throws IOException { - // NOP - } - - @Override - public void noHits(Context context, Writer writer) throws IOException { - // NOP - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java deleted file mode 100644 index f86d76a12a4..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.templates.test; - -import com.google.common.util.concurrent.MoreExecutors; -import com.yahoo.component.chain.Chain; -import com.yahoo.io.IOUtils; -import com.yahoo.language.Linguistics; -import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.prelude.hitfield.XMLString; -import com.yahoo.prelude.templates.SearchRendererAdaptor; -import com.yahoo.prelude.templates.TiledTemplateSet; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.Searcher; -import com.yahoo.search.federation.http.HTTPProviderSearcher; -import com.yahoo.search.rendering.RendererRegistry; -import com.yahoo.search.result.Hit; -import com.yahoo.search.result.HitGroup; -import com.yahoo.search.searchchain.Execution; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Tests representing a federated and grouped result as a Result object and - * rendering a tiled output of the result - * - * @author bratseth - */ -@SuppressWarnings("deprecation") -public class TilingTestCase { - - /** - * This result contains two blocks (center and right). - * The center block contains multiple subblocks while the right one contains a single block of ads. - */ - @Test - public void testTiling() throws IOException { - Chain<Searcher> chain=new Chain<>("tiling", new TiledResultProducer()); - - // Query it - Query query = new Query("/tiled?query=foo"); - Result result = callSearchAndSetRenderer(chain, query); - assertRendered(IOUtils.readFile(new File("src/test/java/com/yahoo/prelude/templates/test/tilingexample.xml")),result); - } - - /** - * This result contains center section and meta blocks. - */ - @Test - public void testTiling2() throws IOException { - Chain<Searcher> chain= new Chain<>("tiling", new TiledResultProducer2()); - - // Query it - Query query=new Query("/tiled?query=foo"); - Result result= callSearchAndSetRenderer(chain, query); - assertRendered(IOUtils.readFile(new File("src/test/java/com/yahoo/prelude/templates/test/tilingexample2.xml")),result); - } - - private Result callSearchAndSetRenderer(Chain<Searcher> chain, Query query) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); - Result result = new Execution(chain, context).search(query); - result.getTemplating().setRenderer(new SearchRendererAdaptor(new TiledTemplateSet())); - return result; - } - - public static void assertRenderedStartsWith(String expected,Result result) throws IOException { - assertRendered(expected,result,false); - } - - public static void assertRendered(String expected,Result result) throws IOException { - assertRendered(expected,result,true); - } - - public static void assertRendered(String expected, Result result,boolean checkFullEquality) throws IOException { - if (checkFullEquality) - assertEquals(filterComments(expected), getRendered(result)); - else - assertTrue(getRendered(result).startsWith(expected)); - } - - private static String filterComments(String s) { - StringBuilder b = new StringBuilder(); - for (String line : s.split("\\\n")) - if ( ! line.startsWith("<!--")) - b.append(line).append("\n"); - return b.toString(); - } - - public static String getRendered(Result result) throws IOException { - if (result.getTemplating().getRenderer() == null) - result.getTemplating().setTemplates(null); - - // Done in a roundabout way to simulate production code path - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - Charset cs = Charset.forName(result.getTemplating().getRenderer().getEncoding()); - CharsetDecoder decoder = cs.newDecoder(); - SearchRendererAdaptor.callRender(stream, result); - stream.flush(); - return decoder.decode(ByteBuffer.wrap(stream.toByteArray())).toString(); - } - - private static class TiledResultProducer extends Searcher { - - @Override - public Result search(Query query, Execution execution) { - Result result = new Result(query); - result.setTotalHitCount(2800000000l); - - // Blocks - HitGroup centerBlock=(HitGroup)result.hits().add(new HitGroup("section:center")); - centerBlock.types().add("section"); - centerBlock.setField("region","center"); - - HitGroup rightBlock=(HitGroup)result.hits().add(new HitGroup("section:right")); - rightBlock.types().add("section"); - rightBlock.setField("region","right"); - - // Center groups - HitGroup navigation=(HitGroup)centerBlock.add(new HitGroup("group:navigation",1.0)); - navigation.types().add("group"); - navigation.setField("type","navigation"); - - HitGroup adsNorth=(HitGroup)centerBlock.add(new HitGroup("group:ads:north",0.9)); - adsNorth.types().add("group"); - adsNorth.setField("type","ads"); - - HitGroup hits=(HitGroup)centerBlock.add(new HitGroup("group:navigation",0.8)); - hits.types().add("group"); - hits.setField("type","hits"); - - HitGroup adsSouth=(HitGroup)centerBlock.add(new HitGroup("group:ads:south",0.7)); - adsSouth.types().add("group"); - adsSouth.setField("type","ads"); - - // Right group - HitGroup adsRight=(HitGroup)rightBlock.add(new HitGroup("group:ads:right",0.7)); - adsRight.types().add("group"); - adsRight.setField("type","ads"); - - // Navigation content - /* - Hit alsoTry=navigation.add(new Hit("alsotry")); - alsoTry.types().add("alsotry"); - alsoTry.setMeta(true); - LinkList links=new LinkList(); - links.add(new Link("Hilton","?search=Hilton hotel")); - links.add(new Link("Habbo hotel","?search=Habbo hotel")); - links.add(new Link("Marriott","?search=Marriott hotel")); - alsoTry.setField("links",links); - */ - - // North ads content - Hit ad1=adsNorth.add(new Hit("http://www.hotels.com",0.7)); - ad1.types().add("ad"); - ad1.setAuxiliary(true); - ad1.setField("title",new XMLString("Cheap <hi>hotels</hi>")); - ad1.setField("body",new XMLString("Low Rates Guaranteed. Call a <hi>Hotel</hi> Expert.")); - - Hit ad2=adsNorth.add(new Hit("http://www.expedia.com",0.6)); - ad2.types().add("ad"); - ad2.setAuxiliary(true); - ad2.setField("title",new XMLString("Cheap <hi>hotels</hi> at Expedia")); - ad2.setField("body","Expedia Special Rates Means We Guarantee Our Low Rates on Rooms."); - -// // Hits content -// // - news hit -// HitGroup news1=(HitGroup)hits.add(new HitGroup("newsarticles",0.9)); -// news1.setMeta(false); -// news1.types().add("news"); -// news1.setField("title","Hotel - News results"); -// Hit article1=news1.add(new Hit("www.miamiherald.com/?article=jhsgd7323",0.5)); -// article1.setAuxiliary(true); -// article1.setField("title","Celebrity blackout: The Hilton of Paris changes name to regain search traffic"); -// article1.types().add("newsarticle"); -// article1.setField("age",23); -// article1.setField("source","Miami Herald"); -// Hit article2=news1.add(new Hit("www.sfgate.com/?article=8763khj7",0.4)); -// article2.setAuxiliary(true); -// article2.setField("title","Hotels - more expensive than staying at home"); -// article2.types().add("newsarticle"); -// article2.setField("age",3500); -// article2.setField("source","SF Gate"); - - // - collapsed hit - Hit hit1=hits.add(new Hit("www.hotels.com",0.8)); - hit1.types().add("hit.collapsed"); - hit1.setField("title","Hotels.com | Cheap Hotels | Discount Hotel Rooms | Motels | Lodging"); - hit1.setField("body",new XMLString("Hotels.com helps you find great rates on hotels and discount <hi>hotel</hi> packages.")); - /* - LinkList collapsed1=new LinkList(); - collapsed1.add(new Link("Last Minute Deals","www.hotels.com/lastminutedeals")); - collapsed1.add(new Link("Hotel Savings","www.hotels.com/deals")); - collapsed1.add(new Link("800-994-6835","www.hotels.com/?PSRC=OT2")); - hit1.setField("links",collapsed1); - */ - - // regular hit with links - Hit hit2=hits.add(new Hit("www.indigohotels.com",0.7)); - hit2.types().add("hit"); - hit2.setField("title","Hotel Indigo Hotels United States - Official Web Site"); - hit2.setField("body","Make Hotel Indigo online hotel reservations and book your hotel rooms today."); - /* - LinkList collapsed2=new LinkList(); - collapsed2.add(new Link("800-333-6835","www.indigohotels.com/order")); - collapsed2.add(new Link("Reservations","www.indigohotels.com/reservations")); - hit2.setField("links",collapsed2); - */ - - // boring old hit - Hit hit3=hits.add(new Hit("www.all-hotels.com",0.6)); - hit3.types().add("hit"); - hit3.setField("title","All hotels"); - hit3.setField("body","Online hotel directory and reservations."); - - // South ads - Hit southAd1=adsSouth.add(new Hit("www.daysinn.com",1.0)); - southAd1.types().add("ad"); - southAd1.setAuxiliary(true); - southAd1.setField("title","Days Inn Special Deal"); - southAd1.setField("body","Buy now and Save 15% Off Our Best Available Rate with Days Inn."); - Hit southAd2=adsSouth.add(new Hit("http://www.expedia.com",0.9)); - southAd2.types().add("ad"); - southAd2.setAuxiliary(true); - southAd2.setField("title",new XMLString("Cheap <hi>hotels</hi> at Expedia")); - southAd2.setField("body","Expedia Special Rates Means We Guarantee Our Low Rates on Rooms."); - - // Right ads - Hit rightAd1=adsRight.add(new Hit("www.daysinn.com",1.0)); - rightAd1.types().add("ad"); - rightAd1.setAuxiliary(true); - rightAd1.setField("title","Days Inn Special Deal"); - rightAd1.setField("body","Buy now and Save 15% Off Our Best Available Rate with Days Inn."); - Hit rightAd2=adsRight.add(new Hit("www.holidayinn.com",0.9)); - rightAd2.types().add("ad"); - rightAd2.setAuxiliary(true); - rightAd2.setField("title","Holiday Inn: Official Site"); - rightAd2.setField("body","Book with Holiday Inn. Free Internet. Kids eat free."); - - // Done creating result - must analyze because we add ads then later set them as auxiliary - result.analyzeHits(); - - return result; - } - - } - - private static class TiledResultProducer2 extends Searcher { - - @Override - public Result search(Query query,Execution execution) { - Result result=new Result(query); - result.setTotalHitCount(1); - - HitGroup section = new HitGroup("section:center"); - result.hits().add(section); - section.setMeta(false); - section.types().add("section"); - section.setField("region", "center"); - - HitGroup yst = new HitGroup("yst"); - section.add(yst); - yst.setMeta(false); - yst.setSource("sr"); - yst.types().add("sr"); - yst.setField("provider", "yst"); - - Hit theHit = new Hit("159"); - yst.add(theHit); - theHit.setSource("sr"); - theHit.types().add("sr"); - theHit.setField("provider", "yst"); - theHit.setField("title", "Yahoo"); - - HitGroup meta = new HitGroup("meta"); - result.hits().add(meta); - meta.types().add("meta"); - - Hit log = new Hit("com.yahoo.search.federation.yst.YSTBackendSearcherproxy-tw1cache.idp.inktomisearch.com55556/search"); - meta.add(log); - log.setMeta(true); - log.setSource("sr"); - log.setField("provider", "yst"); - log.types().add("logging"); - log.setField(HTTPProviderSearcher.LOG_URI, "http://proxy-tw1cache.idp.inktomisearch.com:55556/search?qp=yahootw-twp&Fields=url%2Credirecturl%2Cdate%2Csize%2Cformat%2Csms_product%2Ccacheurl%2Cnodename%2Cid%2Clanguage%2Crsslinks%2Crssvalidatedlinks%2Ccpc%2Cclustertype%2Cxml.active_abstract%2Cactive_abstract_type%2Cactive_abstract_source%2Ccontract_id%2Ctranslated%2Cxml.ydir_tw_hotlist_data%2Cxml.summary%2Cclustercollision%2Cxml.pi_info%2Cpage_adult_overridable%2Cpage_spam_overridable%2Ccategory_ydir%2Chate_edb&Unique=doc%2Chost+2&QueryEncoding=utf-8&Query=ALLWORDS%28yahoo%29&Database=dewownrm-zh-tw&FirstResult=0&srcpvid=&cacheecho=1&ResultsEncoding=utf-8&QueryLanguage=Chinese-traditional&Region=US&NumResults=10&Client=yahoous2"); - log.setField(HTTPProviderSearcher.LOG_SCHEME, "http"); - log.setField(HTTPProviderSearcher.LOG_HOST, "proxy-tw1cache.idp.inktomisearch.com"); - log.setField(HTTPProviderSearcher.LOG_PORT, "55556"); - log.setField(HTTPProviderSearcher.LOG_PATH, "/search"); - log.setField(HTTPProviderSearcher.LOG_STATUS, "200"); - log.setField(HTTPProviderSearcher.LOG_LATENCY_CONNECT, "757"); - log.setField(HTTPProviderSearcher.LOG_RESPONSE_HEADER_PREFIX + "content-length", "16217"); - - result.analyzeHits(); - - return result; - } - - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/error.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/error.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/error.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/footer.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/footer.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/footer.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/header.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/header.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/header.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/hit.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/hit.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/hit.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/nohits.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/nohits.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/asearch/nohits.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/error.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/error.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/error.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/footer.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/footer.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/footer.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/header.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/header.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/header.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/hit.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/hit.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/hit.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/nohits.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/nohits.templ deleted file mode 100644 index 4e7a9379b73..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/cgi-bin/asearch/nohits.templ +++ /dev/null @@ -1 +0,0 @@ -### Result diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/error.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/error.templ deleted file mode 100644 index ca186b86259..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/error.templ +++ /dev/null @@ -1 +0,0 @@ -<ERROR CODE="$result.error.code">$result.error.message</ERROR> diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/footer.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/footer.templ deleted file mode 100644 index 07a5dd6a881..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/footer.templ +++ /dev/null @@ -1 +0,0 @@ -</RESULTSET>
\ No newline at end of file diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/header.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/header.templ deleted file mode 100644 index 8e3a001545d..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/header.templ +++ /dev/null @@ -1,2 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<RESULTSET TOTALHITS="$result.totalHitCount"> diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/hit.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/hit.templ deleted file mode 100644 index 428a2f15ef5..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/hit.templ +++ /dev/null @@ -1,5 +0,0 @@ -<XTEMPLATEHIT RELEVANCY="$relevancy" SOURCE="$hit.source" TYPE="$hit.typeString" OFFSET="$hitno"> -<FIELD NAME="uri">$uri</FIELD> -<FIELD NAME="category">$category</FIELD> -<FIELD NAME="bsumtitle">$bsumtitle</FIELD> -</XTEMPLATEHIT> diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/nohits.templ b/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/nohits.templ deleted file mode 100644 index d466f0bb7d2..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/templates/xsearch/nohits.templ +++ /dev/null @@ -1 +0,0 @@ -<XTEMPLATENOHITS/>
\ No newline at end of file diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/tilingexample.xml b/container-search/src/test/java/com/yahoo/prelude/templates/test/tilingexample.xml deleted file mode 100644 index ea5d56d2b31..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/tilingexample.xml +++ /dev/null @@ -1,65 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<result version="1.0"> - - <section id="section:center" region="center"> - <group type="navigation" relevance="1.0"></group> - <group type="ads" relevance="0.9"> - <hit type="ad" relevance="0.7"> - <id>http://www.hotels.com/</id> - <title>Cheap <hi>hotels</hi></title> - <body>Low Rates Guaranteed. Call a <hi>Hotel</hi> Expert.</body> - </hit> - <hit type="ad" relevance="0.6"> - <id>http://www.expedia.com/</id> - <title>Cheap <hi>hotels</hi> at Expedia</title> - <body>Expedia Special Rates Means We Guarantee Our Low Rates on Rooms.</body> - </hit> - </group> - <group type="hits" relevance="0.8"> - <hit type="hit.collapsed" relevance="0.8"> - <id>www.hotels.com</id> - <title>Hotels.com | Cheap Hotels | Discount Hotel Rooms | Motels | Lodging</title> - <body>Hotels.com helps you find great rates on hotels and discount <hi>hotel</hi> packages.</body> - </hit> - <hit type="hit" relevance="0.7"> - <id>www.indigohotels.com</id> - <title>Hotel Indigo Hotels United States - Official Web Site</title> - <body>Make Hotel Indigo online hotel reservations and book your hotel rooms today.</body> - </hit> - <hit type="hit" relevance="0.6"> - <id>www.all-hotels.com</id> - <title>All hotels</title> - <body>Online hotel directory and reservations.</body> - </hit> - </group> - <group type="ads" relevance="0.7"> - <hit type="ad" relevance="1.0"> - <id>www.daysinn.com</id> - <title>Days Inn Special Deal</title> - <body>Buy now and Save 15% Off Our Best Available Rate with Days Inn.</body> - </hit> - <hit type="ad" relevance="0.9"> - <id>http://www.expedia.com/</id> - <title>Cheap <hi>hotels</hi> at Expedia</title> - <body>Expedia Special Rates Means We Guarantee Our Low Rates on Rooms.</body> - </hit> - </group> - </section> - - <section id="section:right" region="right"> - <group type="ads" relevance="0.7"> - <hit type="ad" relevance="1.0"> - <id>www.daysinn.com</id> - <title>Days Inn Special Deal</title> - <body>Buy now and Save 15% Off Our Best Available Rate with Days Inn.</body> - </hit> - <hit type="ad" relevance="0.9"> - <id>www.holidayinn.com</id> - <title>Holiday Inn: Official Site</title> - <body>Book with Holiday Inn. Free Internet. Kids eat free.</body> - </hit> - </group> - </section> - -</result> diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/tilingexample2.xml b/container-search/src/test/java/com/yahoo/prelude/templates/test/tilingexample2.xml deleted file mode 100644 index 2e936b0015a..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/tilingexample2.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<result version="1.0"> - - <section id="section:center" region="center"> - <group type="sr" relevance="1.0" source="sr" provider="yst"> - <hit type="sr" relevance="1.0" source="sr" provider="yst"> - <id>159</id> - <title>Yahoo</title> - </hit> - </group> - </section> - - <meta> - <provider name="yst" scheme="http" host="proxy-tw1cache.idp.inktomisearch.com" port="55556" path="/search" result="200"> - <id>com.yahoo.search.federation.yst.YSTBackendSearcherproxy-tw1cache.idp.inktomisearch.com55556/search</id> - <uri>http://proxy-tw1cache.idp.inktomisearch.com:55556/search?qp=yahootw-twp&Fields=url%2Credirecturl%2Cdate%2Csize%2Cformat%2Csms_product%2Ccacheurl%2Cnodename%2Cid%2Clanguage%2Crsslinks%2Crssvalidatedlinks%2Ccpc%2Cclustertype%2Cxml.active_abstract%2Cactive_abstract_type%2Cactive_abstract_source%2Ccontract_id%2Ctranslated%2Cxml.ydir_tw_hotlist_data%2Cxml.summary%2Cclustercollision%2Cxml.pi_info%2Cpage_adult_overridable%2Cpage_spam_overridable%2Ccategory_ydir%2Chate_edb&Unique=doc%2Chost+2&QueryEncoding=utf-8&Query=ALLWORDS%28yahoo%29&Database=dewownrm-zh-tw&FirstResult=0&srcpvid=&cacheecho=1&ResultsEncoding=utf-8&QueryLanguage=Chinese-traditional&Region=US&NumResults=10&Client=yahoous2</uri> - <latency type="connect">757</latency> - <response-header name="content-length">16217</response-header> - </provider> - </meta> - -</result> diff --git a/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java deleted file mode 100644 index 3e57c48e7f3..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.test; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.google.common.util.concurrent.MoreExecutors; -import com.yahoo.component.chain.Chain; -import com.yahoo.language.Linguistics; -import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.prelude.templates.test.TilingTestCase; -import com.yahoo.search.rendering.RendererRegistry; -import com.yahoo.search.result.Hit; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.prelude.fastsearch.FastHit; -import com.yahoo.search.Searcher; -import com.yahoo.search.searchchain.Execution; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -/** - * Tests that rank features are rendered when requested in the query - * - * @author bratseth - */ -@SuppressWarnings("deprecation") -public class RankFeatureDumpTestCase { - - private static final String rankFeatureString= - "{\"match.weight.as1\":10,\"attribute(ai1)\":1.000000,\"proximity(as1, 1, 2)\":2.000000}"; - - @Test - public void test() throws IOException { - Query query=new Query("?query=five&rankfeatures"); - assertTrue(query.getRanking().getListFeatures()); // New api - Result result = doSearch(new MockBackend(), query, 0,10); - assertTrue(TilingTestCase.getRendered(result).contains( - "<field name=\"" + com.yahoo.search.result.Hit.RANKFEATURES_FIELD + "\">" + rankFeatureString + "</field>")); - } - - private static class MockBackend extends Searcher { - - @Override - public Result search(com.yahoo.search.Query query, Execution execution) { - Result result=new Result(query); - Hit hit=new FastHit("test",1000); - hit.setField(com.yahoo.search.result.Hit.RANKFEATURES_FIELD,rankFeatureString); - result.hits().add(hit); - return result; - } - - } - - private Result doSearch(Searcher searcher, Query query, int offset, int hits) { - query.setOffset(offset); - query.setHits(hits); - return createExecution(searcher).search(query); - } - - private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); - return new Execution(chainedAsSearchChain(searcher), context); - } - - private Chain<Searcher> chainedAsSearchChain(Searcher topOfChain) { - List<Searcher> searchers = new ArrayList<>(); - searchers.add(topOfChain); - return new Chain<>(searchers); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/GzipDecompressingEntityTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/GzipDecompressingEntityTestCase.java deleted file mode 100644 index 6babba5a36a..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/GzipDecompressingEntityTestCase.java +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.http; - -import static org.junit.Assert.*; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.Random; -import java.util.zip.GZIPOutputStream; - -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.message.BasicHeader; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.yahoo.text.Utf8; - -/** - * Test GZip support for the HTTP integration introduced in 4.2. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class GzipDecompressingEntityTestCase { - private static final String STREAM_CONTENT = "00000000000000000000000000000000000000000000000000"; - private static final byte[] CONTENT_AS_BYTES = Utf8.toBytes(STREAM_CONTENT); - GzipDecompressingEntity testEntity; - - private static final class MockEntity implements HttpEntity { - - private final InputStream inStream; - - MockEntity(InputStream is) { - inStream = is; - } - - @Override - public boolean isRepeatable() { - return false; - } - - @Override - public boolean isChunked() { - return false; - } - - @Override - public long getContentLength() { - return -1; - } - - @Override - public Header getContentType() { - return new BasicHeader("Content-Type", "text/plain"); - } - - @Override - public Header getContentEncoding() { - return new BasicHeader("Content-Encoding", "gzip"); - } - - @Override - public InputStream getContent() throws IOException, - IllegalStateException { - return inStream; - } - - @Override - public void writeTo(OutputStream outstream) throws IOException { - } - - @Override - public boolean isStreaming() { - return false; - } - - @Override - public void consumeContent() throws IOException { - } - } - - @Before - public void setUp() throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - GZIPOutputStream gzip = new GZIPOutputStream(out); - gzip.write(CONTENT_AS_BYTES); - gzip.finish(); - gzip.close(); - byte[] compressed = out.toByteArray(); - InputStream inStream = new ByteArrayInputStream(compressed); - testEntity = new GzipDecompressingEntity(new MockEntity(inStream)); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public final void testGetContentLength() throws UnknownHostException { - assertEquals(STREAM_CONTENT.length(), testEntity.getContentLength()); - } - - @Test - public final void testGetContent() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length]; - int read = in.read(buffer); - assertEquals(CONTENT_AS_BYTES.length, read); - assertArrayEquals(CONTENT_AS_BYTES, buffer); - } - - @Test - public final void testGetContentToBigArray() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length * 2]; - in.read(buffer); - byte[] expected = Arrays.copyOf(CONTENT_AS_BYTES, CONTENT_AS_BYTES.length * 2); - assertArrayEquals(expected, buffer); - } - - @Test - public final void testGetContentAvailable() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - assertEquals(CONTENT_AS_BYTES.length, in.available()); - } - - @Test - public final void testLargeZip() throws IOException { - byte [] input = new byte [10000000]; - Random random = new Random(89); - for (int i = 0; i < input.length; i++) { - input[i] = (byte) random.nextInt(); - } - ByteArrayOutputStream out = new ByteArrayOutputStream(); - GZIPOutputStream gzip = new GZIPOutputStream(out); - gzip.write(input); - gzip.finish(); - gzip.close(); - byte[] compressed = out.toByteArray(); - assertEquals(10003073, compressed.length); - InputStream inStream = new ByteArrayInputStream(compressed); - GzipDecompressingEntity gunzipper = new GzipDecompressingEntity(new MockEntity(inStream)); - assertEquals(input.length, gunzipper.getContentLength()); - byte[] buffer = new byte[input.length]; - InputStream content = gunzipper.getContent(); - assertEquals(input.length, content.available()); - int read = content.read(buffer); - assertEquals(input.length, read); - assertArrayEquals(input, buffer); - } - - @Test - public final void testGetContentReadByte() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length * 2]; - int i = 0; - while (i < buffer.length) { - int r = in.read(); - if (r == -1) { - break; - } else { - buffer[i++] = (byte) r; - } - } - byte[] expected = Arrays.copyOf(CONTENT_AS_BYTES, CONTENT_AS_BYTES.length * 2); - assertEquals(CONTENT_AS_BYTES.length, i); - assertArrayEquals(expected, buffer); - } - - @Test - public final void testGetContentReadWithOffset() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length * 2]; - int read = in.read(buffer, CONTENT_AS_BYTES.length, CONTENT_AS_BYTES.length); - assertEquals(CONTENT_AS_BYTES.length, read); - byte[] expected = new byte[CONTENT_AS_BYTES.length * 2]; - for (int i = 0; i < CONTENT_AS_BYTES.length; ++i) { - expected[CONTENT_AS_BYTES.length + i] = CONTENT_AS_BYTES[i]; - } - assertArrayEquals(expected, buffer); - read = in.read(buffer, 0, CONTENT_AS_BYTES.length); - assertEquals(-1, read); - } - - @Test - public final void testGetContentSkip() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - final long n = 5L; - long skipped = in.skip(n); - assertEquals(n, skipped); - int read = in.read(); - assertEquals(CONTENT_AS_BYTES[(int) n], read); - skipped = in.skip(5000); - assertEquals(CONTENT_AS_BYTES.length - n - 1, skipped); - assertEquals(-1L, in.skip(1L)); - } - - - @Test - public final void testWriteToOutputStream() throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - testEntity.writeTo(out); - assertArrayEquals(CONTENT_AS_BYTES, out.toByteArray()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpParametersTest.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpParametersTest.java deleted file mode 100644 index 11f5d7d14fd..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpParametersTest.java +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.http; - -import com.yahoo.search.federation.ProviderConfig; -import org.junit.Test; - -import static com.yahoo.search.federation.ProviderConfig.Yca; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -/** - * @author gjoranv - * @author Steinar Knutsen - */ -public class HttpParametersTest { - - @Test - public void create_from_config() throws Exception { - ProviderConfig config = new ProviderConfig(new ProviderConfig.Builder() - .connectionTimeout(1.0) - .maxConnectionPerRoute(2) - .maxConnections(3) - .path("myPath") - .readTimeout(4) - .socketBufferBytes(5) - .yca(new Yca.Builder() - .applicationId("myId") - .host("myYcaHost") - .port(7) - .retry(8) - .ttl(9) - .useProxy(true))); - - HTTPParameters httpParameters = new HTTPParameters(config); - - // Written to configuredConnectionTimeout, but it is not accessible!? - //assertThat(httpParameters.getConnectionTimeout(), is(1000)); - - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getMaxConnectionsPerRoute(), is(2)); - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getMaxTotalConnections(), is(3)); - - assertThat(httpParameters.getPath(), is("/myPath")); - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getReadTimeout(), is(4)); - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getSocketBufferSizeBytes(), is(5)); - - - assertThat(httpParameters.getYcaUseProxy(), is(true)); - assertThat(httpParameters.getYcaApplicationId(), is("myId")); - assertThat(httpParameters.getYcaProxy(), is("myYcaHost")); - assertThat(httpParameters.getYcaPort(), is(7)); - assertThat(httpParameters.getYcaRetry(), is(8000L)); - assertThat(httpParameters.getYcaTtl(), is(9000L)); - } - - @Test - public void requireFreezeWorksForAccessors() { - HTTPParameters p = new HTTPParameters(); - boolean caught = false; - final int expected = 37; - p.setConnectionTimeout(expected); - assertEquals(expected, p.getConnectionTimeout()); - p.freeze(); - try { - p.setConnectionTimeout(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setReadTimeout(expected); - assertEquals(expected, p.getReadTimeout()); - p.freeze(); - try { - p.setReadTimeout(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setPersistentConnections(true); - assertTrue(p.getPersistentConnections()); - p.freeze(); - try { - p.setPersistentConnections(false); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - assertEquals("http", p.getProxyType()); - - p = new HTTPParameters(); - caught = false; - p.setEnableProxy(true); - assertTrue(p.getEnableProxy()); - p.freeze(); - try { - p.setEnableProxy(false); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setProxyHost("nalle"); - assertEquals("nalle", p.getProxyHost()); - p.freeze(); - try { - p.setProxyHost("jappe"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setProxyPort(expected); - assertEquals(expected, p.getProxyPort()); - p.freeze(); - try { - p.setProxyPort(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setMethod("POST"); - assertEquals("POST", p.getMethod()); - p.freeze(); - try { - p.setMethod("GET"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setSchema("gopher"); - assertEquals("gopher", p.getSchema()); - p.freeze(); - try { - p.setSchema("http"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setInputEncoding("iso-8859-15"); - assertEquals("iso-8859-15", p.getInputEncoding()); - p.freeze(); - try { - p.setInputEncoding("shift-jis"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setOutputEncoding("iso-8859-15"); - assertEquals("iso-8859-15", p.getOutputEncoding()); - p.freeze(); - try { - p.setOutputEncoding("shift-jis"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setMaxTotalConnections(expected); - assertEquals(expected, p.getMaxTotalConnections()); - p.freeze(); - try { - p.setMaxTotalConnections(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setMaxConnectionsPerRoute(expected); - assertEquals(expected, p.getMaxConnectionsPerRoute()); - p.freeze(); - try { - p.setMaxConnectionsPerRoute(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setSocketBufferSizeBytes(expected); - assertEquals(expected, p.getSocketBufferSizeBytes()); - p.freeze(); - try { - p.setSocketBufferSizeBytes(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setRetries(expected); - assertEquals(expected, p.getRetries()); - p.freeze(); - try { - p.setRetries(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - } -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpPostTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpPostTestCase.java deleted file mode 100644 index e0b2afe4e1f..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpPostTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.StupidSingleThreadedHttpServer; -import com.yahoo.search.federation.ProviderConfig.PingOption; -import com.yahoo.search.federation.http.Connection; -import com.yahoo.search.federation.http.HTTPProviderSearcher; -import com.yahoo.search.result.Hit; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.StringEntity; -import org.junit.Test; - -import java.io.InputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; - -/** - * See bug #3234696. - * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - */ -public class HttpPostTestCase { - - @Test - public void testPostingSearcher() throws Exception { - StupidSingleThreadedHttpServer server = new StupidSingleThreadedHttpServer(); - server.start(); - - TestPostSearcher searcher = new TestPostSearcher(new ComponentId("foo:1"), - Arrays.asList(new Connection("localhost", server.getServerPort())), - "/"); - Query q = new Query(""); - q.setTimeout(10000000L); - Execution e = new Execution(searcher, Execution.Context.createContextStub()); - - searcher.search(q, e); - - assertThat(server.getRequest(), containsString("My POST body")); - server.stop(); - } - - private static class TestPostSearcher extends HTTPProviderSearcher { - public TestPostSearcher(ComponentId id, List<Connection> connections, String path) { - super(id, connections, httpParameters(path), Statistics.nullImplementation); - } - - private static HTTPParameters httpParameters(String path) { - HTTPParameters httpParameters = new HTTPParameters(path); - httpParameters.setPingOption(PingOption.Enum.DISABLE); - return httpParameters; - } - - @Override - protected HttpUriRequest createRequest(String method, URI uri, HttpEntity entity) { - HttpPost request = new HttpPost(uri); - request.setEntity(entity); - return request; - } - - @Override - protected HttpEntity getRequestEntity(Query query, Hit requestMeta) { - try { - return new StringEntity("My POST body"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return new HashMap<>(0); - } - - @Override - public void unmarshal(final InputStream stream, long contentLength, final Result result) throws IOException { - // do nothing with the result - } - - @Override - protected void fill(Result result, String summaryClass, Execution execution, Connection connection) { - //Empty - } - } -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java deleted file mode 100644 index b4f3c13b8e2..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.StupidSingleThreadedHttpServer; -import com.yahoo.search.result.Hit; -import com.yahoo.search.result.HitGroup; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import com.yahoo.text.Utf8; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.xml.bind.JAXBException; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -/** - * Rudimentary http searcher test. - * - * @author bratseth - */ -public class HttpTestCase { - - private StupidSingleThreadedHttpServer httpServer; - private TestHTTPClientSearcher searcher; - - @Test - public void testSearcher() throws JAXBException { - Result result = searchUsingLocalhost(); - - assertEquals("ok", result.getQuery().properties().get("gotResponse")); - assertEquals(0, result.getQuery().errors().size()); - } - - private Result searchUsingLocalhost() { - searcher = new TestHTTPClientSearcher("test","localhost",getPort()); - Query query = new Query("/?query=test"); - - query.setWindow(0,10); - return searcher.search(query, new Execution(searcher, Execution.Context.createContextStub())); - } - - @Test - public void test_that_ip_address_set_on_meta_hit() { - Result result = searchUsingLocalhost(); - Hit metaHit = getFirstMetaHit(result.hits()); - String ip = (String) metaHit.getField(HTTPSearcher.LOG_IP_ADDRESS); - - assertEquals(ip, "127.0.0.1"); - } - - private Hit getFirstMetaHit(HitGroup hits) { - for (Iterator<Hit> i = hits.unorderedDeepIterator(); i.hasNext();) { - Hit hit = i.next(); - if (hit.isMeta()) - return hit; - } - return null; - } - - @Before - public void setUp() throws Exception { - httpServer = new StupidSingleThreadedHttpServer(0, 0) { - @Override - protected byte[] getResponse(String request) { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 5\r\n" + - "\r\n" + - "hello"); - } - }; - httpServer.start(); - } - - private int getPort() { - return httpServer.getServerPort(); - } - - @After - public void tearDown() throws Exception { - httpServer.stop(); - if (searcher != null) { - searcher.shutdownConnectionManagers(); - } - } - - private static class TestHTTPClientSearcher extends HTTPClientSearcher { - - public TestHTTPClientSearcher(String id, String hostName, int port) { - super(new ComponentId(id), toConnections(hostName,port), "", Statistics.nullImplementation); - } - - private static List<Connection> toConnections(String hostName,int port) { - List<Connection> connections=new ArrayList<>(); - connections.add(new Connection(hostName,port)); - return connections; - } - - @Override - public Query handleResponse(InputStream inputStream, long contentLength, Query query) throws IOException { - query.properties().set("gotResponse","ok"); - return query; - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return null; - } - - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java deleted file mode 100644 index 8c1ff69666b..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.prelude.Ping; -import com.yahoo.prelude.Pong; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.StupidSingleThreadedHttpServer; -import com.yahoo.search.result.ErrorMessage; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import com.yahoo.text.Utf8; -import com.yahoo.yolean.Exceptions; -import org.apache.http.HttpEntity; -import org.junit.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Check for different keep-alive scenarios. What we really want to test - * is the server does not hang. - * - * @author Steinar Knutsen - */ -public class PingTestCase { - - private static final int TIMEOUT_MS = 60000; - - @Test - public void testNiceCase() throws Exception { - NiceStupidServer server = new NiceStupidServer(); - server.start(); - checkSearchAndPing(true, true, true, server.getServerPort()); - server.stop(); - } - - private void checkSearchAndPing(boolean firstSearch, boolean pongCheck, boolean secondSearch, int port) { - String resultThing; - String comment; - TestHTTPClientSearcher searcher = new TestHTTPClientSearcher("test", - "localhost", port); - try { - - Query query = new Query("/?query=test"); - - query.setWindow(0, 10); - // high timeout to allow for overloaded test machine - query.setTimeout(TIMEOUT_MS); - Ping ping = new Ping(TIMEOUT_MS); - - long start = System.currentTimeMillis(); - Execution exe = new Execution(searcher, Execution.Context.createContextStub()); - exe.search(query); - - resultThing = firstSearch ? "ok" : null; - comment = firstSearch ? "First search should have succeeded." : "First search should fail."; - assertEquals(comment, resultThing, query.properties().get("gotResponse")); - Pong pong = searcher.ping(ping, searcher.getConnection()); - if (pongCheck) { - assertEquals("Ping should not have failed.", 0, pong.getErrorSize()); - } else { - assertEquals("Ping should have failed.", 1, pong.getErrorSize()); - } - exe = new Execution(searcher, Execution.Context.createContextStub()); - exe.search(query); - - resultThing = secondSearch ? "ok" : null; - comment = secondSearch ? "Second search should have succeeded." : "Second search should fail."; - - assertEquals(resultThing, query.properties().get("gotResponse")); - long duration = System.currentTimeMillis() - start; - // target for duration based on the timeout values + some slack - assertTrue("This test probably hanged.", duration < TIMEOUT_MS + 4000); - searcher.shutdownConnectionManagers(); - } finally { - searcher.deconstruct(); - } - } - - @Test - public void testUselessCase() throws Exception { - UselessStupidServer server = new UselessStupidServer(); - server.start(); - checkSearchAndPing(false, true, false, server.getServerPort()); - server.stop(); - } - - @Test - public void testGrumpyCase() throws Exception { - GrumpyStupidServer server = new GrumpyStupidServer(); - server.start(); - checkSearchAndPing(false, false, false, server.getServerPort()); - server.stop(); - } - - @Test - public void testPassiveAggressiveCase() throws Exception { - PassiveAggressiveStupidServer server = new PassiveAggressiveStupidServer(); - server.start(); - checkSearchAndPing(true, false, true, server.getServerPort()); - server.stop(); - } - - // OK on ping and search - private static class NiceStupidServer extends StupidSingleThreadedHttpServer { - private NiceStupidServer() throws IOException { - super(0, 0); - } - - @Override - protected byte[] getResponse(String request) { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 6\r\n" + - "\r\n" + - "hello\n"); - } - } - - // rejects ping and accepts search - private static class PassiveAggressiveStupidServer extends StupidSingleThreadedHttpServer { - - private PassiveAggressiveStupidServer() throws IOException { - super(0, 0); - } - - @Override - protected byte[] getResponse(String request) { - if (request.contains("/ping")) { - return Utf8.toBytes("HTTP/1.1 404 Not found\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 8\r\n" + - "\r\n" + - "go away\n"); - } else { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 6\r\n" + - "\r\n" + - "hello\n"); - } - } - } - - // accepts ping and rejects search - private static class UselessStupidServer extends StupidSingleThreadedHttpServer { - private UselessStupidServer() throws IOException { - super(0, 0); - } - - - @Override - protected byte[] getResponse(String request) { - if (request.contains("/ping")) { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 6\r\n" + - "\r\n" + - "hello\n"); - } else { - return Utf8.toBytes("HTTP/1.1 404 Not found\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 8\r\n" + - "\r\n" + - "go away\n"); - } - } - } - - // rejects ping and search - private static class GrumpyStupidServer extends StupidSingleThreadedHttpServer { - private GrumpyStupidServer() throws IOException { - super(0, 0); - } - - @Override - protected byte[] getResponse(String request) { - return Utf8.toBytes("HTTP/1.1 404 Not found\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 8\r\n" + - "\r\n" + - "go away\n"); - } - } - - private static class TestHTTPClientSearcher extends HTTPClientSearcher { - - public TestHTTPClientSearcher(String id, String hostName, int port) { - super(new ComponentId(id), toConnections(hostName,port), "", Statistics.nullImplementation); - } - - private static List<Connection> toConnections(String hostName,int port) { - List<Connection> connections=new ArrayList<>(); - connections.add(new Connection(hostName,port)); - return connections; - } - - @Override - public Query handleResponse(InputStream inputStream, long contentLength, Query query) throws IOException { - query.properties().set("gotResponse","ok"); - return query; - } - - @Override - public Result search(Query query, Execution execution, - Connection connection) { - URI uri; - try { - uri = new URL("http", connection.getHost(), connection - .getPort(), "/search").toURI(); - } catch (MalformedURLException e) { - query.errors().add(createMalformedUrlError(query, e)); - return execution.search(query); - } catch (URISyntaxException e) { - query.errors().add(createMalformedUrlError(query, e)); - return execution.search(query); - } - - HttpEntity entity; - try { - entity = getEntity(uri, query); - } catch (IOException e) { - query.errors().add( - ErrorMessage.createBackendCommunicationError("Error when trying to connect to HTTP backend in " - + this + " using " + connection - + " for " + query + ": " - + Exceptions.toMessageString(e))); - return execution.search(query); - } catch (TimeoutException e) { - query.errors().add(ErrorMessage.createTimeout("No time left for HTTP traffic in " - + this - + " for " + query + ": " + e.getMessage())); - return execution.search(query); - } - if (entity == null) { - query.errors().add( - ErrorMessage.createBackendCommunicationError("No result from connecting to HTTP backend in " - + this + " using " + connection + " for " + query)); - return execution.search(query); - } - - try { - query = handleResponse(entity, query); - } catch (IOException e) { - query.errors().add( - ErrorMessage.createBackendCommunicationError("Error when trying to consume input in " - + this + ": " + Exceptions.toMessageString(e))); - } finally { - cleanupHttpEntity(entity); - } - return execution.search(query); - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return null; - } - - @Override - protected URI getPingURI(Connection connection) - throws MalformedURLException, URISyntaxException { - return new URL("http", connection.getHost(), connection.getPort(), "/ping").toURI(); - } - - Connection getConnection() { - return getHasher().getNodes().select(0, 0); - } - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java deleted file mode 100644 index 19750cf84cc..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import com.yahoo.vespa.defaults.Defaults; -import org.junit.Test; - -import java.util.Collections; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -/** - * Tests that source and backend specific parameters from the query are added correctly to the backend requests - * - * @author bratseth - */ -public class QueryParametersTestCase { - - @Test - public void testQueryParameters() { - Query query=new Query(); - query.properties().set("a","a-value"); - query.properties().set("b.c","b.c-value"); - query.properties().set("source.otherSource.d","d-value"); - query.properties().set("source.testSource.e","e-value"); - query.properties().set("source.testSource.f.g","f.g-value"); - query.properties().set("provider.testProvider.h","h-value"); - query.properties().set("provider.testProvider.i.j","i.j-value"); - - query.properties().set("sourceName","testSource"); // Done by federation searcher - query.properties().set("providerName","testProvider"); // Done by federation searcher - - TestHttpProvider searcher=new TestHttpProvider(); - Map<String,String> parameters=searcher.getQueryMap(query); - searcher.deconstruct(); - - assertEquals(4,parameters.size()); // the appropriate 4 of the above - assertEquals(parameters.get("e"),"e-value"); - assertEquals(parameters.get("f.g"),"f.g-value"); - assertEquals(parameters.get("h"),"h-value"); - assertEquals(parameters.get("i.j"),"i.j-value"); - } - - public static class TestHttpProvider extends HTTPProviderSearcher { - - public TestHttpProvider() { - super(new ComponentId("test"), Collections.singletonList(new Connection("host", Defaults.getDefaults().vespaWebServicePort())), "path", Statistics.nullImplementation); - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return Collections.singletonMap("nocaching", String.valueOf(Math.random())); - } - - @Override - protected void fill(Result result, String summaryClass, Execution execution, Connection connection) { - } - - } - -} - diff --git a/container-search/src/test/java/com/yahoo/search/federation/image/.gitignore b/container-search/src/test/java/com/yahoo/search/federation/image/.gitignore deleted file mode 100644 index e69de29bb2d..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/image/.gitignore +++ /dev/null diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryMarshallerTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryMarshallerTestCase.java deleted file mode 100644 index 022177bc42b..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryMarshallerTestCase.java +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.vespa.test; - -import com.yahoo.language.Linguistics; -import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.prelude.IndexFacts; -import com.yahoo.prelude.query.*; -import com.yahoo.search.Query; -import com.yahoo.search.federation.vespa.QueryMarshaller; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class QueryMarshallerTestCase { - - private static final Linguistics linguistics = new SimpleLinguistics(); - - @Test - public void testCommonCommonCase() { - AndItem root = new AndItem(); - addThreeWords(root); - assertEquals("a AND b AND c", new QueryMarshaller().marshal(root)); - } - - @Test - public void testPhrase() { - PhraseItem root = new PhraseItem(); - root.setIndexName("habla"); - addThreeWords(root); - assertEquals("habla:\"a b c\"", new QueryMarshaller().marshal(root)); - } - - @Test - public void testPhraseDefaultIndex() { - PhraseItem root = new PhraseItem(); - addThreeWords(root); - assertEquals("\"a b c\"", new QueryMarshaller().marshal(root)); - } - - @Test - public void testLittleMoreComplex() { - AndItem root = new AndItem(); - addThreeWords(root); - OrItem ambig = new OrItem(); - root.addItem(ambig); - addThreeWords(ambig); - AndItem but = new AndItem(); - addThreeWords(but); - ambig.addItem(but); - assertEquals("a AND b AND c AND ( a OR b OR c OR ( a AND b AND c ) )", - new QueryMarshaller().marshal(root)); - } - - @Test - public void testRank() { - RankItem root = new RankItem(); - addThreeWords(root); - assertEquals("a RANK b RANK c", new QueryMarshaller().marshal(root)); - } - - @Test - public void testNear() { - NearItem near = new NearItem(3); - addThreeWords(near); - assertEquals("a NEAR(3) b NEAR(3) c", new QueryMarshaller().marshal(near)); - } - - @Test - public void testONear() { - ONearItem oNear = new ONearItem(3); - addThreeWords(oNear); - assertEquals("a ONEAR(3) b ONEAR(3) c", new QueryMarshaller().marshal(oNear)); - } - - private void addThreeWords(CompositeItem root) { - root.addItem(new WordItem("a")); - root.addItem(new WordItem("b")); - root.addItem(new WordItem("c")); - } - - @Test - public void testNegativeGroupedTerms() { - testQueryString(new QueryMarshaller(), "a -(b c) -(d e)", - "a ANDNOT ( b AND c ) ANDNOT ( d AND e )"); - } - - @Test - public void testPositiveGroupedTerms() { - testQueryString(new QueryMarshaller(), "a (b c)", "a AND ( b OR c )"); - } - - @Test - public void testInt() { - testQueryString(new QueryMarshaller(), "yahoo 123", "yahoo AND 123"); - } - - @Test - public void testCJKOneWord() { - testQueryString(new QueryMarshaller(), "天龍人"); - } - - @Test - public void testTwoWords() { - testQueryString(new QueryMarshaller(), "John Smith", "John AND Smith", null, new SimpleLinguistics()); - } - - @Test - public void testTwoWordsInPhrase() { - testQueryString(new QueryMarshaller(), "\"John Smith\"", "\"John Smith\"", null, new SimpleLinguistics()); - } - - @Test - public void testCJKTwoSentences() { - testQueryString(new QueryMarshaller(), "是不是這樣的夜晚 你才會這樣地想起我", "是不是這樣的夜晚 AND 你才會這樣地想起我"); - } - - @Test - public void testCJKTwoSentencesWithLanguage() { - testQueryString(new QueryMarshaller(), "助妳好孕 生1胎北市發2萬", "助妳好孕 AND 生1胎北市發2萬", "zh-Hant"); - } - - @Test - public void testCJKTwoSentencesInPhrase() { - QueryMarshaller marshaller = new QueryMarshaller(); - testQueryString(marshaller, "\"助妳好孕 生1胎北市發2萬\"", "\"助妳好孕 生1胎北市發2萬\"", "zh-Hant"); - testQueryString(marshaller, "\"是不是這樣的夜晚 你才會這樣地想起我\"", "\"是不是這樣的夜晚 你才會這樣地想起我\""); - } - - @Test - public void testCJKMultipleSentences() { - testQueryString(new QueryMarshaller(), "염부장님과 함께했던 좋은 추억들은", "염부장님과 AND 함께했던 AND 좋은 AND 추억들은"); - } - - @Test - public void testIndexRestriction() { - /** ticket 3707606, comment #29 */ - testQueryString(new QueryMarshaller(), "site:nytimes.com", "site:\"nytimes com\""); - } - - private void testQueryString(QueryMarshaller marshaller, String uq) { - testQueryString(marshaller, uq, uq, null); - } - - private void testQueryString(QueryMarshaller marshaller, String uq, String mq) { - testQueryString(marshaller, uq, mq, null); - } - - private void testQueryString(QueryMarshaller marshaller, String uq, String mq, String lang) { - testQueryString(marshaller, uq, mq, lang, linguistics); - } - - private void testQueryString(QueryMarshaller marshaller, String uq, String mq, String lang, Linguistics linguistics) { - Query query = new Query("/?query=" + QueryTestCase.httpEncode(uq) + ((lang != null) ? "&language=" + lang : "")); - query.getModel().setExecution(new Execution(new Execution.Context(null, new IndexFacts(), null, null, linguistics))); - assertEquals(mq, marshaller.marshal(query.getModel().getQueryTree().getRoot())); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java deleted file mode 100644 index 8d1ecf4085e..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.vespa.test; - -import com.yahoo.search.Query; -import com.yahoo.search.federation.vespa.VespaSearcher; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -/** - * Tests that source and backend specific parameters from the query are added correctly to the backend requests - * - * @author bratseth - */ -public class QueryParametersTestCase { - - public void testQueryParameters() { - Query query=new Query(); - query.properties().set("a","a-value"); - query.properties().set("b.c","b.c-value"); - query.properties().set("source.otherSource.d","d-value"); - query.properties().set("source.testSource.e","e-value"); - query.properties().set("source.testSource.f.g","f.g-value"); - query.properties().set("provider.testProvider.h","h-value"); - query.properties().set("provider.testProvider.i.j","i.j-value"); - - query.properties().set("sourceName","testSource"); // Done by federation searcher - query.properties().set("providerName","testProvider"); // Done by federation searcher - - VespaSearcher searcher=new VespaSearcher("testProvider","",0,""); - Map<String,String> parameters=searcher.getQueryMap(query); - searcher.deconstruct(); - - assertEquals(9, parameters.size()); // 5 standard + the appropriate 4 of the above - assertEquals(parameters.get("e"),"e-value"); - assertEquals(parameters.get("f.g"),"f.g-value"); - assertEquals(parameters.get("h"),"h-value"); - assertEquals(parameters.get("i.j"),"i.j-value"); - } - -} - diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java deleted file mode 100644 index 50186e03ae8..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.vespa.test; - -import java.util.Iterator; - -import com.yahoo.net.URI; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.federation.vespa.ResultBuilder; -import com.yahoo.search.result.ErrorHit; -import com.yahoo.search.result.ErrorMessage; -import com.yahoo.search.result.HitGroup; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * Test XML parsing of results. - * - * @author Steinar Knutsen - */ -@SuppressWarnings("deprecation") -public class ResultBuilderTestCase { - - private boolean quickCompare(double a, double b) { - double z = Math.min(Math.abs(a), Math.abs(b)); - if (Math.abs((a - b)) < (z / 1e14)) { - return true; - } else { - return false; - } - } - - @Test - public void testSimpleResult() { - boolean gotErrorDetails = false; - ResultBuilder r = new ResultBuilder(); - Result res = r.parse("file:src/test/java/com/yahoo/prelude/searcher/test/testhit.xml", new Query("?query=a")); - assertEquals(3, res.getConcreteHitCount()); - assertEquals(4, res.getHitCount()); - ErrorHit e = (ErrorHit) res.hits().get(0); - // known problem, if the same error is the main error is - // in details, it'll be added twice. Not sure how to fix that, - // because old Vespa systems give no error details, and there - // is no way of nuking an existing error if the details exist. - for (Iterator<?> i = e.errorIterator(); i.hasNext();) { - ErrorMessage err = (ErrorMessage) i.next(); - assertEquals(5, err.getCode()); - String details = err.getDetailedMessage(); - if (details != null) { - gotErrorDetails = true; - assertEquals("An error as ordered", details.trim()); - } - } - assertTrue("Error details are missing", gotErrorDetails); - assertEquals(new URI("http://def"), res.hits().get(1).getId()); - assertEquals("test/stuff\\tsome/other", res.hits().get(2).getField("category")); - assertEquals("<field>habla</field>" - + "<hi>blbl</hi><br /><>&fdlkkgj</field>;lk<a b=\"1\" c=\"2\" />" - + "<x><y><z /></y></x>", res.hits().get(3).getField("annoying").toString()); - } - - @Test - public void testNestedResult() { - ResultBuilder r = new ResultBuilder(); - Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml", new Query("?query=a")); - assertNull(res.hits().getError()); - assertEquals(3, res.hits().size()); - assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", res.hits().get(0).getField("guid").toString()); - HitGroup g1 = (HitGroup) res.hits().get(1); - HitGroup g2 = (HitGroup) res.hits().get(2); - assertEquals(15, g1.size()); - assertEquals("reward_for_thumb", g1.get(1).getField("id").toString()); - assertEquals(10, g2.size()); - HitGroup g3 = (HitGroup) g2.get(3); - assertEquals("badge", g3.types().iterator().next()); - assertEquals(2, g3.size()); - assertEquals("badge/Topic Explorer 5", g3.get(0).getField("name").toString()); - } - - @Test - public void testWeirdDocumentID() { - ResultBuilder r = new ResultBuilder(); - Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml", new Query("?query=a")); - assertNull(res.hits().getError()); - assertEquals(3, res.hits().size()); - assertEquals(new URI("nalle"), res.hits().get(0).getId()); - assertEquals(new URI("tralle"), res.hits().get(1).getId()); - assertEquals(new URI("kalle"), res.hits().get(2).getId()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java deleted file mode 100644 index 7fbe883bfb7..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.vespa.test; - -import com.yahoo.component.chain.Chain; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.Searcher; -import com.yahoo.search.federation.vespa.VespaSearcher; -import com.yahoo.search.searchchain.Execution; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author bratseth - */ -public class VespaIntegrationTestCase { - - // TODO: Setup the answering vespa searcher from this test.... - @Test - public void testIt() { - if (System.currentTimeMillis() > 0) return; - Chain<Searcher> chain = new Chain<>(new VespaSearcher("test","example.yahoo.com",19010,"")); - Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=test")); - assertEquals(23, result.hits().size()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java deleted file mode 100644 index cc00c6739fa..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.federation.vespa.test; - -import com.yahoo.prelude.query.*; -import com.yahoo.search.Query; -import com.yahoo.search.federation.vespa.VespaSearcher; -import com.yahoo.search.query.QueryTree; -import com.yahoo.search.query.parser.Parsable; -import com.yahoo.search.query.parser.Parser; -import com.yahoo.search.query.parser.ParserEnvironment; -import com.yahoo.search.query.parser.ParserFactory; -import com.yahoo.search.result.Hit; -import com.yahoo.search.searchchain.Execution; -import org.apache.http.HttpEntity; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.net.URI; - -import static org.junit.Assert.assertEquals; - -/** - * Check query marshaling in VespaSearcher works. - * - * @author Steinar Knutsen - */ -public class VespaSearcherTestCase { - - private VespaSearcher searcher; - - @Before - public void setUp() { - searcher = new VespaSearcher("cache1","",0,""); - } - - @After - public void tearDown() { - searcher.deconstruct(); - } - - @Test - public void testMarshalQuery() { - RankItem root = new RankItem(); - QueryTree r = new QueryTree(root); - AndItem recall = new AndItem(); - PhraseItem usual = new PhraseItem(); - PhraseItem filterPhrase = new PhraseItem(new String[] {"bloody", "expensive"}); - WordItem filterWord = new WordItem("silly"); - - filterPhrase.setFilter(true); - filterWord.setFilter(true); - - root.addItem(recall); - usual.addItem(new WordItem("new")); - usual.addItem(new WordItem("york")); - recall.addItem(usual); - recall.addItem(new WordItem("shoes")); - root.addItem(new WordItem("nike")); - root.addItem(new WordItem("adidas")); - root.addItem(filterPhrase); - recall.addItem(filterWord); - - assertEquals("( \"new york\" AND shoes AND silly ) RANK nike RANK adidas RANK \"bloody expensive\"", searcher.marshalQuery(r)); - } - - @Test - public void testMarshalQuerySmallTree() { - RankItem root = new RankItem(); - QueryTree r = new QueryTree(root); - AndItem recall = new AndItem(); - PhraseItem usual = new PhraseItem(); - PhraseItem filterPhrase = new PhraseItem(new String[] {"bloody", "expensive"}); - WordItem filterWord = new WordItem("silly"); - - filterPhrase.setFilter(true); - filterWord.setFilter(true); - - root.addItem(recall); - usual.addItem(new WordItem("new")); - usual.addItem(new WordItem("york")); - recall.addItem(usual); - recall.addItem(new WordItem("shoes")); - root.addItem(filterPhrase); - recall.addItem(filterWord); - - assertEquals("( \"new york\" AND shoes AND silly ) RANK \"bloody expensive\"", searcher.marshalQuery(r)); - // TODO: Switch to this 2-way check rather than just 1-way and then also make this actually treat filter terms correctly - // assertMarshals(root) - } - - @Test - public void testWandMarshalling() { - WeakAndItem root = new WeakAndItem(); - root.setN(32); - root.addItem(new WordItem("a")); - root.addItem(new WordItem("b")); - root.addItem(new WordItem("c")); - assertMarshals(root); - } - - @Test - public void testWandMarshalling2() { - // AND (WAND(10) a!1 the!10) source:yahoonews - AndItem root = new AndItem(); - WeakAndItem wand = new WeakAndItem(10); - wand.addItem(newWeightedWordItem("a",1)); - wand.addItem(newWeightedWordItem("the",10)); - root.addItem(wand); - root.addItem(new WordItem("yahoonews","source")); - assertMarshals(root); - } - - private WordItem newWeightedWordItem(String word,int weight) { - WordItem wordItem=new WordItem(word); - wordItem.setWeight(weight); - return wordItem; - } - - private void assertMarshals(Item root) { - QueryTree r = new QueryTree(root); - String marshalledQuery=searcher.marshalQuery(r); - assertEquals("Marshalled form '" + marshalledQuery + "' recreates the original", - r,parseQuery(marshalledQuery,"")); - } - - private static Item parseQuery(String query, String filter) { - Parser parser = ParserFactory.newInstance(Query.Type.ADVANCED, new ParserEnvironment()); - return parser.parse(new Parsable().setQuery(query).setFilter(filter)); - } - - @Test - public void testSourceProviderProperties() throws Exception { - /* TODO: update test - Server httpServer = new Server(); - try { - SocketConnector listener = new SocketConnector(); - listener.setHost("0.0.0.0"); - httpServer.addConnector(listener); - httpServer.setHandler(new DummyHandler()); - httpServer.start(); - - int port=httpServer.getConnectors()[0].getLocalPort(); - - List<SourcesConfig.Source> sourcesConfig = new ArrayList<SourcesConfig.Source>(); - SourcesConfig.Source sourceConfig = new SourcesConfig.Source(); - sourceConfig.chain.setValue("news"); - sourceConfig.provider.setValue("news"); - sourceConfig.id.setValue("news"); - sourceConfig.timelimit.value = 10000; - sourcesConfig.add(sourceConfig); - FederationSearcher federator = - new FederationSearcher(ComponentId.createAnonymousComponentId(), - new ArrayList<SourcesConfig.Source>(sourcesConfig)); - SearchChain mainChain=new OrderedSearchChain(federator); - - SearchChainRegistry registry=new SearchChainRegistry(); - SearchChain sourceChain=new SearchChain(new ComponentId("news"),new VespaSearcher("test","localhost",port,"")); - registry.register(sourceChain); - Query query=new Query("?query=hans&hits=20&provider.news.a=a1&source.news.b=b1"); - Result result=new Execution(mainChain,registry).search(query); - assertNull(result.hits().getError()); - Hit testHit=result.hits().get("testHit"); - assertNotNull(testHit); - assertEquals("testValue",testHit.fields().get("testField")); - assertEquals("a1",testHit.fields().get("a")); - assertEquals("b1",testHit.fields().get("b")); - } - finally { - httpServer.stop(); - } - */ - } - - @Test - public void testVespaSearcher() { - VespaSearcher v=new VespaSearcherValidatingSubclass(); - new Execution(v, Execution.Context.createContextStub()).search(new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&filter=myfilter"))); - } - - private class VespaSearcherValidatingSubclass extends VespaSearcher { - - public VespaSearcherValidatingSubclass() { - super("configId","host",80,"path"); - } - - @Override - protected HttpEntity getEntity(URI uri, Hit requestMeta, Query query) throws IOException { - assertEquals("http://host:80/path?query=test+RANK+myfilter&type=adv&offset=0&hits=10&presentation.format=xml",uri.toString()); - return super.getEntity(uri,requestMeta,query); - } - - } - - // used by the old testSourceProviderProperties() -// private class DummyHandler extends AbstractHandler { -// public void handle(String s, Request request, HttpServletRequest httpServletRequest, -// HttpServletResponse httpServletResponse) throws IOException, ServletException { -// -// try { -// Response httpResponse = httpServletResponse instanceof Response ? (Response) httpServletResponse : HttpConnection.getCurrentConnection().getResponse(); -// -// httpResponse.setStatus(HttpStatus.OK_200); -// httpResponse.setContentType("text/xml"); -// httpResponse.setCharacterEncoding("UTF-8"); -// Result r=new Result(new Query()); -// Hit testHit=new Hit("testHit"); -// testHit.setField("uri","testHit"); // That this is necessary is quite unfortunate... -// testHit.setField("testField","testValue"); -// // Write back all incoming properties: -// for (Object e : httpServletRequest.getParameterMap().entrySet()) { -// Map.Entry entry=(Map.Entry)e; -// testHit.setField(entry.getKey().toString(),getFirstValue(entry.getValue())); -// } -// -// r.hits().add(testHit); -// -// //StringWriter sw=new StringWriter(); -// //r.render(sw); -// //System.out.println(sw.toString()); -// -// SearchRendererAdaptor.callRender(httpResponse.getWriter(), r); -// httpResponse.complete(); -// } -// catch (Exception e) { -// System.out.println("WARNING: Could not respond to request: " + Exceptions.toMessageString(e)); -// e.printStackTrace(); -// } -// } -// -// private String getFirstValue(Object entry) { -// if (entry instanceof String[]) -// return ((String[])entry)[0].toString(); -// else -// return entry.toString(); -// } -// } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml deleted file mode 100644 index c17bbf8474d..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<result total-hit-count="3"> - <hit relevancy="75" source="test" type="summary"> - <field name="uri">nalle</field> - <field name="relevancy">75</field> - <field name="collapseId">0</field> - </hit> - <hit relevancy="73" source="test" type="summary test other"> - <field name="documentId">tralle</field> - <field name="relevancy">73</field> - <field name="collapseId">0</field> - <field name="category">test/stuff\tsome/other</field> - <field name="bsumtitle">dklf øæå sdf > & < -Ipsum, etc.</field> - </hit> - <hit relevancy="70" source="test" type="summary"> - <field name="DOCUMENTID">kalle</field> - <field name="relevancy">75</field> - <field name="collapseId">0</field> - <field name="annoying"><field>habla</field><hi>blbl</hi><br /><![CDATA[<>&fdlkkgj</field>]]>;lk<a b="1" c="2" /><x><y><z /></y></x></field> - </hit> -</result> diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml deleted file mode 100644 index 8b5ab710378..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml +++ /dev/null @@ -1,318 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<result total-hit-count="36"> -<hit type="user_reputation"> -<field name="guid">ABCDEFGHIJKLMNOPQRSTUVWXYZ</field> -<field name="level">zero</field> -<field name="points">0</field> -<field name="created">1287600988</field> -<field name="updated">1287600988</field> -</hit> -<group type="actions"> -<hit type="action"> -<field name="id">thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> -<hit type="action"> -<field name="id">reward_for_thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> -<hit type="action"> -<field name="id">undo_thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">buzz</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">undo_reward_for_thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">vote</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">report_abuse</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">reward_for_vote</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">signup</field> -<field name="created">1287600993</field> -<field name="updated">1287600993</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">registered</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">get_points</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">contrib_SignedUp</field> -<field name="created">1287600993</field> -<field name="updated">1287600993</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">contrib_AgreedToTos</field> -<field name="created">1287600993</field> -<field name="updated">1287600993</field> -<field name="points">500</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">Create Feature</field> -<field name="created"/> -<field name="updated"/> -<field name="points">0</field> -<field name="level"/> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">add_theme</field> -<field name="created"/> -<field name="updated"/> -<field name="points">0</field> -<field name="level"/> -<field name="isEnabled">1</field> -</hit> -</group> - -<group type="awards"> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/First Feature</field> -<field name="description">You’ve created your First Feature!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/1stfeature.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/25th Feature</field> -<field name="description">You’ve created your 25th Feature!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/25thfeature.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/50th Feature</field> -<field name="description">You’ve created your 50th Feature!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/10thfeature.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Topic Explorer 5</field> -<field name="description">You’ve added a Feature to your 5th Topic Page!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/5thtopic.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Topic Explorer 15</field> -<field name="description">You’ve added a Feature to your 15th Topic Page!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/15thtopic.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Topic Explorer 30</field> -<field name="description">You’ve added a Feature to your 30th Topic Page!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/30thtopic.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Pollster</field> -<field name="description">You’ve created your 5th Poll Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/pollster.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -<group type="badge"> -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Reporter</field> -<field name="description">You’ve created your 5th Article Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/newsreporter.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -<group type="badge"> -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Paparazzi</field> -<field name="description">You’ve created your 5th Image Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/paparazzi.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -<group type="badge"> -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Video Reporter</field> -<field name="description">You’ve created your 5th Video Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/director.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -</group> -</result> diff --git a/container-search/src/test/java/com/yahoo/search/federation/ysm/.gitignore b/container-search/src/test/java/com/yahoo/search/federation/ysm/.gitignore deleted file mode 100644 index e69de29bb2d..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/ysm/.gitignore +++ /dev/null diff --git a/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserBenchmarkTest.java b/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserBenchmarkTest.java index 60ada5124a0..326e37ede38 100644 --- a/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserBenchmarkTest.java +++ b/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserBenchmarkTest.java @@ -203,7 +203,6 @@ public class GroupingParserBenchmarkTest { "all(group(artist) max(2) each(each(output(summary()))))", "all(group(artist) max(2) each(each(output(summary(simple)))))", "all(group(artist) max(5) each(output(count()) each(output(summary()))))", - "all(group(ymum()))", "all(group(strlen(attr)))", "all(group(normalizesubject(attr)))", "all(group(strcat(attr, attr2)))", diff --git a/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserTestCase.java index fcf1c3bcdd0..5d311361edf 100644 --- a/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/grouping/request/parser/GroupingParserTestCase.java @@ -150,7 +150,6 @@ public class GroupingParserTestCase { "xor", "xorbit", "y", - "ymum", "zcurve"); for (String image : images) { assertParse("all(group(" + image + "))", "all(group(" + image + "))"); @@ -512,7 +511,6 @@ public class GroupingParserTestCase { assertParse("all(group(artist) max(2) each(each(output(summary()))))"); assertParse("all(group(artist) max(2) each(each(output(summary(simple)))))"); assertParse("all(group(artist) max(5) each(output(count()) each(output(summary()))))"); - assertParse("all(group(ymum()))"); assertParse("all(group(strlen(attr)))"); assertParse("all(group(normalizesubject(attr)))"); assertParse("all(group(strcat(attr, attr2)))"); diff --git a/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java index c64c4d624f2..f61299bd317 100644 --- a/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/grouping/vespa/RequestBuilderTestCase.java @@ -160,7 +160,6 @@ public class RequestBuilderTestCase { assertLayout("all(group(time.year(a)) each(output(count())))", "[[{ TimeStamp, result = [Count] }]]"); assertLayout("all(group(xor(a,b)) each(output(count())))", "[[{ Xor, result = [Count] }]]"); assertLayout("all(group(xorbit(a,1)) each(output(count())))", "[[{ XorBit, result = [Count] }]]"); - assertLayout("all(group(ymum()) each(output(count())))", "[[{ GetYMUMChecksum, result = [Count] }]]"); } @Test diff --git a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java index fa398efd293..9617e0ceb25 100644 --- a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java @@ -232,7 +232,7 @@ public class JSONSearchHandlerTestCase { public void testNormalResultExplicitDefaultRenderingFullRendererName1() throws Exception { JSONObject json = new JSONObject(); json.put("query", "abc"); - json.put("format", "DefaultRenderer"); + json.put("format", "XmlRenderer"); assertXmlResult(json, driver); } @@ -244,22 +244,6 @@ public class JSONSearchHandlerTestCase { assertJsonResult(json, driver); } - @Test - public void testResultLegacyTiledFormat() throws Exception { - JSONObject json = new JSONObject(); - json.put("query", "abc"); - json.put("format", "tiled"); - assertTiledResult(json, driver); - } - - @Test - public void testResultLegacyPageFormat() throws Exception { - JSONObject json = new JSONObject(); - json.put("query", "abc"); - json.put("format", "page"); - assertPageResult(json, driver); - } - private static final String xmlResult = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + "<result total-hit-count=\"0\">\n" + @@ -284,21 +268,6 @@ public class JSONSearchHandlerTestCase { } - private static final String tiledResult = - "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + - "<result version=\"1.0\">\n" + - "\n" + - " <hit relevance=\"1.0\">\n" + - " <id>testHit</id>\n" + - " <uri>testHit</uri>\n" + - " </hit>\n" + - "\n" + - "</result>\n"; - - private void assertTiledResult(JSONObject json, RequestHandlerTestDriver driver) { - assertOkResult(driver.sendRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.POST, json.toString(), JSON_CONTENT_TYPE), tiledResult); - } - private static final String pageResult = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + "<page version=\"1.0\">\n" + @@ -312,10 +281,6 @@ public class JSONSearchHandlerTestCase { "\n" + "</page>\n"; - private void assertPageResult(JSONObject json, RequestHandlerTestDriver driver) { - assertOkResult(driver.sendRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.POST, json.toString(), JSON_CONTENT_TYPE), pageResult); - } - private void assertOkResult(RequestHandlerTestDriver.MockResponseHandler response, String expected) { assertEquals(expected, response.readAll()); assertEquals(200, response.getStatus()); @@ -508,7 +473,6 @@ public class JSONSearchHandlerTestCase { assertEquals("Should have same mapping for properties", map, propertyMap); } - @Test public void testContentTypeParsing() throws Exception { JSONObject json = new JSONObject(); diff --git a/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java b/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java index 5ef13eba2ed..20b18ba6723 100644 --- a/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java @@ -15,7 +15,7 @@ import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.handler.HttpSearchResponse; import com.yahoo.search.handler.SearchHandler; -import com.yahoo.search.rendering.DefaultRenderer; +import com.yahoo.search.rendering.XmlRenderer; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; @@ -105,12 +105,12 @@ public class SearchHandlerTestCase { } @Test - public void testFailing() throws Exception { + public void testFailing() { assertTrue(driver.sendRequest("http://localhost?query=test&searchChain=classLoadingError").readAll().contains("NoClassDefFoundError")); } @Test - public synchronized void testPluginError() throws Exception { + public synchronized void testPluginError() { assertTrue(driver.sendRequest("http://localhost?query=test&searchChain=exceptionInPlugin").readAll().contains("NullPointerException")); } @@ -158,11 +158,11 @@ public class SearchHandlerTestCase { Result r = new Result(q); r.hits().addError(ErrorMessage.createUnspecifiedError("bamse")); r.hits().add(new Hit("http://localhost/dummy", 0.5)); - HttpSearchResponse s = new HttpSearchResponse(200, r, q, new DefaultRenderer()); + HttpSearchResponse s = new HttpSearchResponse(200, r, q, new XmlRenderer()); assertEquals("text/xml", s.getContentType()); assertNull(s.getCoverage()); assertEquals("query 'dummy'", s.getParsedQuery()); - assertEquals(5000, s.getTiming().getTimeout()); + assertEquals(500, s.getTiming().getTimeout()); } @Test @@ -191,7 +191,7 @@ public class SearchHandlerTestCase { } } @Test - public void testInvalidQueryParamWithoutQueryProfile() throws Exception { + public void testInvalidQueryParamWithoutQueryProfile() { testInvalidQueryParam(driver); } private void testInvalidQueryParam(final RequestHandlerTestDriver testDriver) { @@ -213,45 +213,35 @@ public class SearchHandlerTestCase { } @Test - public void testNormalResultImplicitDefaultRendering() throws Exception { + public void testNormalResultImplicitDefaultRendering() { assertJsonResult("http://localhost?query=abc", driver); } @Test - public void testNormalResultExplicitDefaultRendering() throws Exception { + public void testNormalResultExplicitDefaultRendering() { assertJsonResult("http://localhost?query=abc&format=default", driver); } @Test - public void testNormalResultXmlAliasRendering() throws Exception { + public void testNormalResultXmlAliasRendering() { assertXmlResult("http://localhost?query=abc&format=xml", driver); } @Test - public void testNormalResultJsonAliasRendering() throws Exception { + public void testNormalResultJsonAliasRendering() { assertJsonResult("http://localhost?query=abc&format=json", driver); } @Test - public void testNormalResultExplicitDefaultRenderingFullRendererName1() throws Exception { - assertXmlResult("http://localhost?query=abc&format=DefaultRenderer", driver); + public void testNormalResultExplicitDefaultRenderingFullRendererName1() { + assertXmlResult("http://localhost?query=abc&format=XmlRenderer", driver); } @Test - public void testNormalResultExplicitDefaultRenderingFullRendererName2() throws Exception { + public void testNormalResultExplicitDefaultRenderingFullRendererName2() { assertJsonResult("http://localhost?query=abc&format=JsonRenderer", driver); } - @Test - public void testResultLegacyTiledFormat() throws Exception { - assertTiledResult("http://localhost?query=abc&format=tiled", driver); - } - - @Test - public void testResultLegacyPageFormat() throws Exception { - assertPageResult("http://localhost?query=abc&format=page", driver); - } - private static final String xmlResult = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + "<result total-hit-count=\"0\">\n" + @@ -260,10 +250,12 @@ public class SearchHandlerTestCase { " <field name=\"uri\">testHit</field>\n" + " </hit>\n" + "</result>\n"; - private void assertXmlResult(String request, RequestHandlerTestDriver driver) throws Exception { + + private void assertXmlResult(String request, RequestHandlerTestDriver driver) { assertOkResult(driver.sendRequest(request), xmlResult); } - private void assertXmlResult(RequestHandlerTestDriver driver) throws Exception { + + private void assertXmlResult(RequestHandlerTestDriver driver) { assertXmlResult("http://localhost?query=abc", driver); } @@ -272,38 +264,9 @@ public class SearchHandlerTestCase { + "\"children\":[" + "{\"id\":\"testHit\",\"relevance\":1.0,\"fields\":{\"uri\":\"testHit\"}}" + "]}}"; - private void assertJsonResult(String request, RequestHandlerTestDriver driver) throws Exception { - assertOkResult(driver.sendRequest(request), jsonResult); - } - - private static final String tiledResult = - "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + - "<result version=\"1.0\">\n" + - "\n" + - " <hit relevance=\"1.0\">\n" + - " <id>testHit</id>\n" + - " <uri>testHit</uri>\n" + - " </hit>\n" + - "\n" + - "</result>\n"; - private void assertTiledResult(String request, RequestHandlerTestDriver driver) throws Exception { - assertOkResult(driver.sendRequest(request), tiledResult); - } - private static final String pageResult = - "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + - "<page version=\"1.0\">\n" + - "\n" + - " <content>\n" + - " <hit relevance=\"1.0\">\n" + - " <id>testHit</id>\n" + - " <uri>testHit</uri>\n" + - " </hit>\n" + - " </content>\n" + - "\n" + - "</page>\n"; - private void assertPageResult(String request, RequestHandlerTestDriver driver) throws Exception { - assertOkResult(driver.sendRequest(request), pageResult); + private void assertJsonResult(String request, RequestHandlerTestDriver driver) { + assertOkResult(driver.sendRequest(request), jsonResult); } private void assertOkResult(RequestHandlerTestDriver.MockResponseHandler response, String expected) { diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/engine/test/ExecutionAbstractTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/engine/test/ExecutionAbstractTestCase.java index 999a6d32ac6..569f219f635 100644 --- a/container-search/src/test/java/com/yahoo/search/pagetemplates/engine/test/ExecutionAbstractTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/engine/test/ExecutionAbstractTestCase.java @@ -3,9 +3,6 @@ package com.yahoo.search.pagetemplates.engine.test; import com.google.common.util.concurrent.ListenableFuture; import com.yahoo.io.IOUtils; -import com.yahoo.prelude.templates.TiledTemplateSet; -import com.yahoo.prelude.templates.UserTemplate; -import com.yahoo.prelude.templates.test.TilingTestCase; import com.yahoo.search.Result; import com.yahoo.search.pagetemplates.PageTemplate; import com.yahoo.search.pagetemplates.config.PageTemplateXMLReader; diff --git a/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java b/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java index 83ef955a6d9..5026250ab91 100644 --- a/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java @@ -13,14 +13,14 @@ public class SoftTimeoutTestCase { @Test public void testDefaultsInQuery() { Query query=new Query("?query=test"); - assertNull(query.getRanking().getSoftTimeout().getEnable()); + assertTrue(query.getRanking().getSoftTimeout().getEnable()); assertNull(query.getRanking().getSoftTimeout().getFactor()); assertNull(query.getRanking().getSoftTimeout().getTailcost()); } @Test public void testQueryOverride() { - Query query=new Query("?query=test&ranking.softtimeout.enable&ranking.softtimeout.factor=0.7&ranking.softtimeout.tailcost=0.3"); + Query query=new Query("?query=test&ranking.softtimeout.factor=0.7&ranking.softtimeout.tailcost=0.3"); assertTrue(query.getRanking().getSoftTimeout().getEnable()); assertEquals(Double.valueOf(0.7), query.getRanking().getSoftTimeout().getFactor()); assertEquals(Double.valueOf(0.3), query.getRanking().getSoftTimeout().getTailcost()); @@ -30,6 +30,14 @@ public class SoftTimeoutTestCase { assertEquals("0.3", query.getRanking().getProperties().get("vespa.softtimeout.tailcost").get(0)); } + @Test + public void testDisable() { + Query query=new Query("?query=test&ranking.softtimeout.enable=false"); + assertFalse(query.getRanking().getSoftTimeout().getEnable()); + query.prepare(); + assertTrue(query.getRanking().getProperties().isEmpty()); + } + private void verifyException(String key, String value) { try { new Query("?query=test&ranking.softtimeout."+key+"="+value); diff --git a/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java b/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java index 1794f8989b4..276ff107769 100644 --- a/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java @@ -41,7 +41,7 @@ public class ModelTestCase { @Test public void testCopyParameters() { - Query q1 = new Query("?query=test1&filter=test2&defidx=content&default-index=lala&encoding=iso8859-1"); + Query q1 = new Query("?query=test1&filter=test2&default-index=content&default-index=lala&encoding=iso8859-1"); Query q2 = q1.clone(); Model r1 = q1.getModel(); Model r2 = q2.getModel(); diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/LegacyCombinatorTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/LegacyCombinatorTestCase.java deleted file mode 100644 index 4796937eb65..00000000000 --- a/container-search/src/test/java/com/yahoo/search/querytransform/LegacyCombinatorTestCase.java +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.querytransform; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import com.yahoo.container.protect.Error; -import com.yahoo.prelude.IndexFacts; -import com.yahoo.prelude.query.AndItem; -import com.yahoo.prelude.query.WordItem; -import com.yahoo.search.Query; -import com.yahoo.search.Searcher; -import com.yahoo.search.searchchain.Execution; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Unit testing of the searcher com.yahoo.search.querytransform.LegacyCombinator. - * - * @author Steinar Knutsen - */ -public class LegacyCombinatorTestCase { - - Searcher searcher; - - @Before - public void setUp() throws Exception { - searcher = new LegacyCombinator(); - } - - @Test - public void testStraightForwardSearch() { - Query q = new Query("?query=a&query.juhu=b"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("AND a b", q.getModel().getQueryTree().toString()); - q = new Query("?query=a&query.juhu=b&defidx.juhu=juhu.22[gnuff]"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("AND a juhu.22[gnuff]:b", q.getModel().getQueryTree().toString()); - q = new Query("?query=a&query.juhu="); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("a", q.getModel().getQueryTree().toString()); - q = new Query("?query=a+c&query.juhu=b"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("AND a c b", q.getModel().getQueryTree().toString()); - } - - @Test - public void testNoBaseQuery() { - Query q = new Query("?query.juhu=b"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("b", q.getModel().getQueryTree().toString()); - } - - @Test - public void testIncompatibleNewAndOldQuery() { - Query q = new Query("?query.juhu=b&defidx.juhu=a&query.juhu.defidx=c"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("NULL", q.getModel().getQueryTree().toString()); - assertTrue("No expected error found.", q.errors().size() > 0); - assertEquals("Did not get invalid query parameter error as expected.", - Error.INVALID_QUERY_PARAMETER.code, q.errors().get(0).getCode()); - } - - @Test - public void testNotCombinatorWithoutRoot() { - Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=not"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("NULL", q.getModel().getQueryTree().toString()); - assertTrue("No expected error found.", q.errors().size() > 0); - System.out.println(q.errors()); - assertEquals("Did not get invalid query parameter error as expected.", - Error.INVALID_QUERY_PARAMETER.code, q.errors().get(0).getCode()); - } - - @Test - public void testRankCombinator() { - Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("nalle:b", q.getModel().getQueryTree().toString()); - } - - @Test - public void testRankAndNot() { - Query q = new Query("?query.yahoo=2&query.yahoo.defidx=1&query.yahoo.operator=not&query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("+nalle:b -1:2", q.getModel().getQueryTree().toString()); - } - - @Test - public void testReqAndRankAndNot() { - Query q = new Query("?query.yahoo=2&query.yahoo.defidx=1&query.yahoo.operator=not&query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank&query.bamse=z&query.bamse.defidx=y"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("+(RANK y:z nalle:b) -1:2", q.getModel().getQueryTree().toString()); - } - - @Test - public void testReqAndRank() { - Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank&query.bamse=z&query.bamse.defidx=y"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("RANK y:z nalle:b", q.getModel().getQueryTree().toString()); - } - - @Test - public void testReqAndNot() { - Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=not&query.bamse=z&query.bamse.defidx=y"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("+y:z -nalle:b", q.getModel().getQueryTree().toString()); - } - - @Test - public void testNewAndOld() { - Query q = new Query("?query.juhu=b&defidx.juhu=nalle&query.bamse=z&query.bamse.defidx=y"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - Set<StringPair> nastierItems = new HashSet<>(); - nastierItems.add(new StringPair("nalle", "b")); - nastierItems.add(new StringPair("y", "z")); - e.search(q); - AndItem root = (AndItem) q.getModel().getQueryTree().getRoot(); - Iterator<?> iterator = root.getItemIterator(); - while (iterator.hasNext()) { - WordItem word = (WordItem) iterator.next(); - StringPair asPair = new StringPair(word.getIndexName(), word.stringValue()); - if (nastierItems.contains(asPair)) { - nastierItems.remove(asPair); - } else { - assertFalse("Got unexpected item in query tree: (" - + word.getIndexName() + ", " + word.stringValue() + ")", - true); - } - } - assertEquals("Not all expected items found in query.", 0, nastierItems.size()); - } - - @Test - public void testReqAndNotWithQuerySyntaxAll() { - Query q = new Query("?query.juhu=b+c&query.juhu.defidx=nalle&query.juhu.operator=not&query.juhu.type=any&query.bamse=z&query.bamse.defidx=y"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("+y:z -(OR nalle:b nalle:c)", q.getModel().getQueryTree().toString()); - } - - @Test - public void testDefaultIndexWithoutQuery() { - Query q = new Query("?defidx.juhu=b"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("NULL", q.getModel().getQueryTree().toString()); - q = new Query("?query=a&defidx.juhu=b"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("a", q.getModel().getQueryTree().toString()); - } - - private static class StringPair { - - public final String index; - public final String value; - - StringPair(String index, String value) { - super(); - this.index = index; - this.value = value; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((index == null) ? 0 : index.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final StringPair other = (StringPair) obj; - if (index == null) { - if (other.index != null) - return false; - } else if (!index.equals(other.index)) - return false; - if (value == null) { - if (other.value != null) - return false; - } else if (!value.equals(other.value)) - return false; - return true; - } - - } - - @Test - public void testMultiPart() { - Query q = new Query("?query=a&query.juhu=b&query.nalle=c"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - Set<String> items = new HashSet<>(); - items.add("a"); - items.add("b"); - items.add("c"); - e.search(q); - // OK, the problem here is we have no way of knowing whether nalle or - // juhu was added first, since we have passed through HashMap instances - // inside the implementation - - AndItem root = (AndItem) q.getModel().getQueryTree().getRoot(); - Iterator<?> iterator = root.getItemIterator(); - while (iterator.hasNext()) { - WordItem word = (WordItem) iterator.next(); - if (items.contains(word.stringValue())) { - items.remove(word.stringValue()); - } else { - assertFalse("Got unexpected item in query tree: " + word.stringValue(), true); - } - } - assertEquals("Not all expected items found in query.", 0, items.size()); - - Set<StringPair> nastierItems = new HashSet<>(); - nastierItems.add(new StringPair("", "a")); - nastierItems.add(new StringPair("juhu.22[gnuff]", "b")); - nastierItems.add(new StringPair("gnuff[8].name(\"tralala\")", "c")); - q = new Query("?query=a&query.juhu=b&defidx.juhu=juhu.22[gnuff]&query.nalle=c&defidx.nalle=gnuff[8].name(%22tralala%22)"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - root = (AndItem) q.getModel().getQueryTree().getRoot(); - iterator = root.getItemIterator(); - while (iterator.hasNext()) { - WordItem word = (WordItem) iterator.next(); - StringPair asPair = new StringPair(word.getIndexName(), word.stringValue()); - if (nastierItems.contains(asPair)) { - nastierItems.remove(asPair); - } else { - assertFalse("Got unexpected item in query tree: (" - + word.getIndexName() + ", " + word.stringValue() + ")", - true); - } - } - assertEquals("Not all expected items found in query.", 0, nastierItems.size()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/test/QueryCombinatorTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/test/QueryCombinatorTestCase.java deleted file mode 100644 index 995c1cc7a72..00000000000 --- a/container-search/src/test/java/com/yahoo/search/querytransform/test/QueryCombinatorTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.querytransform.test; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import com.yahoo.component.ComponentId; -import com.yahoo.prelude.IndexFacts; -import com.yahoo.prelude.query.AndItem; -import com.yahoo.prelude.query.WordItem; -import com.yahoo.search.Query; -import com.yahoo.search.Searcher; -import com.yahoo.search.querytransform.QueryCombinator; -import com.yahoo.search.searchchain.Execution; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -/** - * Unit testing of the searcher com.yahoo.search.querytransform.QueryCombinator. - * - * @author Steinar Knutsen - */ -public class QueryCombinatorTestCase { - - Searcher searcher; - - @Before - @SuppressWarnings("deprecation") - public void setUp() throws Exception { - searcher = new QueryCombinator(new ComponentId("combinationTest")); - } - - @Test - public void testStraightForwardSearch() { - Query q = new Query("?query=a&query.juhu=b"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("AND a b", q.getModel().getQueryTree().toString()); - q = new Query("?query=a&query.juhu=b&defidx.juhu=juhu.22[gnuff]"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("AND a juhu.22[gnuff]:b", q.getModel().getQueryTree().toString()); - q = new Query("?query=a&query.juhu="); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("a", q.getModel().getQueryTree().toString()); - q = new Query("?query=a+c&query.juhu=b"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("AND a c b", q.getModel().getQueryTree().toString()); - } - - @Test - public void testNoBaseQuery() { - Query q = new Query("?query.juhu=b"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("b", q.getModel().getQueryTree().toString()); - } - - @Test - public void testDefaultIndexWithoutQuery() { - Query q = new Query("?defidx.juhu=b"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("NULL", q.getModel().getQueryTree().toString()); - q = new Query("?query=a&defidx.juhu=b"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - assertEquals("a", q.getModel().getQueryTree().toString()); - } - - private static class StringPair { - - public final String index; - public final String value; - - StringPair(String index, String value) { - super(); - this.index = index; - this.value = value; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((index == null) ? 0 : index.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final StringPair other = (StringPair) obj; - if (index == null) { - if (other.index != null) - return false; - } else if (!index.equals(other.index)) - return false; - if (value == null) { - if (other.value != null) - return false; - } else if (!value.equals(other.value)) - return false; - return true; - } - - } - - @Test - public void testMultiPart() { - Query q = new Query("?query=a&query.juhu=b&query.nalle=c"); - Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - Set<String> items = new HashSet<>(); - items.add("a"); - items.add("b"); - items.add("c"); - e.search(q); - // OK, the problem here is we have no way of knowing whether nalle or - // juhu was added first, since we have passed through HashMap instances - // inside the implementation - - AndItem root = (AndItem) q.getModel().getQueryTree().getRoot(); - Iterator<?> iterator = root.getItemIterator(); - while (iterator.hasNext()) { - WordItem word = (WordItem) iterator.next(); - if (items.contains(word.stringValue())) { - items.remove(word.stringValue()); - } else { - assertFalse("Got unexpected item in query tree: " + word.stringValue(), true); - } - } - assertEquals("Not all expected items found in query.", 0, items.size()); - - Set<StringPair> nastierItems = new HashSet<>(); - nastierItems.add(new StringPair("", "a")); - nastierItems.add(new StringPair("juhu.22[gnuff]", "b")); - nastierItems.add(new StringPair("gnuff[8].name(\"tralala\")", "c")); - q = new Query("?query=a&query.juhu=b&defidx.juhu=juhu.22[gnuff]&query.nalle=c&defidx.nalle=gnuff[8].name(%22tralala%22)"); - e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); - e.search(q); - root = (AndItem) q.getModel().getQueryTree().getRoot(); - iterator = root.getItemIterator(); - while (iterator.hasNext()) { - WordItem word = (WordItem) iterator.next(); - StringPair asPair = new StringPair(word.getIndexName(), word.stringValue()); - if (nastierItems.contains(asPair)) { - nastierItems.remove(asPair); - } else { - assertFalse("Got unexpected item in query tree: (" - + word.getIndexName() + ", " + word.stringValue() + ")", - true); - } - } - assertEquals("Not all expected items found in query.", 0, nastierItems.size()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java index 5b3b5ca6d73..10a3b695f64 100644 --- a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java @@ -1,14 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.rendering; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.util.concurrent.ListenableFuture; +import com.yahoo.component.ComponentId; import com.yahoo.component.chain.Chain; +import com.yahoo.container.QrSearchersConfig; import com.yahoo.data.access.simple.Value; import com.yahoo.data.access.slime.SlimeAdapter; import com.yahoo.document.DataType; @@ -19,8 +18,13 @@ import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.document.datatypes.TensorFieldValue; import com.yahoo.document.predicate.Predicate; +import com.yahoo.prelude.Index; +import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import com.yahoo.prelude.fastsearch.FastHit; import com.yahoo.prelude.hitfield.JSONString; +import com.yahoo.prelude.searcher.JuniperSearcher; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; @@ -38,6 +42,7 @@ import com.yahoo.search.result.NanNumber; import com.yahoo.search.result.Relevance; import com.yahoo.search.result.StructuredData; import com.yahoo.search.searchchain.Execution; +import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; import com.yahoo.search.statistics.ElapsedTimeTestCase; import com.yahoo.search.statistics.ElapsedTimeTestCase.CreativeTimeSource; import com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher; @@ -51,32 +56,31 @@ import com.yahoo.yolean.trace.TraceNode; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.times; /** * Functional testing of {@link JsonRenderer}. * * @author Steinar Knutsen + * @author bratseth */ public class JsonRendererTestCase { - JsonRenderer originalRenderer; - JsonRenderer renderer; + private JsonRenderer originalRenderer; + private JsonRenderer renderer; public JsonRendererTestCase() { originalRenderer = new JsonRenderer(); @@ -84,23 +88,11 @@ public class JsonRendererTestCase { @Before public void setUp() throws Exception { - // Do the same dance as in production + // Use the shared renderer as a prototype object, as specified in the API contract renderer = (JsonRenderer) originalRenderer.clone(); renderer.init(); } - @After - public void tearDown() throws Exception { - renderer = null; - } - - private static final class Thingie { - @Override - public String toString() { - return "thingie"; - } - } - @Test public void testDocumentId() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" @@ -130,14 +122,6 @@ public class JsonRendererTestCase { assertEqualJson(expected, summary); } - private Result newEmptyResult(String[] args) { - return new Result(new Query("/?" + String.join("&", args))); - } - - private Result newEmptyResult() { - return newEmptyResult(new String[] {"query=a"}); - } - @Test public void testDataTypes() throws IOException, InterruptedException, ExecutionException, JSONException { String expected = "{\n" @@ -188,7 +172,7 @@ public class JsonRendererTestCase { @Test - public final void testTracing() throws IOException, InterruptedException, ExecutionException { + public void testTracing() throws IOException, InterruptedException, ExecutionException { // which clearly shows a trace child is created once too often... String expected = "{\n" + " \"root\": {\n" @@ -243,7 +227,7 @@ public class JsonRendererTestCase { } @Test - public final void testEmptyTracing() throws IOException, InterruptedException, ExecutionException { + public void testEmptyTracing() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" @@ -272,7 +256,7 @@ public class JsonRendererTestCase { @SuppressWarnings("unchecked") @Test - public final void testTracingWithEmptySubtree() throws IOException, InterruptedException, ExecutionException { + public void testTracingWithEmptySubtree() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" @@ -346,15 +330,8 @@ public class JsonRendererTestCase { assertEqualJson(expected, summary); } - private void subExecution(Execution execution, String color, int traceLevel) { - Execution e2 = new Execution(new Chain<Searcher>(), execution.context()); - Query subQuery = new Query("/?query=b&tracelevel=" + traceLevel); - e2.search(subQuery); - subQuery.trace(color, 1); - } - @Test - public final void testTracingOfNodesWithBothChildrenAndData() throws IOException, InterruptedException, ExecutionException { + public void testTracingOfNodesWithBothChildrenAndData() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" @@ -400,7 +377,7 @@ public class JsonRendererTestCase { @Test - public final void testTracingOfNodesWithBothChildrenAndDataAndEmptySubnode() throws IOException, InterruptedException, ExecutionException { + public void testTracingOfNodesWithBothChildrenAndDataAndEmptySubnode() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" @@ -441,7 +418,7 @@ public class JsonRendererTestCase { } @Test - public final void testTracingOfNestedNodesWithDataAndSubnodes() throws IOException, InterruptedException, ExecutionException { + public void testTracingOfNestedNodesWithDataAndSubnodes() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" @@ -490,7 +467,7 @@ public class JsonRendererTestCase { @Test - public final void test() throws IOException, InterruptedException, ExecutionException { + public void test() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" @@ -498,8 +475,7 @@ public class JsonRendererTestCase { + " \"children\": [\n" + " {\n" + " \"fields\": {\n" - + " \"c\": \"d\",\n" - + " \"uri\": \"http://localhost/1\"\n" + + " \"c\": \"d\"\n" + " },\n" + " \"id\": \"http://localhost/1\",\n" + " \"relevance\": 0.9,\n" @@ -523,8 +499,7 @@ public class JsonRendererTestCase { + " },\n" + " {\n" + " \"fields\": {\n" - + " \"b\": \"foo\",\n" - + " \"uri\": \"http://localhost/\"\n" + + " \"b\": \"foo\"\n" + " },\n" + " \"id\": \"http://localhost/\",\n" + " \"relevance\": 0.95,\n" @@ -555,7 +530,7 @@ public class JsonRendererTestCase { + " \"relevance\": 1.0\n" + " }\n" + "}"; - Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true"); + Query q = new Query("/?query=a&tracelevel=5"); Execution execution = new Execution(Execution.Context.createContextStub()); Result r = new Result(q); r.setCoverage(new Coverage(500, 500,1,1)); @@ -603,7 +578,7 @@ public class JsonRendererTestCase { + " \"relevance\": 1.0\n" + " }\n" + "}"; - Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true"); + Query q = new Query("/?query=a&tracelevel=5"); Execution execution = new Execution(Execution.Context.createContextStub()); Result r = new Result(q); r.setCoverage(new Coverage(500, 600).setDegradedReason(5)); @@ -725,7 +700,7 @@ public class JsonRendererTestCase { + " \"relevance\": 1.0\n" + " }\n" + "}\n"; - Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true"); + Query q = new Query("/?query=a&tracelevel=5"); Result r = new Result(q); Throwable t = new Throwable(); StackTraceElement[] stack = new StackTraceElement[1]; @@ -885,7 +860,7 @@ public class JsonRendererTestCase { }); GroupList gl = new GroupList("customer"); Group g = new Group(new DoubleBucketId(1.0, 2.0), new Relevance(1.0)); - g.setField("something()", Integer.valueOf(7)); + g.setField("something()", 7); gl.add(g); rg.add(gl); r.hits().add(rg); @@ -958,7 +933,7 @@ public class JsonRendererTestCase { } @Test - public final void testFieldValueInHit() throws IOException, InterruptedException, ExecutionException, JSONException { + public void testFieldValueInHit() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" @@ -993,7 +968,7 @@ public class JsonRendererTestCase { } @Test - public final void testHiddenFields() throws IOException, InterruptedException, ExecutionException, JSONException { + public void testHiddenFields() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" @@ -1017,17 +992,8 @@ public class JsonRendererTestCase { assertEqualJson(expected, summary); } - private Hit createHitWithOnlyHiddenFields() { - Hit h = new Hit("hiddenFields"); - h.setField("NaN", NanNumber.NaN); - h.setField("emptyString", ""); - h.setField("emptyStringFieldValue", new StringFieldValue("")); - h.setField("$vespaImplementationDetail", "Hello, World!"); - return h; - } - @Test - public final void testDebugRendering() throws IOException, InterruptedException, ExecutionException, JSONException { + public void testDebugRendering() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" @@ -1058,7 +1024,7 @@ public class JsonRendererTestCase { } @Test - public final void testTimingRendering() throws InterruptedException, ExecutionException, JsonParseException, JsonMappingException, IOException { + public void testTimingRendering() throws InterruptedException, ExecutionException, IOException { String expected = "{" + " \"root\": {" + " \"fields\": {" @@ -1093,7 +1059,7 @@ public class JsonRendererTestCase { } @Test - public final void testJsonCallback() throws IOException, InterruptedException, ExecutionException, JSONException { + public void testJsonCallback() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" @@ -1131,7 +1097,7 @@ public class JsonRendererTestCase { } @Test - public final void testMapInField() throws IOException, InterruptedException, ExecutionException, JSONException { + public void testMapInField() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" @@ -1187,6 +1153,54 @@ public class JsonRendererTestCase { + "}"; assertEquals("Duplicate key \"duplicate\"", validateJSON(json)); } + + @Test + public void testDynamicSummary() throws Exception { + String content = "\uFFF9Feeding\uFFFAfeed\uFFFB \u001F\uFFF9documents\uFFFAdocument\uFFFB\u001F into Vespa \uFFF9is\uFFFAbe\u001Eincrement of a set of \u001F\uFFF9documents\uFFFAdocument\uFFFB\u001F fed into Vespa \uFFF9is\u001Efloat in XML when \u001Fdocument\u001F attribute \uFFF9is\uFFFAbe\uFFFB int\u001E"; + Result result = createResult("one", content, true); + + String summary = render(result); + + String expected = + "{ \n" + + " \"root\":{ " + + " \"id\":\"toplevel\"," + + " \"relevance\":1.0," + + " \"fields\":{ " + + " \"totalCount\":0" + + " }," + + " \"children\":[ " + + " { " + + " \"id\":\"http://abc.html/\"," + + " \"relevance\":1.0," + + " \"fields\":{ " + + " \"sddocname\":\"one\",\n" + + " \"dynteaser\":\"Feeding <hi>documents</hi> into Vespa is<sep />increment of a set of <hi>documents</hi> fed into Vespa <sep />float in XML when <hi>document</hi> attribute is int<sep />\"\n" + + " }\n" + + " }\n" + + " ]\n" + + " }\n" + + "}\n"; + assertEqualJson(expected, summary); + } + + private Result newEmptyResult(String[] args) { + return new Result(new Query("/?" + String.join("&", args))); + } + + private Result newEmptyResult() { + return newEmptyResult(new String[] {"query=a"}); + } + + private Hit createHitWithOnlyHiddenFields() { + Hit h = new Hit("hiddenFields"); + h.setField("NaN", NanNumber.NaN); + h.setField("emptyString", ""); + h.setField("emptyStringFieldValue", new StringFieldValue("")); + h.setField("$vespaImplementationDetail", "Hello, World!"); + return h; + } + private String render(Result r) throws InterruptedException, ExecutionException { Execution execution = new Execution(Execution.Context.createContextStub()); return render(execution, r); @@ -1209,6 +1223,7 @@ public class JsonRendererTestCase { assertEquals("", validateJSON(expected)); assertEquals("", validateJSON(generated)); } + private String validateJSON(String presumablyValidJson) { try { new JSONObject(presumablyValidJson); @@ -1218,4 +1233,76 @@ public class JsonRendererTestCase { } } + private static final class Thingie { + @Override + public String toString() { + return "thingie"; + } + } + + private Result createResult(String sdName, String content, boolean bolding) { + Chain<Searcher> chain = createSearchChain(sdName, content); + Query query = new Query("?query=12"); + if ( ! bolding) + query = new Query("?query=12&bolding=false"); + Execution execution = createExecution(chain); + Result result = execution.search(query); + execution.fill(result); + return result; + } + + /** + * Creates a search chain which always returns a result with one hit containing information given in this + * + * @param sdName the search definition type of the returned hit + * @param content the content of the "dynteaser" field of the returned hit + */ + private Chain<Searcher> createSearchChain(String sdName, String content) { + JuniperSearcher searcher = new JuniperSearcher(new ComponentId("test"), + new QrSearchersConfig(new QrSearchersConfig.Builder())); + + DocumentSourceSearcher docsource = new DocumentSourceSearcher(); + addResult(new Query("?query=12"), sdName, content, docsource); + addResult(new Query("?query=12&bolding=false"), sdName, content, docsource); + return new Chain<>(searcher, docsource); + } + + private void addResult(Query query, String sdName, String content, DocumentSourceSearcher docsource) { + Result r = new Result(query); + FastHit hit = new FastHit(); + hit.setId("http://abc.html"); + hit.setRelevance(new Relevance(1)); + hit.setField(Hit.SDDOCNAME_FIELD, sdName); + hit.setField("dynteaser", content); + r.hits().add(hit); + docsource.addResult(query, r); + } + + private Execution createExecution(Chain<Searcher> chain) { + Map<String, List<String>> clusters = new LinkedHashMap<>(); + Map<String, SearchDefinition> searchDefs = new LinkedHashMap<>(); + searchDefs.put("one", createSearchDefinitionOne()); + SearchDefinition union = new SearchDefinition("union"); + IndexModel indexModel = new IndexModel(clusters, searchDefs, union); + return new Execution(chain, Execution.Context.createContextStub(new IndexFacts(indexModel))); + } + + private SearchDefinition createSearchDefinitionOne() { + SearchDefinition one = new SearchDefinition("one"); + + Index dynteaser = new Index("dynteaser"); + dynteaser.setDynamicSummary(true); + one.addIndex(dynteaser); + + Index bigteaser = new Index("bigteaser"); + dynteaser.setHighlightSummary(true); + one.addIndex(bigteaser); + + Index otherteaser = new Index("otherteaser"); + otherteaser.setDynamicSummary(true); + one.addIndex(otherteaser); + + return one; + } + } diff --git a/container-search/src/test/java/com/yahoo/search/rendering/SyncDefaultRendererTestCase.java b/container-search/src/test/java/com/yahoo/search/rendering/SyncDefaultRendererTestCase.java index 1d2187376a4..acb69670b14 100644 --- a/container-search/src/test/java/com/yahoo/search/rendering/SyncDefaultRendererTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/rendering/SyncDefaultRendererTestCase.java @@ -58,8 +58,8 @@ public class SyncDefaultRendererTestCase { @SuppressWarnings("deprecation") @Test - public final void testRenderWriterResult() throws InterruptedException, ExecutionException { - Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true"); + public void testRenderWriterResult() throws InterruptedException, ExecutionException { + Query q = new Query("/?query=a&tracelevel=5"); q.getPresentation().setTiming(true); Result r = new Result(q); r.setCoverage(new Coverage(500, 1)); @@ -96,7 +96,7 @@ public class SyncDefaultRendererTestCase { assertTrue(f.get()); String summary = Utf8.toString(bs.toByteArray()); // TODO figure out a reasonably strict and reasonably flexible way to test - assertTrue(summary.length() > 1000); + assertTrue(summary.length() > 900); } } diff --git a/container-search/src/test/java/com/yahoo/search/rendering/XMLRendererTestCase.java b/container-search/src/test/java/com/yahoo/search/rendering/XMLRendererTestCase.java index c95019d37d6..184a8c1aa43 100644 --- a/container-search/src/test/java/com/yahoo/search/rendering/XMLRendererTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/rendering/XMLRendererTestCase.java @@ -4,13 +4,21 @@ package com.yahoo.search.rendering; import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; - -import com.yahoo.search.handler.SearchHandler; -import org.junit.After; -import org.junit.Before; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import com.yahoo.component.ComponentId; +import com.yahoo.container.QrSearchersConfig; +import com.yahoo.prelude.Index; +import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; +import com.yahoo.prelude.searcher.JuniperSearcher; +import com.yahoo.search.result.Hit; +import com.yahoo.search.result.Relevance; +import com.yahoo.search.searchchain.Execution; +import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; import org.junit.Test; import com.google.common.util.concurrent.ListenableFuture; @@ -25,50 +33,112 @@ import com.yahoo.search.result.HitGroup; import com.yahoo.search.statistics.ElapsedTimeTestCase; import com.yahoo.search.statistics.TimeTracker; import com.yahoo.search.statistics.ElapsedTimeTestCase.CreativeTimeSource; -import com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher; import com.yahoo.text.Utf8; /** * Test the XML renderer * * @author Steinar Knutsen + * @author bratseth */ public class XMLRendererTestCase { - DefaultRenderer d; - - @Before - public void setUp() throws Exception { - d = new DefaultRenderer(); - d.init(); + @Test + public void testGetEncoding() { + XmlRenderer renderer = new XmlRenderer(); + renderer.init(); + assertEquals("utf-8", renderer.getEncoding()); } - @After - public void tearDown() throws Exception { + @Test + public void testGetMimeType() { + XmlRenderer renderer = new XmlRenderer(); + renderer.init(); + assertEquals("text/xml", renderer.getMimeType()); } @Test - public final void testGetEncoding() { - assertEquals("utf-8", d.getEncoding()); + public void testXmlRendering() throws Exception { + Query q = new Query("/?query=a"); + + Result result = new Result(q); + result.setCoverage(new Coverage(500, 1)); + + FastHit h = new FastHit("http://localhost/", .95); + h.setField("$a", "Hello, world."); + h.setField("b", "foo"); + result.hits().add(h); + + HitGroup g = new HitGroup("usual"); + h = new FastHit("http://localhost/1", .90); + h.setField("c", "d"); + g.add(h); + result.hits().add(g); + + HitGroup gg = new HitGroup("type grouphit"); + gg.types().add("grouphit"); + gg.setField("e", "f"); + result.hits().add(gg); + result.hits().addError(ErrorMessage.createInternalServerError("message")); + + String summary = render(result); + + String expected = + "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + + "<result total-hit-count=\"0\" coverage-docs=\"500\" coverage-nodes=\"1\" coverage-full=\"false\" coverage=\"0\" results-full=\"0\" results=\"1\">\n" + + " <error code=\"18\">Internal server error.</error>\n" + + " <errordetails>\n" + + " <error error=\"Internal server error.\" code=\"18\">message</error>\n" + + " </errordetails>\n" + + " <group relevancy=\"1.0\">\n" + + " <hit type=\"summary\" relevancy=\"0.9\">\n" + + " <field name=\"relevancy\">0.9</field>\n" + + " <field name=\"c\">d</field>\n" + + " </hit>\n" + + " </group>\n" + + " <hit type=\"grouphit\" relevancy=\"1.0\">\n" + + " <id>type grouphit</id>\n" + + " </hit>\n" + + " <hit type=\"summary\" relevancy=\"0.95\">\n" + + " <field name=\"relevancy\">0.95</field>\n" + + " <field name=\"b\">foo</field>\n" + + " </hit>\n" + + "</result>\n"; + + assertEquals(expected, summary); } @Test - public final void testGetMimeType() { - assertEquals("text/xml", d.getMimeType()); + public void testXmlRenderingOfDynamicSummary() throws Exception { + String content = "\uFFF9Feeding\uFFFAfeed\uFFFB \u001F\uFFF9documents\uFFFAdocument\uFFFB\u001F into Vespa \uFFF9is\uFFFAbe\u001Eincrement of a set of \u001F\uFFF9documents\uFFFAdocument\uFFFB\u001F fed into Vespa \uFFF9is\u001Efloat in XML when \u001Fdocument\u001F attribute \uFFF9is\uFFFAbe\uFFFB int\u001E"; + Result result = createResult("one", content, true); + + String summary = render(result); + + String expected = + "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + + "<result total-hit-count=\"0\">\n" + + " <hit relevancy=\"1.0\">\n" + + " <field name=\"relevancy\">1.0</field>\n" + + " <field name=\"sddocname\">one</field>\n" + + " <field name=\"dynteaser\">Feeding <hi>documents</hi> into Vespa is<sep />increment of a set of <hi>documents</hi> fed into Vespa <sep />float in XML when <hi>document</hi> attribute is int<sep /></field>\n" + + " </hit>\n" + + "</result>\n"; + assertEquals(expected, summary); } @Test - public final void testImplicitDefaultRender() throws Exception { - Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true"); + public void testXmlRenderingWithTimeTracking() throws Exception { + Query q = new Query("/?query=a&tracelevel=5"); q.getPresentation().setTiming(true); - Result r = new Result(q); - r.setCoverage(new Coverage(500, 1)); - - TimeTracker t = new TimeTracker(new Chain<Searcher>( - new UselessSearcher("first"), new UselessSearcher("second"), - new UselessSearcher("third"))); - ElapsedTimeTestCase.doInjectTimeSource(t, new CreativeTimeSource( - new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L })); + + Result result = new Result(q); + result.setCoverage(new Coverage(500, 1)); + + TimeTracker t = new TimeTracker(new Chain<Searcher>(new NoopSearcher("first"), + new NoopSearcher("second"), + new NoopSearcher("third"))); + ElapsedTimeTestCase.doInjectTimeSource(t, new CreativeTimeSource(new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L })); t.sampleSearch(0, true); t.sampleSearch(1, true); t.sampleSearch(2, true); @@ -76,47 +146,103 @@ public class XMLRendererTestCase { t.sampleSearchReturn(2, true, null); t.sampleSearchReturn(1, true, null); t.sampleSearchReturn(0, true, null); - r.getElapsedTime().add(t); - FastHit h = new FastHit("http://localhost/", .95); - h.setField("$a", "Hello, world."); - h.setField("b", "foo"); - r.hits().add(h); - HitGroup g = new HitGroup("usual"); - h = new FastHit("http://localhost/1", .90); - h.setField("c", "d"); - g.add(h); - r.hits().add(g); - HitGroup gg = new HitGroup("type grouphit"); - gg.types().add("grouphit"); - gg.setField("e", "f"); - r.hits().add(gg); - r.hits().addError(ErrorMessage.createInternalServerError("boom")); + result.getElapsedTime().add(t); + String summary = render(result); + + assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<result total-hit-count=\"0\"", + summary.substring(0, 67)); + assertTrue(summary.contains("querytime=")); + assertTrue(summary.contains("summaryfetchtime=")); + assertTrue(summary.contains("searchtime=")); + assertTrue(summary.contains("<meta type=\"context\">")); + } + + private String render(Result result) throws Exception { + XmlRenderer renderer = new XmlRenderer(); + renderer.init(); ByteArrayOutputStream bs = new ByteArrayOutputStream(); - ListenableFuture<Boolean> f = d.render(bs, r, null, null); + ListenableFuture<Boolean> f = renderer.render(bs, result, null, null); assertTrue(f.get()); - String summary = Utf8.toString(bs.toByteArray()); + return Utf8.toString(bs.toByteArray()); + } - assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + - "<result total-hit-count=\"0\"", - summary.substring(0, 67) - ); - assertTrue(summary.contains("<meta type=\"context\">")); - assertTrue(summary.contains("<error code=\"18\">Internal server error.</error>")); - assertTrue(summary.contains("<hit type=\"grouphit\" relevancy=\"1.0\">")); - assertTrue(summary.contains("<hit type=\"summary\" relevancy=\"0.95\">")); - assertEquals(2, occurrences("<error ", summary)); - assertTrue(summary.length() > 1000); + private Result createResult(String sdName, String content, boolean bolding) { + Chain<Searcher> chain = createSearchChain(sdName, content); + Query query = new Query("?query=12"); + if ( ! bolding) + query = new Query("?query=12&bolding=false"); + Execution execution = createExecution(chain); + Result result = execution.search(query); + execution.fill(result); + return result; + } + + /** + * Creates a search chain which always returns a result with one hit containing information given in this + * + * @param sdName the search definition type of the returned hit + * @param content the content of the "dynteaser" field of the returned hit + */ + private Chain<Searcher> createSearchChain(String sdName, String content) { + JuniperSearcher searcher = new JuniperSearcher(new ComponentId("test"), + new QrSearchersConfig(new QrSearchersConfig.Builder())); + + DocumentSourceSearcher docsource = new DocumentSourceSearcher(); + addResult(new Query("?query=12"), sdName, content, docsource); + addResult(new Query("?query=12&bolding=false"), sdName, content, docsource); + return new Chain<>(searcher, docsource); + } + + private void addResult(Query query, String sdName, String content, DocumentSourceSearcher docsource) { + Result r = new Result(query); + FastHit hit = new FastHit(); + hit.setId("http://abc.html"); + hit.setRelevance(new Relevance(1)); + hit.setField(Hit.SDDOCNAME_FIELD, sdName); + hit.setField("dynteaser", content); + r.hits().add(hit); + docsource.addResult(query, r); + } + + private Execution createExecution(Chain<Searcher> chain) { + Map<String, List<String>> clusters = new LinkedHashMap<>(); + Map<String, SearchDefinition> searchDefs = new LinkedHashMap<>(); + searchDefs.put("one", createSearchDefinitionOne()); + SearchDefinition union = new SearchDefinition("union"); + IndexModel indexModel = new IndexModel(clusters, searchDefs, union); + return new Execution(chain, Execution.Context.createContextStub(new IndexFacts(indexModel))); } - private int occurrences(String fragment, String string) { - int occurrences = 0; - int cursor = 0; - while ( -1 != (cursor = string.indexOf(fragment, cursor))) { - occurrences++; - cursor += fragment.length(); + private SearchDefinition createSearchDefinitionOne() { + SearchDefinition one = new SearchDefinition("one"); + + Index dynteaser = new Index("dynteaser"); + dynteaser.setDynamicSummary(true); + one.addIndex(dynteaser); + + Index bigteaser = new Index("bigteaser"); + dynteaser.setHighlightSummary(true); + one.addIndex(bigteaser); + + Index otherteaser = new Index("otherteaser"); + otherteaser.setDynamicSummary(true); + one.addIndex(otherteaser); + + return one; + } + + public static class NoopSearcher extends Searcher { + + public NoopSearcher(String name) { + super(new ComponentId(name)); } - return occurrences; + + @Override + public Result search(Query query, Execution execution) { + return execution.search(query); + } + } } diff --git a/container-search/src/test/java/com/yahoo/search/result/PositionsDataTestCase.java b/container-search/src/test/java/com/yahoo/search/result/PositionsDataTestCase.java index c77ff2eca3c..91c8acbab12 100644 --- a/container-search/src/test/java/com/yahoo/search/result/PositionsDataTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/PositionsDataTestCase.java @@ -5,8 +5,6 @@ import com.yahoo.data.access.simple.Value; import static org.junit.Assert.*; -import org.junit.After; -import org.junit.Before; import org.junit.Test; /** @@ -15,41 +13,43 @@ import org.junit.Test; public class PositionsDataTestCase { @Test - public void testRendering() { - Value.ArrayValue arr = new Value.ArrayValue(); - Value.ObjectValue p1 = new Value.ObjectValue(); - p1.put("x", new Value.LongValue(-122057174)); - p1.put("y", new Value.LongValue(37374821)); - p1.put("latlong", new Value.StringValue("N37.374821;W122.057174")); - arr.add(p1); + public void testRenderingOfSinglePosition() { + Value.ObjectValue pos = createPosition(-122057174, 37374821, "N37.374821;W122.057174"); - PositionsData pd = new PositionsData(arr.inspect()); + PositionsData pd = new PositionsData(pos.inspect()); - String rendered = pd.toXML(); - String correct = "<position x=\"-122057174\" y=\"37374821\" latlong=\"N37.374821;W122.057174\" />"; - assertEquals(correct, rendered); + assertXml("<position x=\"-122057174\" y=\"37374821\" latlong=\"N37.374821;W122.057174\" />", pd); + assertJson("{\"x\":-122057174,\"y\":37374821,\"latlong\":\"N37.374821;W122.057174\"}", pd); + } + + @Test + public void testRenderingOfMultiplePositions() { + Value.ArrayValue arr = new Value.ArrayValue(); + arr.add(createPosition(-122057174, 37374821, "N37.374821;W122.057174")); + arr.add(createPosition(3, -7, "S0.000007;E0.000003")); - rendered = pd.toJson(); - correct = "[{\"x\":-122057174,\"y\":37374821,\"latlong\":\"N37.374821;W122.057174\"}]"; - assertEquals(correct, rendered); + PositionsData pd = new PositionsData(arr.inspect()); - Value.ObjectValue p2 = new Value.ObjectValue(); - p2.put("x", new Value.LongValue(3)); - p2.put("y", new Value.LongValue(-7)); - p2.put("latlong", new Value.StringValue("S0.000007;E0.000003")); - arr.add(p2); + assertXml("<position x=\"-122057174\" y=\"37374821\" latlong=\"N37.374821;W122.057174\" />" + + "<position x=\"3\" y=\"-7\" latlong=\"S0.000007;E0.000003\" />", pd); + assertJson("[{\"x\":-122057174,\"y\":37374821,\"latlong\":\"N37.374821;W122.057174\"}," + + "{\"x\":3,\"y\":-7,\"latlong\":\"S0.000007;E0.000003\"}]", pd); + } - pd = new PositionsData(arr.inspect()); + private Value.ObjectValue createPosition(long x, long y, String latlong) { + Value.ObjectValue result = new Value.ObjectValue(); + result.put("x", new Value.LongValue(x)); + result.put("y", new Value.LongValue(y)); + result.put("latlong", new Value.StringValue(latlong)); + return result; + } - rendered = pd.toXML(); - correct = "<position x=\"-122057174\" y=\"37374821\" latlong=\"N37.374821;W122.057174\" />" + - "<position x=\"3\" y=\"-7\" latlong=\"S0.000007;E0.000003\" />"; - assertEquals(correct, rendered); + private void assertXml(String expected, PositionsData pd) { + assertEquals(expected, pd.toXML()); + } - rendered = pd.toJson(); - correct = "[{\"x\":-122057174,\"y\":37374821,\"latlong\":\"N37.374821;W122.057174\"}," + - "{\"x\":3,\"y\":-7,\"latlong\":\"S0.000007;E0.000003\"}]"; - assertEquals(correct, rendered); + private void assertJson(String expected, PositionsData pd) { + assertEquals(expected, pd.toJson()); } } diff --git a/container-search/src/test/java/com/yahoo/search/result/TemplatingTestCase.java b/container-search/src/test/java/com/yahoo/search/result/TemplatingTestCase.java deleted file mode 100644 index 13d0c64a0c2..00000000000 --- a/container-search/src/test/java/com/yahoo/search/result/TemplatingTestCase.java +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.result; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.Writer; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import com.yahoo.search.rendering.Renderer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.google.common.base.Splitter; -import com.yahoo.prelude.fastsearch.FastHit; -import com.yahoo.prelude.templates.UserTemplate; -import com.yahoo.prelude.templates.test.BoomTemplate; -import com.yahoo.search.Query; -import com.yahoo.search.Result; - -/** - * Control helper method for result rendering/result templates. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class TemplatingTestCase { - Result result; - - @Before - public void setUp() throws Exception { - Query q = new Query("/?query=a&presentation.format=nalle&offset=1&hits=5"); - result = new Result(q); - result.setTotalHitCount(1000L); - result.hits().add(new FastHit("http://localhost/1", .95)); - result.hits().add(new FastHit("http://localhost/2", .90)); - result.hits().add(new FastHit("http://localhost/3", .85)); - result.hits().add(new FastHit("http://localhost/4", .80)); - result.hits().add(new FastHit("http://localhost/5", .75)); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public final void testGetFirstHitNo() { - assertEquals(2, result.getTemplating().getFirstHitNo()); - } - - @Test - public final void testGetNextFirstHitNo() { - assertEquals(7, result.getTemplating().getNextFirstHitNo()); - result.getQuery().setHits(6); - assertEquals(0, result.getTemplating().getNextFirstHitNo()); - } - - @Test - public final void testGetNextLastHitNo() { - assertEquals(11, result.getTemplating().getNextLastHitNo()); - result.getQuery().setHits(6); - assertEquals(0, result.getTemplating().getNextLastHitNo()); - } - - @Test - public final void testGetLastHitNo() { - assertEquals(6, result.getTemplating().getLastHitNo()); - } - - @Test - public final void testGetPrevFirstHitNo() { - assertEquals(1, result.getTemplating().getPrevFirstHitNo()); - } - - @Test - public final void testGetPrevLastHitNo() { - assertEquals(1, result.getTemplating().getPrevLastHitNo()); - } - - @Test - public final void testGetNextResultURL() { - String next = result.getTemplating().getNextResultURL(); - Set<String> expectedParameters = new HashSet<>(Arrays.asList(new String[] { - "hits=5", - "query=a", - "presentation.format=nalle", - "offset=6" - })); - Set<String> actualParameters = new HashSet<>(); - Splitter s = Splitter.on("&"); - for (String parameter : s.split(next.substring(next.indexOf('?') + 1))) { - actualParameters.add(parameter); - } - assertEquals(expectedParameters, actualParameters); - } - - @Test - public final void testGetPreviousResultURL() { - String previous = result.getTemplating().getPreviousResultURL(); - Set<String> expectedParameters = new HashSet<>(Arrays.asList(new String[] { - "hits=5", - "query=a", - "presentation.format=nalle", - "offset=0" - })); - Set<String> actualParameters = new HashSet<>(); - Splitter s = Splitter.on("&"); - for (String parameter : s.split(previous.substring(previous.indexOf('?') + 1))) { - actualParameters.add(parameter); - } - assertEquals(expectedParameters, actualParameters); - } - - @Test - public final void testGetCurrentResultURL() { - String previous = result.getTemplating().getCurrentResultURL(); - Set<String> expectedParameters = new HashSet<>(Arrays.asList(new String[] { - "hits=5", - "query=a", - "presentation.format=nalle", - "offset=1" - })); - Set<String> actualParameters = new HashSet<>(); - Splitter s = Splitter.on("&"); - for (String parameter : s.split(previous.substring(previous.indexOf('?') + 1))) { - actualParameters.add(parameter); - } - assertEquals(expectedParameters, actualParameters); - } - - @Test - public final void testGetTemplates() { - @SuppressWarnings({ "unchecked", "deprecation" }) - UserTemplate<Writer> t = result.getTemplating().getTemplates(); - assertEquals("default", t.getName()); - } - - @SuppressWarnings("deprecation") - @Test - public final void testSetTemplates() { - result.getTemplating().setTemplates(new BoomTemplate("gnuff", "text/plain", "ISO-8859-15")); - @SuppressWarnings("unchecked") - UserTemplate<Writer> t = result.getTemplating().getTemplates(); - assertEquals("gnuff", t.getName()); - } - - private static class TestRenderer extends Renderer { - - @Override - public void render(Writer writer, Result result) throws IOException { - } - - @Override - public String getEncoding() { - return null; - } - - @Override - public String getMimeType() { - return null; - } - } - - @SuppressWarnings("deprecation") - @Test - public final void testUsesDefaultTemplate() { - assertTrue(result.getTemplating().usesDefaultTemplate()); - result.getTemplating().setRenderer(new TestRenderer()); - assertFalse(result.getTemplating().usesDefaultTemplate()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/result/test/ArrayOutputTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/ArrayOutputTestCase.java deleted file mode 100644 index 11d163373ac..00000000000 --- a/container-search/src/test/java/com/yahoo/search/result/test/ArrayOutputTestCase.java +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.result.test; - -import java.io.IOException; - -import com.yahoo.prelude.hitfield.XMLString; -import com.yahoo.prelude.templates.test.TilingTestCase; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.result.Hit; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author bratseth - */ -public class ArrayOutputTestCase { - - @Test - public void testArrayOutput() throws IOException { - Result r=new Result(new Query("?query=ignored")); - Hit hit=new Hit("test"); - hit.setField("phone",new XMLString("\n <item>408-555-1234</item>" + "\n <item>408-555-5678</item>\n ")); - r.hits().add(hit); - - String rendered = TilingTestCase.getRendered(r); - String[] lines= rendered.split("\n"); - assertEquals(" <field name=\"phone\">",lines[4]); - assertEquals(" <item>408-555-1234</item>",lines[5]); - assertEquals(" <item>408-555-5678</item>",lines[6]); - assertEquals(" </field>",lines[7]); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java b/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java index 15937e77899..7491e970b23 100644 --- a/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java @@ -50,6 +50,7 @@ public class ElapsedTimeTestCase { } public static class UselessSearcher extends Searcher { + public UselessSearcher(String name) { super(new ComponentId(name)); } @@ -58,9 +59,11 @@ public class ElapsedTimeTestCase { public Result search(Query query, Execution execution) { return execution.search(query); } + } private static class AlmostUselessSearcher extends Searcher { + AlmostUselessSearcher(String name) { super(new ComponentId(name)); } @@ -73,9 +76,11 @@ public class ElapsedTimeTestCase { r.hits().add(h); return r; } + } private static class NoForwardSearcher extends Searcher { + @Override public Result search(Query query, Execution execution) { Result r = new Result(query); @@ -84,6 +89,7 @@ public class ElapsedTimeTestCase { r.hits().add(h); return r; } + } private class TestingSearcher extends Searcher { diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index ed80c0bf256..a5c46fc7887 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -684,34 +684,34 @@ public class QueryTestCase { @Test public void testThatSessionIdIsUniquePerQuery() { Query q = new Query(); - assertNull(q.getSessionId(false)); - assertNull(q.getSessionId(false)); - SessionId s1 = q.getSessionId(true); + assertNull(q.getSessionId()); + assertNull(q.getSessionId()); + SessionId s1 = q.getSessionId("node-0"); assertNotNull(s1); - SessionId s2 = q.getSessionId(true); + SessionId s2 = q.getSessionId("node-0"); assertNotSame(s1, s2); assertEquals(s1, s2); assertEquals(s1.toString(), s2.toString()); Query q2 = new Query(); - assertNotEquals(q.getSessionId(false), q2.getSessionId(true)); - assertNotEquals(q.getSessionId(false).toString(), q2.getSessionId(true).toString()); + assertNotEquals(q.getSessionId(), q2.getSessionId("node-0")); + assertNotEquals(q.getSessionId().toString(), q2.getSessionId("node-0").toString()); } @Test public void testThatCloneGetANewSessionId() { Query q = new Query(); - q.getSessionId(true); + q.getSessionId("node-0"); Query clonedQ = q.clone(); - assertNull(clonedQ.getSessionId(false)); - assertNotEquals(q.getSessionId(false), clonedQ.getSessionId(true)); + assertNull(clonedQ.getSessionId()); + assertNotEquals(q.getSessionId(), clonedQ.getSessionId("node-0")); } @Test public void testThatSessionIdIsUniquePerRankProfilePerQuery() { Query q = new Query(); - SessionId s1 = q.getSessionId(true); + SessionId s1 = q.getSessionId("node-0"); q.getRanking().setProfile("my-profile"); - SessionId s2 = q.getSessionId(false); + SessionId s2 = q.getSessionId(); assertNotEquals(s1, s2); } @@ -719,14 +719,14 @@ public class QueryTestCase { public void testThatSessionIdIsNotSharedIfCreatedAfterClone() { Query q = new Query(); Query q2 = q.clone(); - assertNull(q.getSessionId(false)); - assertNull(q2.getSessionId(false)); + assertNull(q.getSessionId()); + assertNull(q2.getSessionId()); - assertNotNull(q.getSessionId(true)); - assertNull(q2.getSessionId(false)); + assertNotNull(q.getSessionId("node-0")); + assertNull(q2.getSessionId()); - assertNotNull(q2.getSessionId(true)); - assertNotEquals(q.getSessionId(false), q2.getSessionId(false)); + assertNotNull(q2.getSessionId("node-0")); + assertNotEquals(q.getSessionId(), q2.getSessionId()); } @Test diff --git a/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/VdsVisitorTestCase.java b/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/VdsVisitorTestCase.java index f75b78fd36f..d7fc53a6c00 100644 --- a/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/VdsVisitorTestCase.java +++ b/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/VdsVisitorTestCase.java @@ -100,7 +100,7 @@ public class VdsVisitorTestCase { private class QueryArguments { // General query parameters String query = "test"; - long timeout = 5; + double timeout = 0.5; int offset = 0; int hits = 10; int traceLevel = 0; @@ -114,7 +114,6 @@ public class VdsVisitorTestCase { String userId = null; String groupName = null; String selection = null; - boolean headersOnly = false; long from = 0; long to = 0; String loadTypeName = null; @@ -140,7 +139,6 @@ public class VdsVisitorTestCase { userId = "1234"; groupName = null; selection = null; - headersOnly = true; from = 123; to = 456; loadTypeName = "low"; @@ -155,7 +153,7 @@ public class VdsVisitorTestCase { private Query buildQuery(QueryArguments qa) throws Exception { StringBuilder queryString = new StringBuilder(); queryString.append("/?query=").append(qa.query); - if (qa.timeout != 5) { + if (qa.timeout != 0.5) { queryString.append("&timeout=").append(qa.timeout); } if (qa.offset != 0) { @@ -192,9 +190,6 @@ public class VdsVisitorTestCase { if (qa.selection != null) { queryString.append("&streaming.selection=").append(URLEncoder.encode(qa.selection, "UTF-8")); } - if (qa.headersOnly) { - queryString.append("&streaming.headersonly=").append(qa.headersOnly); - } if (qa.from != 0) { queryString.append("&streaming.fromtimestamp=").append(qa.from); } @@ -236,7 +231,6 @@ public class VdsVisitorTestCase { } else { assertEquals(docType + " and ( " + qa.selection + " )", params.getDocumentSelection()); } - assertEquals(qa.headersOnly, params.getVisitHeadersOnly()); assertEquals(qa.from, params.getFromTimestamp()); assertEquals(qa.to, params.getToTimestamp()); if (qa.loadTypeName != null && loadTypeSet.getNameMap().get(qa.loadTypeName) != null) { @@ -276,8 +270,8 @@ public class VdsVisitorTestCase { } // Verify parameters based only on query - assertEquals(qa.timeout*1000, params.getTimeoutMs()); - assertEquals(qa.timeout*1000, params.getSessionTimeoutMs()); + assertEquals(qa.timeout*1000, params.getTimeoutMs(),0.0000001); + assertEquals(qa.timeout*1000, params.getSessionTimeoutMs(), 0.0000001); assertEquals("searchvisitor", params.getVisitorLibrary()); assertEquals(Integer.MAX_VALUE, params.getMaxPending()); assertEquals(qa.traceLevel, params.getTraceLevel()); |