Make ESTestCase resilient to initialization errors.
This commit is contained in:
parent
f80165c374
commit
2d81750a13
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.SuppressLoggerChecks;
|
|||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
|
@ -63,7 +64,7 @@ public class DeprecationLogger {
|
|||
* @throws IllegalStateException if this {@code threadContext} has already been set
|
||||
*/
|
||||
public static void setThreadContext(ThreadContext threadContext) {
|
||||
assert threadContext != null;
|
||||
Objects.requireNonNull(threadContext, "Cannot register a null ThreadContext");
|
||||
|
||||
// add returning false means it _did_ have it already
|
||||
if (THREAD_CONTEXT.add(threadContext) == false) {
|
||||
|
|
|
@ -255,6 +255,7 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|||
@Before
|
||||
public final void before() {
|
||||
logger.info("[{}]: before test", getTestName());
|
||||
assertNull("Thread context initialized twice", threadContext);
|
||||
if (enableWarningsCheck()) {
|
||||
this.threadContext = new ThreadContext(Settings.EMPTY);
|
||||
DeprecationLogger.setThreadContext(threadContext);
|
||||
|
@ -272,8 +273,13 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|||
@After
|
||||
public final void after() throws Exception {
|
||||
checkStaticState();
|
||||
if (enableWarningsCheck()) {
|
||||
// We check threadContext != null rather than enableWarningsCheck()
|
||||
// because after methods are still called in the event that before
|
||||
// methods failed, in which case threadContext might not have been
|
||||
// initialized
|
||||
if (threadContext != null) {
|
||||
ensureNoWarnings();
|
||||
threadContext = null;
|
||||
}
|
||||
ensureAllSearchContextsReleased();
|
||||
ensureCheckIndexPassed();
|
||||
|
|
Loading…
Reference in New Issue