diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-12-13 08:34:42 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-12-13 08:34:42 +0100 |
commit | cf7cf81ea64c016e5dcc9032462624ddb4460842 (patch) | |
tree | 39d1d97aafa73bdb8ca5d290f1148b9dc9116fa1 /container-search/src/test/java/com/yahoo/search | |
parent | da72f32fa5bfcce81b6bcc8dbe717be0869bcc77 (diff) |
Revert "Merge pull request #20456 from vespa-engine/revert-20439-bratseth/zoneinfo-in-query-profile-context"
This reverts commit 2780822f7d1fc66ea2833b2b7aaa2b9cb74f5833, reversing
changes made to 8ff6429daf9a695f2fa5d45a8033c75fdadfcfe2.
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search')
3 files changed, 71 insertions, 9 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java b/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java index a6ae5f2b1b9..e1987aa50ca 100644 --- a/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java +++ b/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java @@ -186,7 +186,7 @@ public class SearchHandlerTest { RequestHandlerTestDriver.MockResponseHandler responseHandler = newDriver.sendRequest( "http://localhost/search/?yql=select%20*%20from%20foo%20where%20bar%20%3E%201453501295%27%3B"); responseHandler.readAll(); - assertThat(responseHandler.getStatus(), is(400)); + assertEquals(400, responseHandler.getStatus()); assertEquals(Request.RequestType.READ, responseHandler.getResponse().getRequestType()); } } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java index 231020c4fa5..3542e1413eb 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java @@ -1,6 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile.test; +import ai.vespa.cloud.ApplicationId; +import ai.vespa.cloud.Environment; +import ai.vespa.cloud.Zone; +import ai.vespa.cloud.ZoneInfo; +import com.yahoo.jdisc.application.Application; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.processing.request.CompoundName; @@ -1331,6 +1336,53 @@ public class QueryProfileVariantsTestCase { assertEquals("yahoo/alerts", cAlert.get("vertical.custid", toMap("entry=alert", "intl=us", "lang=en-US"))); } + @Test + public void testZoneInfoInContext() { + QueryProfileRegistry registry = new QueryProfileRegistry(); + QueryProfile profile = new QueryProfile("test"); + profile.setDimensions(new String[] { "environment", "region", "instance" }); + profile.set("value", "default", registry); + profile.set("value", "prod-region1-instance1", + toMap("environment=prod", "region=region1", "instance=instance1"), + registry); + profile.set("value", "prod-instance2", + toMap("environment=prod", "instance=instance2"), + registry); + profile.set("value", "prod-region3", + toMap("environment=prod", "region=region3"), + registry); + profile.set("value", "dev", + toMap("environment=dev"), + registry); + registry.register(profile); + + CompiledQueryProfileRegistry cRegistry = registry.compile(); + CompiledQueryProfile cTest = cRegistry.findQueryProfile("test"); + + assertValueForZone("default", ZoneInfo.defaultInfo(), cTest); + assertValueForZone("prod-region1-instance1", + new ZoneInfo(new ApplicationId("tenant1", "application1", "instance1"), + new Zone(Environment.prod, "region1")), + cTest); + assertValueForZone("prod-instance2", + new ZoneInfo(new ApplicationId("tenant2", "application2", "instance2"), + new Zone(Environment.prod, "region1")), + cTest); + assertValueForZone("prod-region3", + new ZoneInfo(new ApplicationId("tenant3", "application3", "instance3"), + new Zone(Environment.prod, "region3")), + cTest); + assertValueForZone("dev", + new ZoneInfo(new ApplicationId("tenant4", "application4", "instance4"), + new Zone(Environment.dev, "region4")), + cTest); + } + + private void assertValueForZone(String expected, ZoneInfo zoneInfo, CompiledQueryProfile cTest) { + assertEquals(expected, + new Query.Builder().setQueryProfile(cTest).setZoneInfo(zoneInfo).build().properties().get("value")); + } + private void assertGet(String expectedValue, String parameter, String[] dimensionValues, QueryProfile profile, CompiledQueryProfile cprofile) { Map<String,String> context=toMap(profile,dimensionValues); assertEquals("Looking up '" + parameter + "' for '" + Arrays.toString(dimensionValues) + "'",expectedValue,cprofile.get(parameter,context)); diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java index a642d14b368..d6e99ec3a44 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java @@ -5,6 +5,7 @@ import com.yahoo.config.search.IntConfig; import com.yahoo.config.search.StringConfig; import com.yahoo.container.core.config.HandlersConfigurerDi; import com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper; +import com.yahoo.lang.MutableInteger; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; @@ -38,6 +39,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertThat; @@ -129,7 +131,7 @@ public class SearchChainConfigurerTestCase { @Test public void testConfigurableSearcher() { - HandlersConfigurerTestWrapper configurer=new HandlersConfigurerTestWrapper("dir:" + testDir); + HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + testDir); SearchChain configurable = getSearchChainRegistryFrom(configurer).getComponent("configurable"); assertNotNull(configurable); @@ -137,9 +139,8 @@ public class SearchChainConfigurerTestCase { Searcher s = configurable.searchers().get(0); assertThat(s, instanceOf(ConfigurableSearcher.class)); ConfigurableSearcher searcher = (ConfigurableSearcher)s; - assertThat("Value from int.cfg file", searcher.intConfig.intVal(), is(7)); - assertThat("Value from string.cfg file", searcher.stringConfig.stringVal(), - is("com.yahoo.search.searchchain.config.test")); + assertEquals("Value from int.cfg file", 7, searcher.intConfig.intVal()); + assertEquals("Value from string.cfg file", "com.yahoo.search.searchchain.config.test", searcher.stringConfig.stringVal()); configurer.shutdown(); } @@ -342,7 +343,7 @@ public class SearchChainConfigurerTestCase { if (append) { Pattern p = Pattern.compile("^[a-z]+" + "\\[\\d+\\]\\.id (.+)"); BufferedReader reader = new BufferedReader(new InputStreamReader( - new FileInputStream(new File(componentsFile)), StandardCharsets.UTF_8)); + new FileInputStream(componentsFile), StandardCharsets.UTF_8)); while ((line = reader.readLine()) != null) { Matcher m = p.matcher(line); if (m.matches() && !m.group(1).equals(HandlersConfigurerDi.RegistriesHack.class.getName())) { @@ -353,7 +354,7 @@ public class SearchChainConfigurerTestCase { reader.close(); } BufferedReader reader = new BufferedReader(new InputStreamReader( - new FileInputStream(new File(configFile)), StandardCharsets.UTF_8)); + new FileInputStream(configFile), StandardCharsets.UTF_8)); Pattern component = Pattern.compile("^" + componentType + "\\[\\d+\\]\\.id (.+)"); while ((line = reader.readLine()) != null) { Matcher m = component.matcher(line); @@ -366,13 +367,22 @@ public class SearchChainConfigurerTestCase { buf.append("components[").append(i++).append("].id ").append(HandlersConfigurerDi.RegistriesHack.class.getName()).append("\n"); if (componentType.equals("components")) - buf.append("components[").append(i++).append("].id ").append(ExecutionFactory.class.getName()).append("\n"); + i = addStandardComponents(i, buf); buf.insert(0, "components["+i+"]\n"); - Writer writer = new OutputStreamWriter(new FileOutputStream(new File(componentsFile)), StandardCharsets.UTF_8); + Writer writer = new OutputStreamWriter(new FileOutputStream(componentsFile), StandardCharsets.UTF_8); writer.write(buf.toString()); writer.flush(); writer.close(); } + private static int addStandardComponents(int i, StringBuilder builder) { + addComponent(ExecutionFactory.class.getName(), i++, builder); + return i; + } + + private static void addComponent(String component, int i, StringBuilder builder) { + builder.append("components[").append(i).append("].id ").append(component).append("\n"); + } + } |