Search in sources :

Example 31 with SolrQueryResponse

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

the class TestSolrQueryResponse method testReturnFields.

@Test
public void testReturnFields() throws Exception {
    final SolrQueryResponse response = new SolrQueryResponse();
    final ReturnFields defaultReturnFields = new SolrReturnFields();
    assertEquals("returnFields initial value", defaultReturnFields.toString(), response.getReturnFields().toString());
    final SolrReturnFields newValue = new SolrReturnFields((random().nextBoolean() ? SolrReturnFields.SCORE : "value"), null);
    response.setReturnFields(newValue);
    assertEquals("returnFields new value", newValue.toString(), response.getReturnFields().toString());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrReturnFields(org.apache.solr.search.SolrReturnFields) ReturnFields(org.apache.solr.search.ReturnFields) SolrReturnFields(org.apache.solr.search.SolrReturnFields) Test(org.junit.Test)

Example 32 with SolrQueryResponse

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

the class TestSolrQueryResponse method testResponse.

@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() ? "answer" : Integer.valueOf(42)) : null);
    response.addResponse(newValue);
    assertEquals("response new value", newValue, response.getResponse());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Test(org.junit.Test)

Example 33 with SolrQueryResponse

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

the class TestSolrQueryResponse method testException.

@Test
public void testException() throws Exception {
    final SolrQueryResponse response = new SolrQueryResponse();
    assertEquals("exception initial value", null, response.getException());
    final Exception newValue = (random().nextBoolean() ? (random().nextBoolean() ? new ArithmeticException() : new IOException()) : null);
    response.setException(newValue);
    assertEquals("exception new value", newValue, response.getException());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) ArithmeticException(java.lang.ArithmeticException) IOException(java.io.IOException) IOException(java.io.IOException) ArithmeticException(java.lang.ArithmeticException) Test(org.junit.Test)

Example 34 with SolrQueryResponse

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

the class HardAutoCommitTest method testCommitWithin.

public void testCommitWithin() throws Exception {
    SolrCore core = h.getCore();
    NewSearcherListener trigger = new NewSearcherListener();
    core.registerNewSearcherListener(trigger);
    DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
    CommitTracker tracker = updater.commitTracker;
    tracker.setTimeUpperBound(0);
    tracker.setDocsUpperBound(-1);
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
    // Add a single document with commitWithin == 2 second
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    req.setContentStreams(AutoCommitTest.toContentStreams(adoc(2000, "id", "529", "field_t", "what's inside?", "subject", "info"), null));
    trigger.reset();
    handler.handleRequest(req, rsp);
    // Check it isn't in the index
    assertQ("shouldn't find any", req("id:529"), "//result[@numFound=0]");
    // Wait longer than the commitWithin time
    assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
    // Add one document without commitWithin
    req.setContentStreams(AutoCommitTest.toContentStreams(adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null));
    trigger.reset();
    handler.handleRequest(req, rsp);
    // Check it isn't in the index
    assertQ("shouldn't find any", req("id:530"), "//result[@numFound=0]");
    // Delete one document with commitWithin
    trigger.pause();
    req.setContentStreams(AutoCommitTest.toContentStreams(delI("529", "commitWithin", "1000"), null));
    trigger.reset();
    handler.handleRequest(req, rsp);
    // Now make sure we can find it
    assertQ("should find one", req("id:529"), "//result[@numFound=1]");
    trigger.unpause();
    // Wait for the commit to happen
    assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
    // Now we shouldn't find it
    assertQ("should find none", req("id:529"), "//result[@numFound=0]");
    // ... but we should find the new one
    assertQ("should find one", req("id:530"), "//result[@numFound=1]");
    trigger.reset();
    // now make the call 10 times really fast and make sure it 
    // only commits once
    req.setContentStreams(AutoCommitTest.toContentStreams(adoc(2000, "id", "500"), null));
    for (int i = 0; i < 10; i++) {
        handler.handleRequest(req, rsp);
    }
    assertQ("should not be there yet", req("id:500"), "//result[@numFound=0]");
    // the same for the delete
    req.setContentStreams(AutoCommitTest.toContentStreams(delI("530", "commitWithin", "1000"), null));
    for (int i = 0; i < 10; i++) {
        handler.handleRequest(req, rsp);
    }
    assertQ("should be there", req("id:530"), "//result[@numFound=1]");
    assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
    assertQ("should be there", req("id:500"), "//result[@numFound=1]");
    assertQ("should not be there", req("id:530"), "//result[@numFound=0]");
    assertEquals(3, tracker.getCommitCount());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler)

Example 35 with SolrQueryResponse

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

the class AutoCommitTest method testMaxTime.

public void testMaxTime() throws Exception {
    SolrCore core = h.getCore();
    NewSearcherListener trigger = new NewSearcherListener();
    core.registerNewSearcherListener(trigger);
    DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
    CommitTracker tracker = updater.softCommitTracker;
    // too low of a number can cause a slow host to commit before the test code checks that it
    // isn't there... causing a failure at "shouldn't find any"
    tracker.setTimeUpperBound(1500);
    tracker.setDocsUpperBound(-1);
    // updater.commitCallbacks.add(trigger);
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
    // Add a single document
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    req.setContentStreams(toContentStreams(adoc("id", "529", "field_t", "what's inside?", "subject", "info"), null));
    trigger.reset();
    handler.handleRequest(req, rsp);
    // Check it it is in the index
    assertQ("shouldn't find any", req("id:529"), "//result[@numFound=0]");
    // Wait longer than the autocommit time
    assertTrue(trigger.waitForNewSearcher(45000));
    trigger.reset();
    req.setContentStreams(toContentStreams(adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null));
    handler.handleRequest(req, rsp);
    // Now make sure we can find it
    assertQ("should find one", req("id:529"), "//result[@numFound=1]");
    // But not this one
    assertQ("should find none", req("id:530"), "//result[@numFound=0]");
    // Delete the document
    assertU(delI("529"));
    assertQ("deleted, but should still be there", req("id:529"), "//result[@numFound=1]");
    // Wait longer than the autocommit time
    assertTrue(trigger.waitForNewSearcher(30000));
    trigger.reset();
    req.setContentStreams(toContentStreams(adoc("id", "550", "field_t", "what's inside?", "subject", "info"), null));
    handler.handleRequest(req, rsp);
    assertEquals(2, tracker.getCommitCount());
    assertQ("deleted and time has passed", req("id:529"), "//result[@numFound=0]");
    // now make the call 10 times really fast and make sure it 
    // only commits once
    req.setContentStreams(toContentStreams(adoc("id", "500"), null));
    for (int i = 0; i < 10; i++) {
        handler.handleRequest(req, rsp);
    }
    assertQ("should not be there yet", req("id:500"), "//result[@numFound=0]");
    // Wait longer than the autocommit time
    assertTrue(trigger.waitForNewSearcher(45000));
    trigger.reset();
    req.setContentStreams(toContentStreams(adoc("id", "531", "field_t", "what's inside?", "subject", "info"), null));
    handler.handleRequest(req, rsp);
    assertEquals(3, tracker.getCommitCount());
    assertQ("now it should", req("id:500"), "//result[@numFound=1]");
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler)

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