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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations