-
Notifications
You must be signed in to change notification settings - Fork 860
SOLR-18373: remove NamedList.asShallowMap/get(String,int) and SolrParams.toNamedList #4761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9a6d0a2
a6e287b
ccfd4d3
672cf8a
19e1303
d161703
0e31ef7
604da4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1237,10 +1237,10 @@ protected void mergeIds(ResponseBuilder rb, ShardRequest sreq) { | |
| populateNextCursorMarkFromMergedShards(rb); | ||
|
|
||
| if (thereArePartialResults) { | ||
| rb.rsp | ||
| .getResponseHeader() | ||
| .asShallowMap() | ||
| .put(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY, Boolean.TRUE); | ||
| updateResponseHeader( | ||
| rb.rsp.getResponseHeader(), | ||
| SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY, | ||
| Boolean.TRUE); | ||
| } | ||
| if (segmentTerminatedEarly != null) { | ||
| final Object existingSegmentTerminatedEarly = | ||
|
|
@@ -1255,14 +1255,10 @@ protected void mergeIds(ResponseBuilder rb, ShardRequest sreq) { | |
| segmentTerminatedEarly); | ||
| } else if (!Boolean.TRUE.equals(existingSegmentTerminatedEarly) | ||
| && Boolean.TRUE.equals(segmentTerminatedEarly)) { | ||
| rb.rsp | ||
| .getResponseHeader() | ||
| .remove(SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY); | ||
| rb.rsp | ||
| .getResponseHeader() | ||
| .add( | ||
| SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY, | ||
| segmentTerminatedEarly); | ||
| updateResponseHeader( | ||
| rb.rsp.getResponseHeader(), | ||
| SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY, | ||
| segmentTerminatedEarly); | ||
| } | ||
| } | ||
| if (maxHitsTerminatedEarly) { | ||
|
|
@@ -1284,6 +1280,11 @@ protected void mergeIds(ResponseBuilder rb, ShardRequest sreq) { | |
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| protected static void updateResponseHeader(NamedList<Object> header, String key, Object value) { | ||
| ((SimpleOrderedMap<Object>) header).put(key, value); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you do this? I much prefer it as it was (assuming it worked)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It didn't work, that's why -- I reverted it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sigh... that really sucks because we're IMO making the code worse on the account of a test matter. I wonder how easy it might be to "just" change the return types of SolrQueryResponse in its own PR separately from this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened #4809 -- tightens
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you :-) In the mean time: Couldn't we update our mocks to return a SimpleOrderedMap? Just because the "documented contract" is a NamedList, doesn't mean Solr truly needs to support a plain NamedList from these methods on SolrQueryResponse. SQR is the base implementation; subclasses add to the instances returned by the base; don't replace / override (I think).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done -- fixed |
||
| protected void setResultIdsAndResponseDocs( | ||
| ResponseBuilder rb, | ||
| ShardDocQueue shardDocQueue, | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.solr.jersey; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.apache.solr.SolrTestCaseJ4; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.junit.Test; | ||
|
|
||
| /** Unit tests for {@link SolrJacksonMapper}'s NamedList/SimpleOrderedMap serialization. */ | ||
| public class SolrJacksonMapperTest extends SolrTestCaseJ4 { | ||
|
|
||
| @Test | ||
| public void testSimpleOrderedMapSerializesDirectlyWithoutRecursing() throws Exception { | ||
| final SimpleOrderedMap<Object> top = new SimpleOrderedMap<>(); | ||
| top.add("status", 0); | ||
|
|
||
| final NamedList<Object> nestedPlainNamedList = new NamedList<>(); | ||
| nestedPlainNamedList.add("nestedKey", "nestedVal"); | ||
| top.add("nested_plain_namedlist", nestedPlainNamedList); | ||
|
|
||
| final SimpleOrderedMap<Object> nestedSimpleOrderedMap = new SimpleOrderedMap<>(); | ||
| nestedSimpleOrderedMap.add("innerKey", 42); | ||
| top.add("nested_simple_ordered_map", nestedSimpleOrderedMap); | ||
|
|
||
| final ObjectMapper mapper = SolrJacksonMapper.getObjectMapper(); | ||
| final String json = mapper.writeValueAsString(top); | ||
|
|
||
| assertThat( | ||
| json, | ||
| equalTo( | ||
| "{\"status\":0," | ||
| + "\"nested_plain_namedlist\":{\"nestedKey\":\"nestedVal\"}," | ||
| + "\"nested_simple_ordered_map\":{\"innerKey\":42}}")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPlainNamedListStillSerializesViaAsMap() throws Exception { | ||
| final NamedList<Object> namedList = new NamedList<>(); | ||
| namedList.add("key", "value"); | ||
|
|
||
| final ObjectMapper mapper = SolrJacksonMapper.getObjectMapper(); | ||
| final String json = mapper.writeValueAsString(namedList); | ||
|
|
||
| assertThat(json, equalTo("{\"key\":\"value\"}")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSimpleOrderedMapOmitsNullValuesLikeNamedListDoes() throws Exception { | ||
| final NamedList<Object> namedListWithNull = new NamedList<>(); | ||
| namedListWithNull.add("present", "val"); | ||
| namedListWithNull.add("absent", null); | ||
|
|
||
| final SimpleOrderedMap<Object> somWithNull = new SimpleOrderedMap<>(); | ||
| somWithNull.add("present", "val"); | ||
| somWithNull.add("absent", null); | ||
|
|
||
| final ObjectMapper mapper = SolrJacksonMapper.getObjectMapper(); | ||
| assertThat(mapper.writeValueAsString(namedListWithNull), equalTo("{\"present\":\"val\"}")); | ||
| assertThat(mapper.writeValueAsString(somWithNull), equalTo("{\"present\":\"val\"}")); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.