use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class AtomicUpdateProcessorFactoryTest method testBasics.
public void testBasics() throws Exception {
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams().add("processor", "Atomic").add("Atomic.cat", "add").add("Atomic.title", "set").add("Atomic.count_i", "set").add("Atomic.name_s", "set").add("Atomic.multiDefault", "set").add("commit", "true")));
cmd.solrDoc = new SolrInputDocument();
cmd.solrDoc.addField("id", 1);
cmd.solrDoc.addField("cat", "human");
cmd.solrDoc.addField("title", "Mr");
cmd.solrDoc.addField("count_i", 20);
cmd.solrDoc.addField("name_s", "Virat");
cmd.solrDoc.addField("multiDefault", "Delhi");
AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
factory.inform(h.getCore());
factory.getInstance(cmd.getReq(), new SolrQueryResponse(), new DistributedUpdateProcessor(cmd.getReq(), new SolrQueryResponse(), new RunUpdateProcessor(cmd.getReq(), null))).processAdd(cmd);
assertU(commit());
assertQ("Check the total number of docs", req("q", "id:1"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "cat:human"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "title:Mr"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "count_i:20"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "name_s:Virat"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "multiDefault:Delhi"), "//result[@numFound=1]");
cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams().add("processor", "Atomic").add("Atomic.cat", "add").add("Atomic.title", "set").add("Atomic.count_i", "inc").add("Atomic.name_s", "remove").add("Atomic.multiDefault", "removeregex").add("commit", "true")));
cmd.solrDoc = new SolrInputDocument();
cmd.solrDoc.addField("id", 1);
cmd.solrDoc.addField("cat", "animal");
cmd.solrDoc.addField("title", "Dr");
cmd.solrDoc.addField("count_i", 20);
cmd.solrDoc.addField("name_s", "Virat");
cmd.solrDoc.addField("multiDefault", ".elh.");
factory = new AtomicUpdateProcessorFactory();
factory.inform(h.getCore());
factory.getInstance(cmd.getReq(), new SolrQueryResponse(), new DistributedUpdateProcessor(cmd.getReq(), new SolrQueryResponse(), new RunUpdateProcessor(cmd.getReq(), null))).processAdd(cmd);
assertU(commit());
assertQ("Check the total number of docs", req("q", "id:1"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "cat:human"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "cat:animal"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "title:Mr"), "//result[@numFound=0]");
assertQ("Check the total number of docs", req("q", "title:Dr"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "count_i:20"), "//result[@numFound=0]");
assertQ("Check the total number of docs", req("q", "count_i:40"), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "name_s:Virat"), "//result[@numFound=0]");
assertQ("Check the total number of docs", req("q", "multiDefault:Delhi"), "//result[@numFound=0]");
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class AtomicUpdateProcessorFactoryTest method testMultipleThreads.
public void testMultipleThreads() throws Exception {
clearIndex();
String[] strings = new String[5];
for (int i = 0; i < 5; i++) {
strings[i] = generateRandomString();
}
List<Thread> threads = new ArrayList<>(100);
//int_i
int finalCount = 0;
for (int i = 0; i < 100; i++) {
int index = random().nextInt(5);
Thread t = new Thread() {
@Override
public void run() {
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams().add("processor", "Atomic").add("Atomic.cat", "add").add("Atomic.int_i", "inc").add("commit", "true")));
cmd.solrDoc = new SolrInputDocument();
//hardcoded id=2
cmd.solrDoc.addField("id", 10);
cmd.solrDoc.addField("cat", strings[index]);
cmd.solrDoc.addField("int_i", index);
try {
AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
factory.inform(h.getCore());
factory.getInstance(cmd.getReq(), new SolrQueryResponse(), new DistributedUpdateProcessor(cmd.getReq(), new SolrQueryResponse(), new RunUpdateProcessor(cmd.getReq(), null))).processAdd(cmd);
} catch (IOException e) {
}
}
};
t.run();
threads.add(t);
//int_i
finalCount += index;
}
for (Thread thread : threads) {
thread.join();
}
assertU(commit());
assertQ("Check the total number of docs", req("q", "id:10"), "//result[@numFound=1]");
StringJoiner queryString = new StringJoiner(" ");
for (String string : strings) {
queryString.add(string);
}
assertQ("Check the total number of docs", req("q", "cat:" + queryString.toString()), "//result[@numFound=1]");
assertQ("Check the total number of docs", req("q", "int_i:" + finalCount), "//result[@numFound=1]");
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class AtomicUpdateProcessorFactoryTest method testWrongAtomicOpPassed.
public void testWrongAtomicOpPassed() throws Exception {
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams().add("processor", "Atomic").add("Atomic.cat", "delete").add("commit", "true")));
try {
AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
factory.inform(h.getCore());
factory.getInstance(cmd.getReq(), new SolrQueryResponse(), null).processAdd(cmd);
} catch (SolrException e) {
assertEquals("Unexpected param(s) for AtomicUpdateProcessor, invalid atomic op passed: 'delete'", e.getMessage());
}
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class AtomicUpdateProcessorFactoryTest method testNoUniqueIdPassed.
public void testNoUniqueIdPassed() throws Exception {
//TODO
AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams().add("processor", "Atomic").add("Atomic.cat", "add").add("commit", "true")));
cmd.solrDoc = new SolrInputDocument();
cmd.solrDoc.addField("title", 1);
try {
AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
factory.inform(h.getCore());
factory.getInstance(cmd.getReq(), new SolrQueryResponse(), null).processAdd(cmd);
} catch (SolrException e) {
assertEquals("Document passed with no unique field: 'id'", e.getMessage());
}
}
use of org.apache.solr.update.AddUpdateCommand in project lucene-solr by apache.
the class DefaultValueUpdateProcessorTest method processAdd.
/**
* Runs a document through the specified chain, and returns the final
* document used when the chain is completed (NOTE: some chains may
* modify the document in place
*/
SolrInputDocument processAdd(final String chain, final SolrInputDocument docIn) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = docIn;
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
processor.processAdd(cmd);
return cmd.solrDoc;
} finally {
SolrRequestInfo.clearRequestInfo();
req.close();
}
}
Aggregations