You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2017/12/15 22:20:31 UTC
lucene-solr:branch_7x: SOLR-11757: Tests:
SolrException.ignoreException use CopyOnWrite
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x 46fa2e45f -> 00c7568dc
SOLR-11757: Tests: SolrException.ignoreException use CopyOnWrite
(cherry picked from commit e441a99)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/00c7568d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/00c7568d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/00c7568d
Branch: refs/heads/branch_7x
Commit: 00c7568dc10c44b0827bb22c50d9fb216b175cc2
Parents: 46fa2e4
Author: David Smiley <ds...@apache.org>
Authored: Fri Dec 15 17:19:37 2017 -0500
Committer: David Smiley <ds...@apache.org>
Committed: Fri Dec 15 17:20:25 2017 -0500
----------------------------------------------------------------------
solr/CHANGES.txt | 4 ++++
.../org/apache/solr/common/SolrException.java | 8 +++++--
.../java/org/apache/solr/SolrTestCaseJ4.java | 25 +++++++++++---------
3 files changed, 24 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/00c7568d/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9e4a663..7d8ca67 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -48,8 +48,12 @@ Optimizations
Other Changes
----------------------
+
* SOLR-11575: Improve ref-guide solrj snippets via mock 'print()' method (Jason Gerlowski via hossman)
+* SOLR-11757: In tests, fix race condition on SolrException.ignoreException.
+ Also ensure we register "ignore_exception" in @BeforeClass (previously only @AfterClass) (David Smiley)
+
================== 7.2.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/00c7568d/solr/solrj/src/java/org/apache/solr/common/SolrException.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/SolrException.java b/solr/solrj/src/java/org/apache/solr/common/SolrException.java
index 22782b0..f73f5dd 100644
--- a/solr/solrj/src/java/org/apache/solr/common/SolrException.java
+++ b/solr/solrj/src/java/org/apache/solr/common/SolrException.java
@@ -191,16 +191,20 @@ public class SolrException extends RuntimeException {
}
- /** For test code - do not log exceptions that match any of the regular expressions in ignorePatterns */
+ /**
+ * For test code - do not log exceptions that match any of these regular expressions.
+ * A {@link java.util.concurrent.CopyOnWriteArraySet is recommended}.
+ */
public static Set<String> ignorePatterns;
/** Returns null if this exception does not match any ignore patterns, or a message string to use if it does. */
public static String doIgnore(Throwable t, String m) {
+ Set<String> ignorePatterns = SolrException.ignorePatterns; // guard against races, albeit unlikely
if (ignorePatterns == null || m == null) return null;
if (t != null && t instanceof AssertionError) return null;
for (String regex : ignorePatterns) {
- Pattern pattern = Pattern.compile(regex);
+ Pattern pattern = Pattern.compile(regex); // TODO why do we compile late; why not up-front?
Matcher matcher = pattern.matcher(m);
if (matcher.find()) return "Ignoring exception matching " + regex;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/00c7568d/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 449af4e..c089b24 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -49,15 +49,15 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
-import java.util.Map.Entry;
+import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.TimeUnit;
import com.carrotsearch.randomizedtesting.RandomizedContext;
@@ -65,7 +65,6 @@ import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.carrotsearch.randomizedtesting.TraceFormatting;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
-
import org.apache.commons.io.FileUtils;
import org.apache.http.client.HttpClient;
import org.apache.lucene.analysis.MockAnalyzer;
@@ -145,11 +144,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
+import static java.util.Objects.requireNonNull;
import static org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase;
import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
-import static java.util.Objects.requireNonNull;
-
/**
* A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
* invoke the {@link #initCore(String, String, String, String)} method.
@@ -260,6 +258,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
public static void setupTestCases() {
initialRootLogLevel = StartupLoggingUtils.getLogLevelString();
initClassLogLevels();
+ resetExceptionIgnores();
initCoreDataDir = createTempDir("init-core-data").toFile();
System.err.println("Creating dataDir: " + initCoreDataDir.getAbsolutePath());
@@ -589,8 +588,8 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
/** Causes an exception matching the regex pattern to not be logged. */
public static void ignoreException(String pattern) {
- if (SolrException.ignorePatterns == null)
- SolrException.ignorePatterns = new HashSet<>();
+ if (SolrException.ignorePatterns == null) // usually initialized already but in case not...
+ resetExceptionIgnores();
SolrException.ignorePatterns.add(pattern);
}
@@ -599,9 +598,13 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
SolrException.ignorePatterns.remove(pattern);
}
+ /**
+ * Clears all exception patterns, although keeps {@code "ignore_exception"}.
+ * {@link SolrTestCaseJ4} calls this in {@link AfterClass} so usually tests don't need to call this.
+ */
public static void resetExceptionIgnores() {
- SolrException.ignorePatterns = null;
- ignoreException("ignore_exception"); // always ignore "ignore_exception"
+ // CopyOnWrite for safety; see SOLR-11757
+ SolrException.ignorePatterns = new CopyOnWriteArraySet<>(Collections.singleton("ignore_exception"));
}
protected static String getClassName() {
@@ -2765,8 +2768,8 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
private static final Map<Class,String> private_RANDOMIZED_NUMERIC_FIELDTYPES = new HashMap<>();
/**
- * A Map of "primative" java "numeric" types and the string name of the <code>class</code> used in the
- * corrisponding schema fieldType declaration.
+ * A Map of "primitive" java "numeric" types and the string name of the <code>class</code> used in the
+ * corresponding schema fieldType declaration.
* <p>
* Example: <code>java.util.Date => "solr.DatePointField"</code>
* </p>