Search in sources :

Example 26 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class TestSolrQueryResponse method testSetHttpHeader.

@Test
public void testSetHttpHeader() {
    SolrQueryResponse response = new SolrQueryResponse();
    Iterator<Entry<String, String>> it = response.httpHeaders();
    assertFalse(it.hasNext());
    response.setHttpHeader("key1", "value1");
    it = response.httpHeaders();
    assertTrue(it.hasNext());
    Entry<String, String> entry = it.next();
    assertEquals("key1", entry.getKey());
    assertEquals("value1", entry.getValue());
    assertFalse(it.hasNext());
    response.setHttpHeader("key1", "value2");
    it = response.httpHeaders();
    assertTrue(it.hasNext());
    entry = it.next();
    assertEquals("key1", entry.getKey());
    assertEquals("value2", entry.getValue());
    assertFalse(it.hasNext());
    response.addHttpHeader("key1", "value3");
    response.setHttpHeader("key1", "value4");
    it = response.httpHeaders();
    assertTrue(it.hasNext());
    entry = it.next();
    assertEquals("key1", entry.getKey());
    assertEquals("value4", entry.getValue());
    assertFalse(it.hasNext());
    response.setHttpHeader("key2", "value5");
    it = response.httpHeaders();
    assertTrue(it.hasNext());
    entry = it.next();
    assertEquals("key1", entry.getKey());
    assertEquals("value4", entry.getValue());
    assertTrue(it.hasNext());
    entry = it.next();
    assertEquals("key2", entry.getKey());
    assertEquals("value5", entry.getValue());
    assertFalse(it.hasNext());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Entry(java.util.Map.Entry) Test(org.junit.Test)

Example 27 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class TestSolrQueryResponse method testValues.

@Test
public void testValues() throws Exception {
    final SolrQueryResponse response = new SolrQueryResponse();
    assertEquals("values initially not empty", 0, response.getValues().size());
    // initially empty, then add something
    final NamedList<Object> newValue = new SimpleOrderedMap<>();
    newValue.add("key1", "value1");
    response.setAllValues(newValue);
    assertEquals("values new value", newValue, response.getValues());
    response.add("key2", "value2");
    {
        final Iterator<Map.Entry<String, Object>> it = response.getValues().iterator();
        assertTrue(it.hasNext());
        final Map.Entry<String, Object> entry1 = it.next();
        assertEquals("key1", entry1.getKey());
        assertEquals("value1", entry1.getValue());
        assertTrue(it.hasNext());
        final Map.Entry<String, Object> entry2 = it.next();
        assertEquals("key2", entry2.getKey());
        assertEquals("value2", entry2.getValue());
        assertFalse(it.hasNext());
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) Test(org.junit.Test)

Example 28 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class TestSolrQueryResponse method testRemoveHttpHeaders.

@Test
public void testRemoveHttpHeaders() {
    SolrQueryResponse response = new SolrQueryResponse();
    Iterator<Entry<String, String>> it = response.httpHeaders();
    assertFalse(it.hasNext());
    response.addHttpHeader("key1", "value1");
    assertTrue(response.httpHeaders().hasNext());
    assertEquals(Arrays.asList("value1"), response.removeHttpHeaders("key1"));
    assertFalse(response.httpHeaders().hasNext());
    response.addHttpHeader("key1", "value2");
    response.addHttpHeader("key1", "value3");
    response.addHttpHeader("key2", "value4");
    assertTrue(response.httpHeaders().hasNext());
    assertEquals(Arrays.asList(new String[] { "value2", "value3" }), response.removeHttpHeaders("key1"));
    assertNull(response.removeHttpHeaders("key1"));
    assertEquals("key2", response.httpHeaders().next().getKey());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Entry(java.util.Map.Entry) Test(org.junit.Test)

Example 29 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class TestSolrQueryResponse method testRemoveHttpHeader.

@Test
public void testRemoveHttpHeader() {
    SolrQueryResponse response = new SolrQueryResponse();
    Iterator<Entry<String, String>> it = response.httpHeaders();
    assertFalse(it.hasNext());
    response.addHttpHeader("key1", "value1");
    assertTrue(response.httpHeaders().hasNext());
    assertEquals("value1", response.removeHttpHeader("key1"));
    assertFalse(response.httpHeaders().hasNext());
    response.addHttpHeader("key1", "value2");
    response.addHttpHeader("key1", "value3");
    response.addHttpHeader("key2", "value4");
    assertTrue(response.httpHeaders().hasNext());
    assertEquals("value2", response.removeHttpHeader("key1"));
    assertEquals("value3", response.httpHeaders().next().getValue());
    assertEquals("value3", response.removeHttpHeader("key1"));
    assertNull(response.removeHttpHeader("key1"));
    assertEquals("key2", response.httpHeaders().next().getKey());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Entry(java.util.Map.Entry) Test(org.junit.Test)

Example 30 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class TestSolrQueryResponse method testToLog.

@Test
public void testToLog() throws Exception {
    final SolrQueryResponse response = new SolrQueryResponse();
    assertEquals("toLog initially not empty", 0, response.getToLog().size());
    assertEquals("logid_only", response.getToLogAsString("logid_only"));
    // initially empty, then add something
    response.addToLog("key1", "value1");
    {
        final Iterator<Map.Entry<String, Object>> it = response.getToLog().iterator();
        assertTrue(it.hasNext());
        final Map.Entry<String, Object> entry1 = it.next();
        assertEquals("key1", entry1.getKey());
        assertEquals("value1", entry1.getValue());
        assertFalse(it.hasNext());
    }
    assertEquals("key1=value1", response.getToLogAsString(""));
    assertEquals("abc123 key1=value1", response.getToLogAsString("abc123"));
    // and then add something else
    response.addToLog("key2", "value2");
    {
        final Iterator<Map.Entry<String, Object>> it = response.getToLog().iterator();
        assertTrue(it.hasNext());
        final Map.Entry<String, Object> entry1 = it.next();
        assertEquals("key1", entry1.getKey());
        assertEquals("value1", entry1.getValue());
        assertTrue(it.hasNext());
        final Map.Entry<String, Object> entry2 = it.next();
        assertEquals("key2", entry2.getKey());
        assertEquals("value2", entry2.getValue());
        assertFalse(it.hasNext());
    }
    assertEquals("key1=value1 key2=value2", response.getToLogAsString(""));
    assertEquals("xyz789 key1=value1 key2=value2", response.getToLogAsString("xyz789"));
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)258 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)128 Test (org.junit.Test)100 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)80 NamedList (org.apache.solr.common.util.NamedList)68 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)58 SolrCore (org.apache.solr.core.SolrCore)52 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)40 SolrException (org.apache.solr.common.SolrException)32 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)29 ArrayList (java.util.ArrayList)26 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)22 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)21 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)20 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)20 JsonLoader (org.apache.solr.handler.loader.JsonLoader)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)16