Search in sources :

Example 1 with SolrQueryRequestBase

use of org.apache.solr.request.SolrQueryRequestBase in project lucene-solr by apache.

the class UpdateParamsTest method testUpdateProcessorParamDeprecationRemoved.

/**
   * Tests that only update.chain and not update.processor works (SOLR-2105)
   */
public void testUpdateProcessorParamDeprecationRemoved() throws Exception {
    SolrCore core = h.getCore();
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
    params.getMap().put("update.processor", "nonexistant");
    // Add a single document
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    // First check that the old param behaves as it should
    try {
        handler.handleRequestBody(req, rsp);
        assertTrue("Old param update.processor should not have any effect anymore", true);
    } catch (Exception e) {
        assertFalse("Got wrong exception while testing update.chain", e.getMessage().equals("unknown UpdateRequestProcessorChain: nonexistant"));
    }
    // Then check that the new param behaves correctly
    params.getMap().remove("update.processor");
    params.getMap().put(UpdateParams.UPDATE_CHAIN, "nonexistant");
    req.setParams(params);
    try {
        handler.handleRequestBody(req, rsp);
        assertFalse("Faulty update.chain parameter not causing an error - i.e. it is not detected", true);
    } catch (Exception e) {
        assertEquals("Got wrong exception while testing update.chain", e.getMessage(), "unknown UpdateRequestProcessorChain: nonexistant");
    }
}
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 2 with SolrQueryRequestBase

use of org.apache.solr.request.SolrQueryRequestBase in project lucene-solr by apache.

the class DocumentAnalysisRequestHandlerTest method testCharsetOutsideDocument.

// This test should also test charset detection in UpdateRequestHandler,
// but the DocumentAnalysisRequestHandler is simplier to use/check.
@Test
public void testCharsetOutsideDocument() throws Exception {
    final byte[] xmlBytes = ("<docs>\r\n" + " <doc>\r\n" + "  <field name=\"id\">Müller</field>\r\n" + " </doc>" + "</docs>").getBytes(StandardCharsets.ISO_8859_1);
    // we declare a content stream with charset:
    final ContentStream cs = new ByteStream(xmlBytes, "application/xml; charset=ISO-8859-1");
    ModifiableSolrParams params = new ModifiableSolrParams();
    SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {

        @Override
        public Iterable<ContentStream> getContentStreams() {
            return Collections.singleton(cs);
        }
    };
    DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
    assertNotNull(request);
    final List<SolrInputDocument> documents = request.getDocuments();
    assertNotNull(documents);
    assertEquals(1, documents.size());
    SolrInputDocument doc = documents.get(0);
    assertEquals("Müller", doc.getField("id").getValue());
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) DocumentAnalysisRequest(org.apache.solr.client.solrj.request.DocumentAnalysisRequest) Test(org.junit.Test)

Example 3 with SolrQueryRequestBase

use of org.apache.solr.request.SolrQueryRequestBase in project lucene-solr by apache.

the class DocumentAnalysisRequestHandlerTest method testCharsetInDocument.

// This test should also test charset detection in UpdateRequestHandler,
// but the DocumentAnalysisRequestHandler is simplier to use/check.
@Test
public void testCharsetInDocument() throws Exception {
    final byte[] xmlBytes = ("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" + "<docs>\r\n" + " <doc>\r\n" + "  <field name=\"id\">Müller</field>\r\n" + " </doc>" + "</docs>").getBytes(StandardCharsets.ISO_8859_1);
    // we declare a content stream without charset:
    final ContentStream cs = new ByteStream(xmlBytes, "application/xml");
    ModifiableSolrParams params = new ModifiableSolrParams();
    SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {

        @Override
        public Iterable<ContentStream> getContentStreams() {
            return Collections.singleton(cs);
        }
    };
    DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
    assertNotNull(request);
    final List<SolrInputDocument> documents = request.getDocuments();
    assertNotNull(documents);
    assertEquals(1, documents.size());
    SolrInputDocument doc = documents.get(0);
    assertEquals("Müller", doc.getField("id").getValue());
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) DocumentAnalysisRequest(org.apache.solr.client.solrj.request.DocumentAnalysisRequest) Test(org.junit.Test)

Example 4 with SolrQueryRequestBase

use of org.apache.solr.request.SolrQueryRequestBase 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 5 with SolrQueryRequestBase

use of org.apache.solr.request.SolrQueryRequestBase 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

SolrQueryRequestBase (org.apache.solr.request.SolrQueryRequestBase)15 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)11 SolrCore (org.apache.solr.core.SolrCore)8 ContentStream (org.apache.solr.common.util.ContentStream)7 UpdateRequestHandler (org.apache.solr.handler.UpdateRequestHandler)7 MapSolrParams (org.apache.solr.common.params.MapSolrParams)6 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)5 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)5 ArrayList (java.util.ArrayList)4 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)4 Test (org.junit.Test)4 DocumentAnalysisRequest (org.apache.solr.client.solrj.request.DocumentAnalysisRequest)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 File (java.io.File)2 HashMap (java.util.HashMap)2 SolrException (org.apache.solr.common.SolrException)2 MultiMapSolrParams (org.apache.solr.common.params.MultiMapSolrParams)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1