SOLR-7603: more test tweaks to protect ourselves from unexpected log levels in tests like the one introduced by SOLR-7408

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1682570 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2015-05-30 00:56:17 +00:00
parent 9cf98e784e
commit 405b29c886
2 changed files with 45 additions and 26 deletions

View File

@ -75,29 +75,37 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {
}
public void testConcurrentCreateAndDeleteOverTheSameConfig() {
Logger.getLogger("org.apache.solr").setLevel(Level.WARN);
final String configName = "testconfig";
final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile();
uploadConfig(configDir, configName); // upload config once, to be used by all collections
final SolrClient solrClient = new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final AtomicReference<Exception> failure = new AtomicReference<>();
final int timeToRunSec = 30;
final Thread[] threads = new Thread[2];
for (int i = 0; i < threads.length; i++) {
final String collectionName = "collection" + i;
threads[i] = new CreateDeleteCollectionThread("create-delete-" + i, collectionName, configName,
timeToRunSec, solrClient, failure);
}
startAll(threads);
joinAll(threads);
assertNull("concurrent create and delete collection failed: " + failure.get(), failure.get());
// TODO: no idea what this test needs to override the level, but regardless of reason it should
// reset when it's done.
final Logger logger = Logger.getLogger("org.apache.solr");
final Level SAVED_LEVEL = logger.getLevel();
try {
solrClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
logger.setLevel(Level.WARN);
final String configName = "testconfig";
final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile();
uploadConfig(configDir, configName); // upload config once, to be used by all collections
final SolrClient solrClient = new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final AtomicReference<Exception> failure = new AtomicReference<>();
final int timeToRunSec = 30;
final Thread[] threads = new Thread[2];
for (int i = 0; i < threads.length; i++) {
final String collectionName = "collection" + i;
threads[i] = new CreateDeleteCollectionThread("create-delete-" + i, collectionName, configName,
timeToRunSec, solrClient, failure);
}
startAll(threads);
joinAll(threads);
assertNull("concurrent create and delete collection failed: " + failure.get(), failure.get());
try {
solrClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
} finally {
logger.setLevel(SAVED_LEVEL);
}
}
@ -222,4 +230,4 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {
}
}
}

View File

@ -34,12 +34,12 @@ import org.junit.BeforeClass;
*/
public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
private static org.apache.log4j.Level SAVED_LEVEL = null; // SOLR-7603
private static org.apache.log4j.Level SAVED_LEVEL = null; // SOLR-7603 - remove
@BeforeClass
public static void beforeClass() throws Exception {
// SOLR-7603
// SOLR-7603 - remove
SAVED_LEVEL = org.apache.log4j.LogManager.getRootLogger().getLevel();
org.apache.log4j.LogManager.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG);
@ -47,7 +47,7 @@ public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
}
@AfterClass
public static void fixLogLevelAfterClass() throws Exception { // SOLR-7603
public static void fixLogLevelAfterClass() throws Exception { // SOLR-7603 - remove
org.apache.log4j.LogManager.getRootLogger().setLevel(SAVED_LEVEL);
}
@ -85,6 +85,16 @@ public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
public void testUpdateDistribChainSkipping() throws Exception {
// a key part of this test is verifying that LogUpdateProcessor is found in all chains because it
// is a @RunAllways 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.",
LogUpdateProcessor.log.isInfoEnabled());
final int EXPECTED_CHAIN_LENGTH = 5;
SolrCore core = h.getCore();
for (final String name : Arrays.asList("distrib-chain-explicit",
@ -165,3 +175,4 @@ public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
return result;
}
}