mirror of https://github.com/apache/lucene.git
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:
parent
8416038b6e
commit
6e4bb7c60f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue