SOLR-7603: more detail in asserts, and more asserts on the initial chain (before looking at the distributed version) to try and figure out WTF is going on here

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1682564 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2015-05-29 22:55:53 +00:00
parent f35ca87130
commit 9cf98e784e
1 changed files with 69 additions and 39 deletions

View File

@ -20,10 +20,13 @@ package org.apache.solr.update.processor;
import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM; import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
import java.util.Arrays; import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.util.AbstractSolrTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
/** /**
@ -31,11 +34,22 @@ import org.junit.BeforeClass;
*/ */
public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase { public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
private static org.apache.log4j.Level SAVED_LEVEL = null; // SOLR-7603
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
// SOLR-7603
SAVED_LEVEL = org.apache.log4j.LogManager.getRootLogger().getLevel();
org.apache.log4j.LogManager.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG);
initCore("solrconfig-transformers.xml", "schema.xml"); initCore("solrconfig-transformers.xml", "schema.xml");
} }
@AfterClass
public static void fixLogLevelAfterClass() throws Exception { // SOLR-7603
org.apache.log4j.LogManager.getRootLogger().setLevel(SAVED_LEVEL);
}
public void testConfiguration() throws Exception public void testConfiguration() throws Exception
{ {
@ -78,60 +92,76 @@ public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
"distrib-chain-noop")) { "distrib-chain-noop")) {
UpdateRequestProcessor proc; UpdateRequestProcessor proc;
List<UpdateRequestProcessor> procs;
UpdateRequestProcessorChain chain = core.getUpdateProcessingChain(name); UpdateRequestProcessorChain chain = core.getUpdateProcessingChain(name);
assertNotNull(name, chain); assertNotNull(name, chain);
// either explicitly, or because of injection // either explicitly, or because of injection
assertEquals(name + " chain length", EXPECTED_CHAIN_LENGTH, assertEquals(name + " chain length: " + chain.toString(), EXPECTED_CHAIN_LENGTH,
chain.getFactories().length); chain.getFactories().length);
// Custom comes first in all three of our chains // test a basic (non distrib) chain
proc = chain.createProcessor(req(), new SolrQueryResponse()); proc = chain.createProcessor(req(), new SolrQueryResponse());
assertTrue(name + " first processor isn't a CustomUpdateRequestProcessor: " procs = procToList(proc);
+ proc.getClass().getName(), assertEquals(name + " procs size: " + procs.toString(),
proc instanceof CustomUpdateRequestProcessor); // -1 = NoOpDistributingUpdateProcessorFactory produces no processor
EXPECTED_CHAIN_LENGTH - ("distrib-chain-noop".equals(name) ? 1 : 0),
procs.size());
// varies depending on chain, but definitely shouldn't be Custom // 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 LogUpdateProcessor
&& procs.get(1) instanceof LogUpdateProcessor));
// fetch the distributed version of this chain
proc = chain.createProcessor(req(DISTRIB_UPDATE_PARAM, "non_blank_value"), proc = chain.createProcessor(req(DISTRIB_UPDATE_PARAM, "non_blank_value"),
new SolrQueryResponse()); new SolrQueryResponse());
procs = procToList(proc);
assertNotNull(name + " (distrib) chain produced null proc", proc);
assertFalse(name + " (distrib) procs is empty", procs.isEmpty());
assertNotNull(name + " distrib chain had no proc's in it", // for these 3 (distrib) chains, the first proc should always be LogUpdateProcessor
proc); assertTrue(name + " (distrib) first proc should be LogUpdateProcessor because of @RunAllways: "
assertFalse(name + " post distrib proc should not be a CustomUpdateRequestProcessor: " + procs.toString(),
+ proc.getClass().getName(), ( // compare them both just because i'm going insane and the more checks the better
proc instanceof CustomUpdateRequestProcessor); proc instanceof LogUpdateProcessor
&& procs.get(0) instanceof LogUpdateProcessor));
int n=0; // for these 3 (distrib) chains, the last proc should always be RunUpdateProcessor
boolean foundLog = false; assertTrue(name + " (distrib) last processor isn't a RunUpdateProcessor: " + procs.toString(),
String seen = ""; procs.get(procs.size()-1) instanceof RunUpdateProcessor );
for (;;) {
n++;
seen = seen + proc.toString() + ", ";
if (proc instanceof LogUpdateProcessor) {
foundLog = true;
}
if (null == proc.next) {
break;
} else {
proc = proc.next;
}
}
// some processors should have been dropped // either 1 proc was droped in distrib mode, or 1 for the "implicit" chain
assertTrue(name + " expected a distrib chain shorter then " + EXPECTED_CHAIN_LENGTH + " but got: " + n assertEquals(name + " (distrib) chain has wrong length: " + procs.toString(),
+ " (" + seen +")", // -1 = all chains lose CustomUpdateRequestProcessorFactory
n < EXPECTED_CHAIN_LENGTH ); // -1 = distrib-chain-noop: NoOpDistributingUpdateProcessorFactory produces no processor
// make sure the marker interface was successful in keeping the log processor even though it comes // -1 = distrib-chain-implicit: does RemoveBlank before distrib
// before distrib EXPECTED_CHAIN_LENGTH - ( "distrib-chain-explicit".equals(name) ? 1 : 2),
assertTrue(name + " expected LogUpdateProcessor in chain due to @RunAllways, but not found: " + seen, procs.size());
foundLog );
// all of these (shortened) distrib chains should still end with RunUpdateprocessor
assertTrue(name + " last processor isn't a RunUpdateProcessor: " + proc.getClass().getName(),
proc instanceof RunUpdateProcessor);
} }
} }
/**
* walks the "next" values of the proc building up a List of the procs for easier testing
*/
public static List<UpdateRequestProcessor> procToList(UpdateRequestProcessor proc) {
List<UpdateRequestProcessor> result = new ArrayList<UpdateRequestProcessor>(7);
while (null != proc) {
result.add(proc);
proc = proc.next;
}
return result;
}
} }