diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-10-28 16:06:15 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-10-28 16:06:15 +0100 |
commit | 6376e0d4c2a6da939e68be55195e95369e0c3e20 (patch) | |
tree | 60ab90a0ad3391a2fc67ddea8a62bbd9ed8b5c40 /container-search | |
parent | 571d218c6fb6306ad780a9caff153974f2ac82a8 (diff) |
Add tests
Diffstat (limited to 'container-search')
9 files changed, 101 insertions, 17 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json index dcac62b38c6..c6d378bd64b 100644 --- a/container-search/abi-spec.json +++ b/container-search/abi-spec.json @@ -5526,6 +5526,7 @@ ], "methods": [ "public void <init>(com.yahoo.search.query.profile.QueryProfile)", + "public java.lang.String getSource()", "public synchronized void freeze()", "protected java.lang.Object localLookup(java.lang.String, com.yahoo.search.query.profile.DimensionBinding)", "protected java.lang.Boolean isLocalInstanceOverridable(java.lang.String)", @@ -5654,6 +5655,7 @@ ], "methods": [ "protected void <init>()", + "protected void <init>(java.lang.String)", "protected java.lang.Object checkAndConvertAssignment(java.lang.String, java.lang.Object, com.yahoo.search.query.profile.QueryProfileRegistry)", "protected com.yahoo.search.query.profile.QueryProfile createSubProfile(java.lang.String, com.yahoo.search.query.profile.DimensionBinding)", "public com.yahoo.search.query.profile.OverridableQueryProfile clone()", @@ -5676,6 +5678,8 @@ "methods": [ "public void <init>(com.yahoo.component.ComponentId)", "public void <init>(java.lang.String)", + "public void <init>(com.yahoo.component.ComponentId, java.lang.String)", + "public java.lang.String getSource()", "public com.yahoo.search.query.profile.types.QueryProfileType getType()", "public void setType(com.yahoo.search.query.profile.types.QueryProfileType)", "public com.yahoo.search.query.profile.QueryProfileVariants getVariants()", @@ -6007,6 +6011,7 @@ "public final java.util.Map listValues(java.lang.String, java.util.Map)", "public final java.util.Map listValues(com.yahoo.processing.request.CompoundName, java.util.Map)", "public java.util.Map listValues(com.yahoo.processing.request.CompoundName, java.util.Map, com.yahoo.processing.request.Properties)", + "public java.util.Map listValuesWithSources(com.yahoo.processing.request.CompoundName, java.util.Map, com.yahoo.processing.request.Properties)", "public final java.lang.Object get(java.lang.String)", "public final java.lang.Object get(java.lang.String, java.util.Map)", "public final java.lang.Object get(java.lang.String, java.util.Map, com.yahoo.processing.request.Properties)", @@ -6090,6 +6095,22 @@ ], "fields": [] }, + "com.yahoo.search.query.profile.compiled.ValueWithSource": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ + "public" + ], + "methods": [ + "public void <init>(java.lang.Object, java.lang.String, com.yahoo.search.query.profile.DimensionValues)", + "public java.lang.Object value()", + "public java.lang.String source()", + "public com.yahoo.search.query.profile.compiled.ValueWithSource withValue(java.lang.Object)", + "public java.util.Optional variant()", + "public java.lang.String toString()" + ], + "fields": [] + }, "com.yahoo.search.query.profile.types.FieldDescription": { "superClass": "java.lang.Object", "interfaces": [ diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java index 6886b53e1d4..f27500085e1 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java @@ -43,7 +43,9 @@ final class AllValuesQueryProfileVisitor extends PrefixQueryProfileVisitor { if (fullName.isEmpty()) return; // Avoid putting a non-leaf (subtree) root in the list if (values.containsKey(fullName.toString())) return; // The first value encountered has priority - values.put(fullName.toString(), new ValueWithSource(value, owner.getSource(), variant)); + values.put(fullName.toString(), new ValueWithSource(value, + owner == null ? "anonymous" : owner.getSource(), + variant)); } /** Returns the values resulting from this visiting */ diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java index e6af1311bc3..99f1e26b221 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/BackedOverridableQueryProfile.java @@ -33,10 +33,13 @@ public class BackedOverridableQueryProfile extends OverridableQueryProfile imple public BackedOverridableQueryProfile(QueryProfile backingProfile) { Validator.ensureNotNull("An overridable query profile must be backed by a real query profile",backingProfile); setType(backingProfile.getType()); - this.backingProfile=backingProfile; + this.backingProfile = backingProfile; } @Override + public String getSource() { return backingProfile.getSource(); } + + @Override public synchronized void freeze() { super.freeze(); backingProfile.freeze(); diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java index b70474371d4..9eb50c0f72e 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * An immutable set of dimension values. @@ -104,7 +105,9 @@ public class DimensionValues implements Comparable<DimensionValues> { } @Override - public String toString() { return Arrays.toString(values); } + public String toString() { + return "[" + Arrays.stream(values).map(value -> value == null ? "*" : value).collect(Collectors.joining(", ")) + "]"; + } public boolean isEmpty() { return this==empty; diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java index 325c85ac491..37940b813dc 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/OverridableQueryProfile.java @@ -17,7 +17,11 @@ public class OverridableQueryProfile extends QueryProfile { /** Creates an unbacked overridable query profile */ protected OverridableQueryProfile() { - super(ComponentId.createAnonymousComponentId(simpleClassName)); + this(""); + } + + protected OverridableQueryProfile(String sourceName) { + super(ComponentId.createAnonymousComponentId(simpleClassName), sourceName); } @Override @@ -31,7 +35,7 @@ public class OverridableQueryProfile extends QueryProfile { @Override protected QueryProfile createSubProfile(String name, DimensionBinding binding) { - return new OverridableQueryProfile(); // Nothing is set in this branch, so nothing to override, but need override checking + return new OverridableQueryProfile(getSource()); // Nothing is set in this branch, so nothing to override, but need override checking } /** Returns a clone of this which can be independently overridden */ diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java index 79426cbce3a..925d20903c6 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/ValueWithSource.java @@ -15,23 +15,23 @@ public class ValueWithSource { private final Object value; /** The source of the query profile having a value */ - private final String ownerSource; + private final String source; /** The dimension values specifying a variant in that profile, or null if it is not in a variant */ private final DimensionValues variant; - public ValueWithSource(Object value, String ownerSource, DimensionValues variant) { + public ValueWithSource(Object value, String source, DimensionValues variant) { this.value = value; - this.ownerSource = ownerSource; + this.source = source; this.variant = variant; } public Object value() { return value; } - public String ownerSource() { return ownerSource; } + public String source() { return source; } public ValueWithSource withValue(Object value) { - return new ValueWithSource(value, ownerSource, variant); + return new ValueWithSource(value, source, variant); } /** Returns the variant having this value, or empty if it's not in a variant */ @@ -40,7 +40,7 @@ public class ValueWithSource { @Override public String toString() { return value + - " (from query profile '" + ownerSource + "'" + + " (from query profile '" + source + "'" + ( variant != null ? " variant " + variant : "") + ")"; } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java index 5e2e018f375..46efb736918 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java @@ -3,16 +3,19 @@ package com.yahoo.search.query.profile.test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.processing.request.CompoundName; import com.yahoo.processing.request.Properties; import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileProperties; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.compiled.CompiledQueryProfile; +import com.yahoo.search.query.profile.compiled.ValueWithSource; import com.yahoo.yolean.trace.TraceNode; import org.junit.Test; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -500,9 +503,32 @@ public class QueryProfileTestCase { QueryProfile p = new QueryProfile("test"); p.set("a","a-value", null); p.set("a.b","a.b-value", null); - Map<String,Object> values = p.compile(null).listValues("a"); - assertEquals(1,values.size()); - assertEquals("a.b-value",values.get("b")); + Map<String, Object> values = p.compile(null).listValues("a"); + assertEquals(1, values.size()); + assertEquals("a.b-value", values.get("b")); + } + + @Test + public void testListingSources() { + QueryProfile p = new QueryProfile("test"); + p.set("a","a-value", null); + p.set("a.b","a.b-value", null); + + { + Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(new CompoundName(""), new HashMap<>(), null); + assertEquals(2, values.size()); + assertEquals("a-value", values.get("a").value()); + assertEquals("test", values.get("a").source()); + assertEquals("a.b-value", values.get("a.b").value()); + assertEquals("test", values.get("a.b").source()); + } + + { + Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(new CompoundName("a"), new HashMap<>(), null); + assertEquals(1, values.size()); + assertEquals("a.b-value", values.get("b").value()); + assertEquals("test", values.get("b").source()); + } } @Test diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java index 84326d9370d..aa1d1c243a0 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsCloneTestCase.java @@ -18,9 +18,6 @@ import static org.junit.Assert.assertEquals; */ public class QueryProfileVariantsCloneTestCase { - /** - * Test for Ticket 4882480. - */ @Test public void test_that_interior_and_leaf_values_on_a_path_are_preserved_when_cloning() { Map<String, String> dimensionBinding = createDimensionBinding("location", "norway"); 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 b4112b17c92..73b455c147b 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 @@ -3,6 +3,7 @@ package com.yahoo.search.query.profile.test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.processing.request.CompoundName; import com.yahoo.search.Query; import com.yahoo.search.query.Properties; import com.yahoo.search.query.profile.BackedOverridableQueryProfile; @@ -11,6 +12,7 @@ import com.yahoo.search.query.profile.QueryProfileProperties; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.compiled.CompiledQueryProfile; import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry; +import com.yahoo.search.query.profile.compiled.ValueWithSource; import com.yahoo.yolean.trace.TraceNode; import org.junit.Test; @@ -93,6 +95,32 @@ public class QueryProfileVariantsTestCase { assertEquals("default_value", new Query("?", cTest).properties().get("feed.main.streams")); assertEquals("variant_value", new Query("?x=x1&y=y1&z=z1", cTest).properties().get("feed.main.streams")); + + { + Map<String, ValueWithSource> values = cRegistry.findQueryProfile("test") + .listValuesWithSources(new CompoundName(""), + new HashMap<>(), + null); + assertEquals(1, values.size()); + assertEquals("default_value", values.get("feed.main.streams").value()); + assertEquals("referenced", values.get("feed.main.streams").source()); + assertTrue(values.get("feed.main.streams").variant().isEmpty()); + } + + { + Map<String, ValueWithSource> values = cRegistry.findQueryProfile("test") + .listValuesWithSources(new CompoundName(""), + toMap("x=x1", "y=y1", "z=z1"), + null); + assertEquals(2, values.size()); + assertEquals("variant_value", values.get("feed.main.streams").value()); + assertEquals("referenced", values.get("feed.main.streams").source()); + assertEquals("[x1, *, z1]", values.get("feed.main.streams").variant().get().toString()); + + assertEquals("otherValue", values.get("other").value()); + assertEquals("parent", values.get("other").source()); + assertEquals("[x1, y1]", values.get("other").variant().get().toString()); + } } @Test |