Search in sources :

Example 16 with BufferingRequestProcessor

use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.

the class JavabinLoaderTest method doTestLastDocInBatchFlag.

protected void doTestLastDocInBatchFlag(int numDocsInBatch) throws Exception {
    List<SolrInputDocument> batch = new ArrayList<>(numDocsInBatch);
    for (int d = 0; d < numDocsInBatch; d++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.setField("id", String.valueOf(d));
        batch.add(doc);
    }
    UpdateRequest updateRequest = new UpdateRequest();
    if (batch.size() > 1) {
        updateRequest.add(batch);
    } else {
        updateRequest.add(batch.get(0));
    }
    // client-side SolrJ would do this ...
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    (new JavaBinUpdateRequestCodec()).marshal(updateRequest, os);
    // need to override the processAdd method b/c JavabinLoader calls
    // clear on the addCmd after it is passed on to the handler ... a simple clone will suffice for this test
    BufferingRequestProcessor mockUpdateProcessor = new BufferingRequestProcessor(null) {

        @Override
        public void processAdd(AddUpdateCommand cmd) throws IOException {
            addCommands.add((AddUpdateCommand) cmd.clone());
        }
    };
    SolrQueryRequest req = req();
    (new JavabinLoader()).load(req, new SolrQueryResponse(), new ContentStreamBase.ByteArrayStream(os.toByteArray(), "test"), mockUpdateProcessor);
    req.close();
    assertTrue(mockUpdateProcessor.addCommands.size() == numDocsInBatch);
    for (int i = 0; i < numDocsInBatch - 1; i++) // not last doc in batch
    assertFalse(mockUpdateProcessor.addCommands.get(i).isLastDocInBatch);
    // last doc should have the flag set
    assertTrue(mockUpdateProcessor.addCommands.get(batch.size() - 1).isLastDocInBatch);
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JavaBinUpdateRequestCodec(org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 17 with BufferingRequestProcessor

use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.

the class ExtractingRequestHandlerTest method testCommitWithin.

@Test
public void testCommitWithin() throws Exception {
    ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
    assertTrue("handler is null and it shouldn't be", handler != null);
    SolrQueryRequest req = req("literal.id", "one", ExtractingParams.RESOURCE_NAME, "extraction/version_control.txt", "commitWithin", "200");
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    ExtractingDocumentLoader loader = (ExtractingDocumentLoader) handler.newLoader(req, p);
    loader.load(req, rsp, new ContentStreamBase.FileStream(getFile("extraction/version_control.txt")), p);
    AddUpdateCommand add = p.addCommands.get(0);
    assertEquals(200, add.commitWithin);
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 18 with BufferingRequestProcessor

use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.

the class BinaryUpdateRequestHandlerTest method testRequestParams.

@Test
public void testRequestParams() throws Exception {
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    UpdateRequest ureq = new UpdateRequest();
    ureq.add(doc);
    ureq.setParam(UpdateParams.COMMIT_WITHIN, "100");
    ureq.setParam(UpdateParams.OVERWRITE, Boolean.toString(false));
    BinaryRequestWriter brw = new BinaryRequestWriter();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    SolrQueryResponse rsp = new SolrQueryResponse();
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(new NamedList());
    SolrQueryRequest req = req();
    ContentStreamLoader csl = handler.newLoader(req, p);
    csl.load(req, rsp, brw.getContentStream(ureq), p);
    AddUpdateCommand add = p.addCommands.get(0);
    System.out.println(add.solrDoc);
    assertEquals(false, add.overwrite);
    assertEquals(100, add.commitWithin);
    req.close();
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) NamedList(org.apache.solr.common.util.NamedList) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 19 with BufferingRequestProcessor

use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.

the class XsltUpdateRequestHandlerTest method testEntities.

@Test
public void testEntities() throws Exception {
    // use a binary file, so when it's loaded fail with XML eror:
    String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
    String xml = "<?xml version=\"1.0\"?>" + "<!DOCTYPE foo [" + // check that external entities are not resolved!
    "<!ENTITY bar SYSTEM \"" + file + "\">" + // but named entities should be
    "<!ENTITY wacky \"zzz\">" + "]>" + "<random>" + " &bar;" + " <document>" + "  <node name=\"id\" value=\"12345\"/>" + "  <node name=\"foo_s\" value=\"&wacky;\"/>" + " </document>" + "</random>";
    SolrQueryRequest req = req(CommonParams.TR, "xsl-update-handler-test.xsl");
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    XMLLoader loader = new XMLLoader().init(null);
    loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);
    AddUpdateCommand add = p.addCommands.get(0);
    assertEquals("12345", add.solrDoc.getField("id").getFirstValue());
    assertEquals("zzz", add.solrDoc.getField("foo_s").getFirstValue());
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 20 with BufferingRequestProcessor

use of org.apache.solr.update.processor.BufferingRequestProcessor in project lucene-solr by apache.

the class JsonLoaderTest method testDeleteSyntax.

// The delete syntax was both extended for simplification in 4.0
@Test
public void testDeleteSyntax() throws Exception {
    String str = "{'delete':10" + "\n ,'delete':'20'" + "\n ,'delete':['30','40']" + "\n ,'delete':{'id':50, '_version_':12345}" + "\n ,'delete':[{'id':60, '_version_':67890}, {'id':70, '_version_':77777}, {'query':'id:80', '_version_':88888}]" + "\n ,'delete':{'id':90, '_route_':'shard1', '_version_':88888}" + "\n}\n";
    str = str.replace('\'', '"');
    SolrQueryRequest req = req();
    SolrQueryResponse rsp = new SolrQueryResponse();
    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
    JsonLoader loader = new JsonLoader();
    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
    // DELETE COMMANDS
    assertEquals(9, p.deleteCommands.size());
    DeleteUpdateCommand delete = p.deleteCommands.get(0);
    assertEquals(delete.id, "10");
    assertEquals(delete.query, null);
    assertEquals(delete.commitWithin, -1);
    delete = p.deleteCommands.get(1);
    assertEquals(delete.id, "20");
    assertEquals(delete.query, null);
    assertEquals(delete.commitWithin, -1);
    delete = p.deleteCommands.get(2);
    assertEquals(delete.id, "30");
    assertEquals(delete.query, null);
    assertEquals(delete.commitWithin, -1);
    delete = p.deleteCommands.get(3);
    assertEquals(delete.id, "40");
    assertEquals(delete.query, null);
    assertEquals(delete.commitWithin, -1);
    delete = p.deleteCommands.get(4);
    assertEquals(delete.id, "50");
    assertEquals(delete.query, null);
    assertEquals(delete.getVersion(), 12345L);
    delete = p.deleteCommands.get(5);
    assertEquals(delete.id, "60");
    assertEquals(delete.query, null);
    assertEquals(delete.getVersion(), 67890L);
    delete = p.deleteCommands.get(6);
    assertEquals(delete.id, "70");
    assertEquals(delete.query, null);
    assertEquals(delete.getVersion(), 77777L);
    delete = p.deleteCommands.get(7);
    assertEquals(delete.id, null);
    assertEquals(delete.query, "id:80");
    assertEquals(delete.getVersion(), 88888L);
    delete = p.deleteCommands.get(8);
    assertEquals(delete.id, "90");
    assertEquals(delete.query, null);
    assertEquals(delete.getRoute(), "shard1");
    assertEquals(delete.getVersion(), 88888L);
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) JsonLoader(org.apache.solr.handler.loader.JsonLoader) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Aggregations

SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)24 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)24 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)21 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)19 SolrInputDocument (org.apache.solr.common.SolrInputDocument)17 JsonLoader (org.apache.solr.handler.loader.JsonLoader)17 Test (org.junit.Test)15 SolrInputField (org.apache.solr.common.SolrInputField)11 XMLLoader (org.apache.solr.handler.loader.XMLLoader)3 Map (java.util.Map)2 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)2 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)2 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 UnaryOperator (java.util.function.UnaryOperator)1 BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)1 JavaBinUpdateRequestCodec (org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec)1 SolrException (org.apache.solr.common.SolrException)1