SOLR-8317: add responseHeader and response accessors to SolrQueryResponse. TestSolrQueryResponse tests for accessors.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1720822 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christine Poerschke 2015-12-18 16:39:35 +00:00
parent 8416038b6e
commit 6e4bb7c60f
3 changed files with 48 additions and 1 deletions

View File

@ -358,6 +358,8 @@ Other Changes
* SOLR-8419: TermVectorComponent for distributed search now requires a uniqueKey in the schema. Also, it no longer
returns "uniqueKeyField" in the response. (David Smiley)
* SOLR-8317: add responseHeader and response accessors to SolrQueryResponse. (Christine Poerschke)
================== 5.4.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -67,6 +67,8 @@ import org.apache.solr.search.SolrReturnFields;
*/
public class SolrQueryResponse {
public static final String NAME = "response";
private static final String RESPONSE_HEADER_KEY = "responseHeader";
private static final String RESPONSE_KEY = "response";
/**
* Container for user defined values
@ -171,13 +173,33 @@ public class SolrQueryResponse {
return err;
}
/** Set response header */
public void addResponseHeader(NamedList<Object> header) {
values.add(RESPONSE_HEADER_KEY, header);
}
/** Clear response header */
public void removeResponseHeader() {
values.remove(RESPONSE_HEADER_KEY);
}
/** Response header to be logged */
public NamedList<Object> getResponseHeader() {
@SuppressWarnings("unchecked")
SimpleOrderedMap<Object> header = (SimpleOrderedMap<Object>) values.get("responseHeader");
SimpleOrderedMap<Object> header = (SimpleOrderedMap<Object>) values.get(RESPONSE_HEADER_KEY);
return header;
}
/** Set response */
public void addResponse(Object response) {
values.add(RESPONSE_KEY, response);
}
/** Return response */
public Object getResponse() {
return values.get(RESPONSE_KEY);
}
/** Add a value to be logged.
*
* @param name name of the thing to log

View File

@ -63,6 +63,16 @@ public class TestSolrQueryResponse extends LuceneTestCase {
}
}
@Test
public void testResponse() throws Exception {
final SolrQueryResponse response = new SolrQueryResponse();
assertEquals("response initial value", null, response.getResponse());
final Object newValue = (random().nextBoolean()
? (random().nextBoolean() ? new String("answer") : new Integer(42)) : null);
response.addResponse(newValue);
assertEquals("response new value", newValue, response.getResponse());
}
@Test
public void testToLog() throws Exception {
final SolrQueryResponse response = new SolrQueryResponse();
@ -247,6 +257,19 @@ public class TestSolrQueryResponse extends LuceneTestCase {
assertEquals("exception new value", newValue, response.getException());
}
@Test
public void testResponseHeader() throws Exception {
final SolrQueryResponse response = new SolrQueryResponse();
assertEquals("responseHeader initially present", null, response.getResponseHeader());
final NamedList<Object> newValue = new SimpleOrderedMap<>();
newValue.add("key1", "value1");
response.add("key2", "value2");
response.addResponseHeader(newValue);
assertEquals("responseHeader new value", newValue, response.getResponseHeader());
response.removeResponseHeader();
assertEquals("responseHeader removed value", null, response.getResponseHeader());
}
@Test
public void testHttpCaching() throws Exception {
final SolrQueryResponse response = new SolrQueryResponse();