use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class TolerantUpdateProcessorTest method assertAddsSucceedWithErrors.
private void assertAddsSucceedWithErrors(String chain, final Collection<SolrInputDocument> docs, SolrParams requestParams, String... idsShouldFail) throws IOException {
SolrQueryResponse response = add(chain, requestParams, docs);
@SuppressWarnings("unchecked") List<SimpleOrderedMap<String>> errors = (List<SimpleOrderedMap<String>>) response.getResponseHeader().get("errors");
assertNotNull(errors);
assertEquals("number of errors", idsShouldFail.length, errors.size());
Set<String> addErrorIdsExpected = new HashSet<String>(Arrays.asList(idsShouldFail));
for (SimpleOrderedMap<String> err : errors) {
assertEquals("this method only expects 'add' errors", "ADD", err.get("type"));
String id = err.get("id");
assertNotNull("null err id", id);
assertTrue("unexpected id", addErrorIdsExpected.contains(id));
}
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class TolerantUpdateProcessorTest method add.
protected SolrQueryResponse add(final String chain, SolrParams requestParams, final Collection<SolrInputDocument> docs) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap<Object>());
if (requestParams == null) {
requestParams = new ModifiableSolrParams();
}
SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams);
UpdateRequestProcessor processor = null;
try {
processor = pc.createProcessor(req, rsp);
for (SolrInputDocument doc : docs) {
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = doc;
processor.processAdd(cmd);
}
processor.finish();
} finally {
IOUtils.closeQuietly(processor);
req.close();
}
return rsp;
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class UpdateProcessorTestBase 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
*/
protected SolrInputDocument processAdd(final String chain, final SolrParams requestParams, 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, requestParams);
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = docIn;
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
if (null != processor) {
// test chain might be empty or short circuited.
processor.processAdd(cmd);
}
return cmd.solrDoc;
} finally {
SolrRequestInfo.clearRequestInfo();
req.close();
}
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class UpdateProcessorTestBase method processDeleteById.
protected void processDeleteById(final String chain, String id) 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());
DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
cmd.setId(id);
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
try {
processor.processDelete(cmd);
} finally {
req.close();
}
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class UpdateRequestProcessorFactoryTest method testUpdateDistribChainSkipping.
public void testUpdateDistribChainSkipping() throws Exception {
// a key part of this test is verifying that LogUpdateProcessor is found in all chains because it
// is a @RunAlways processor -- but in order for that to work, we have to sanity check that the log
// level is at least "INFO" otherwise the factory won't even produce a processor and all our assertions
// are for nought. (see LogUpdateProcessorFactory.getInstance)
//
// TODO: maybe create a new mock Processor w/ @RunAlways annot if folks feel requiring INFO is evil.
assertTrue("Tests must be run with INFO level logging " + "otherwise LogUpdateProcessor isn't used and can't be tested.", log.isInfoEnabled());
final int EXPECTED_CHAIN_LENGTH = 5;
SolrCore core = h.getCore();
for (final String name : Arrays.asList("distrib-chain-explicit", "distrib-chain-implicit", "distrib-chain-noop")) {
UpdateRequestProcessor proc;
List<UpdateRequestProcessor> procs;
UpdateRequestProcessorChain chain = core.getUpdateProcessingChain(name);
assertNotNull(name, chain);
// either explicitly, or because of injection
assertEquals(name + " chain length: " + chain.toString(), EXPECTED_CHAIN_LENGTH, chain.getProcessors().size());
// test a basic (non distrib) chain
proc = chain.createProcessor(req(), new SolrQueryResponse());
procs = procToList(proc);
assertEquals(name + " procs size: " + procs.toString(), // -1 = NoOpDistributingUpdateProcessorFactory produces no processor
EXPECTED_CHAIN_LENGTH - ("distrib-chain-noop".equals(name) ? 1 : 0), procs.size());
// Custom comes first in all three of our chains
assertTrue(name + " first processor isn't a CustomUpdateRequestProcessor: " + procs.toString(), (// compare them both just because i'm going insane and the more checks the better
proc instanceof CustomUpdateRequestProcessor && procs.get(0) instanceof CustomUpdateRequestProcessor));
// Log should always come second in our chain.
assertNotNull(name + " proc.next is null", proc.next);
assertNotNull(name + " second proc is null", procs.get(1));
assertTrue(name + " second proc isn't LogUpdateProcessor: " + procs.toString(), (// compare them both just because i'm going insane and the more checks the better
proc.next instanceof LogUpdateProcessorFactory.LogUpdateProcessor && procs.get(1) instanceof LogUpdateProcessorFactory.LogUpdateProcessor));
// fetch the distributed version of this chain
proc = chain.createProcessor(req(DISTRIB_UPDATE_PARAM, "non_blank_value"), new SolrQueryResponse());
procs = procToList(proc);
assertNotNull(name + " (distrib) chain produced null proc", proc);
assertFalse(name + " (distrib) procs is empty", procs.isEmpty());
// for these 3 (distrib) chains, the first proc should always be LogUpdateProcessor
assertTrue(name + " (distrib) first proc should be LogUpdateProcessor because of @RunAllways: " + procs.toString(), (// compare them both just because i'm going insane and the more checks the better
proc instanceof LogUpdateProcessorFactory.LogUpdateProcessor && procs.get(0) instanceof LogUpdateProcessorFactory.LogUpdateProcessor));
// for these 3 (distrib) chains, the last proc should always be RunUpdateProcessor
assertTrue(name + " (distrib) last processor isn't a RunUpdateProcessor: " + procs.toString(), procs.get(procs.size() - 1) instanceof RunUpdateProcessor);
// either 1 proc was droped in distrib mode, or 1 for the "implicit" chain
assertEquals(name + " (distrib) chain has wrong length: " + procs.toString(), // -1 = distrib-chain-implicit: does RemoveBlank before distrib
EXPECTED_CHAIN_LENGTH - ("distrib-chain-explicit".equals(name) ? 1 : 2), procs.size());
}
}
Aggregations