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 java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.apache.solr.core.SolrCore;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.AbstractSolrTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
@ -31,11 +34,22 @@ import org.junit.BeforeClass;
*/
public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
private static org.apache.log4j.Level SAVED_LEVEL = null; // SOLR-7603
@BeforeClass
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");
}
@AfterClass
public static void fixLogLevelAfterClass() throws Exception { // SOLR-7603
org.apache.log4j.LogManager.getRootLogger().setLevel(SAVED_LEVEL);
}
public void testConfiguration() throws Exception
{
@ -78,60 +92,76 @@ public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
"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", EXPECTED_CHAIN_LENGTH,
assertEquals(name + " chain length: " + chain.toString(), EXPECTED_CHAIN_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());
assertTrue(name + " first processor isn't a CustomUpdateRequestProcessor: "
+ proc.getClass().getName(),
proc instanceof CustomUpdateRequestProcessor);
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());
// 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"),
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",
proc);
assertFalse(name + " post distrib proc should not be a CustomUpdateRequestProcessor: "
+ proc.getClass().getName(),
proc instanceof CustomUpdateRequestProcessor);
// 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 LogUpdateProcessor
&& procs.get(0) instanceof LogUpdateProcessor));
int n=0;
boolean foundLog = false;
String seen = "";
for (;;) {
n++;
seen = seen + proc.toString() + ", ";
if (proc instanceof LogUpdateProcessor) {
foundLog = true;
}
if (null == proc.next) {
break;
} else {
proc = proc.next;
}
}
// 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 );
// some processors should have been dropped
assertTrue(name + " expected a distrib chain shorter then " + EXPECTED_CHAIN_LENGTH + " but got: " + n
+ " (" + seen +")",
n < EXPECTED_CHAIN_LENGTH );
// make sure the marker interface was successful in keeping the log processor even though it comes
// before distrib
assertTrue(name + " expected LogUpdateProcessor in chain due to @RunAllways, but not found: " + seen,
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);
// either 1 proc was droped in distrib mode, or 1 for the "implicit" chain
assertEquals(name + " (distrib) chain has wrong length: " + procs.toString(),
// -1 = all chains lose CustomUpdateRequestProcessorFactory
// -1 = distrib-chain-noop: NoOpDistributingUpdateProcessorFactory produces no processor
// -1 = distrib-chain-implicit: does RemoveBlank before distrib
EXPECTED_CHAIN_LENGTH - ( "distrib-chain-explicit".equals(name) ? 1 : 2),
procs.size());
}
}
/**
* 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;
}
}