diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-06-15 09:00:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-15 09:00:02 +0200 |
commit | 051d0a60c4948cb022a23888bad3841de3011e92 (patch) | |
tree | 4eb007256c1be605a73135b0f6e793678ae207ae /container-search/src/test/java/com/yahoo | |
parent | 3c240626131ff7287448d41a8c86b4b6d5b58dd6 (diff) | |
parent | 2475842932c0bf9bc133619900c7c0ddbfda7326 (diff) |
Merge pull request #23080 from vespa-engine/bratseth/zone-context
Support zone context variants for native properties
Diffstat (limited to 'container-search/src/test/java/com/yahoo')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java | 69 |
1 files changed, 63 insertions, 6 deletions
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 3542e1413eb..3cf2949f33c 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 @@ -1359,33 +1359,90 @@ public class QueryProfileVariantsTestCase { CompiledQueryProfileRegistry cRegistry = registry.compile(); CompiledQueryProfile cTest = cRegistry.findQueryProfile("test"); - assertValueForZone("default", ZoneInfo.defaultInfo(), cTest); + assertValueForZone("default", ZoneInfo.defaultInfo(), null, cTest); assertValueForZone("prod-region1-instance1", new ZoneInfo(new ApplicationId("tenant1", "application1", "instance1"), new Zone(Environment.prod, "region1")), + null, cTest); assertValueForZone("prod-instance2", new ZoneInfo(new ApplicationId("tenant2", "application2", "instance2"), new Zone(Environment.prod, "region1")), + null, cTest); assertValueForZone("prod-region3", new ZoneInfo(new ApplicationId("tenant3", "application3", "instance3"), new Zone(Environment.prod, "region3")), + null, cTest); assertValueForZone("dev", new ZoneInfo(new ApplicationId("tenant4", "application4", "instance4"), new Zone(Environment.dev, "region4")), + null, cTest); } - private void assertValueForZone(String expected, ZoneInfo zoneInfo, CompiledQueryProfile cTest) { - assertEquals(expected, - new Query.Builder().setQueryProfile(cTest).setZoneInfo(zoneInfo).build().properties().get("value")); + @Test + public void testZoneInfoInContextWithUnoverridability() { + QueryProfileRegistry registry = new QueryProfileRegistry(); + QueryProfile profile = new QueryProfile("test"); + profile.setDimensions(new String[] { "instance", "environment", "region" }); + profile.set("value", "default", registry); + profile.set("value", "prod-beta", + toMap("environment=prod", "instance=beta"), + registry); + profile.setOverridable("value", false, toMap("environment=prod", "instance=beta")); + registry.register(profile); + + CompiledQueryProfileRegistry cRegistry = registry.compile(); + CompiledQueryProfile cTest = cRegistry.findQueryProfile("test"); + + assertValueForZone("prod-beta", + new ZoneInfo(new ApplicationId("tenant1", "application1", "beta"), + new Zone(Environment.prod, "region1")), + "fromRequest", + cTest); + } + + + private void assertValueForZone(String expected, ZoneInfo zoneInfo, String requestValue, CompiledQueryProfile cTest) { + var builder = new Query.Builder().setQueryProfile(cTest).setZoneInfo(zoneInfo); + if (requestValue != null) + builder.setRequestMap(Map.of("value", requestValue)); + assertEquals(expected, builder.build().properties().get("value")); + } + + @Test + public void testZoneInfoInContextSettingNativeProperty() { + QueryProfileRegistry registry = new QueryProfileRegistry(); + QueryProfile profile = new QueryProfile("test"); + profile.setDimensions(new String[] { "instance", "environment", "region" }); + profile.set("timeout", "0.3", + toMap("environment=prod", "instance=beta"), + registry); + registry.register(profile); + + CompiledQueryProfileRegistry cRegistry = registry.compile(); + CompiledQueryProfile cTest = cRegistry.findQueryProfile("test"); + + assertTimeoutForZone(300, + new ZoneInfo(new ApplicationId("tenant1", "application1", "beta"), + new Zone(Environment.prod, "region1")), + null, + cTest); + } + + private void assertTimeoutForZone(int expected, ZoneInfo zoneInfo, String requestValue, CompiledQueryProfile cTest) { + var builder = new Query.Builder().setQueryProfile(cTest).setZoneInfo(zoneInfo); + if (requestValue != null) + builder.setRequestMap(Map.of("timeout", requestValue)); + assertEquals(expected, builder.build().getTimeout()); } 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)); + Map<String, String> context = toMap(profile,dimensionValues); + assertEquals("Looking up '" + parameter + "' for '" + Arrays.toString(dimensionValues) + "'", + expectedValue, cprofile.get(parameter,context)); } public static Map<String,String> toMap(QueryProfile profile, String[] dimensionValues) { |