diff options
author | Jon Bratseth <bratseth@oath.com> | 2019-05-16 09:47:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-16 09:47:44 +0200 |
commit | 509fa1c2e9bcdc5eac2f257ce0f83dcffe73e9ec (patch) | |
tree | c9b12a6665b2b020dbee5507c1e87496e1e95695 /container-search | |
parent | e4e963b9d923ad790115d41a8e8b226fefa47550 (diff) | |
parent | 2219ea79b5ac9584d503af3d6f61c859a470eb0c (diff) |
Merge pull request #9427 from vespa-engine/ollivir/more-protobuf-null-checking
Another null check and a minimal test
Diffstat (limited to 'container-search')
2 files changed, 35 insertions, 1 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java index 9404eb845bc..5ef4562f040 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java @@ -148,7 +148,9 @@ public class ProtobufSerialization { } MapConverter.convertMapStrings(featureMap, builder::addFeatureOverrides); MapConverter.convertMapTensors(featureMap, builder::addTensorFeatureOverrides); - MapConverter.convertStringMultiMap(query.getPresentation().getHighlight().getHighlightTerms(), builder::addHighlightTerms); + if (query.getPresentation().getHighlight() != null) { + MapConverter.convertStringMultiMap(query.getPresentation().getHighlight().getHighlightTerms(), builder::addHighlightTerms); + } mergeRankProperties(ranking, builder::addRankProperties, builder::addTensorRankProperties); } diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java new file mode 100644 index 00000000000..3882612ddef --- /dev/null +++ b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java @@ -0,0 +1,32 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.search.dispatch.rpc; + +import com.yahoo.document.GlobalId; +import com.yahoo.document.idstring.IdString; +import com.yahoo.prelude.fastsearch.FastHit; +import com.yahoo.search.Query; +import org.junit.Test; + +import java.io.IOException; +import java.util.Collections; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * @author ollivir + */ +public class ProtobufSerializationTest { + @Test + public void testDocsumSerialization() throws IOException { + Query q = new Query("search/?query=test&hits=10&offset=3"); + var builder = ProtobufSerialization.createDocsumRequestBuilder(q, "server", "summary", true); + builder.setTimeout(0); + var hit = new FastHit(); + hit.setGlobalId(new GlobalId(IdString.createIdString("doc:namespace:id"))); + var bytes = ProtobufSerialization.serializeDocsumRequest(builder, Collections.singletonList(hit)); + + assertThat(bytes.length, equalTo(41)); + } +} |