From f8258e958e49488440ba09fb4626541ce3e0d418 Mon Sep 17 00:00:00 2001 From: Chris Hegarty <62058229+ChrisHegarty@users.noreply.github.com> Date: Fri, 17 Dec 2021 15:29:23 +0000 Subject: [PATCH] Tolerate benign log4j status messages in tests (#81851) Tolerate either 1) the absence or, 2) the denial, of the JNDI lookup class --- .../org/elasticsearch/test/ESTestCase.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 3fc37ed6ce2f3..b493abcbf9086 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -150,9 +150,13 @@ import static java.util.Collections.emptyMap; import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.emptyCollectionOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.startsWith; /** * Base testcase for randomized unit testing with Elasticsearch @@ -631,6 +635,15 @@ public void log(StatusData data) { }); } + // Tolerate the absence or otherwise denial of these specific lookup classes. + // At some future time, we should require the JDNI warning. + private static final List LOG_4J_MSG_PREFIXES = List.of( + "JNDI lookup class is not available because this JRE does not support JNDI. " + + "JNDI string lookups will not be available, continuing configuration.", + "JMX runtime input lookup class is not available because this JRE does not support JMX. " + + "JMX lookups will not be available, continuing configuration. " + ); + // separate method so that this can be checked again after suite scoped cluster is shut down protected static void checkStaticState() throws Exception { LeakTracker.INSTANCE.reportLeak(); @@ -644,7 +657,10 @@ protected static void checkStaticState() throws Exception { // StatusData instances to Strings as otherwise their toString output is useless assertThat( statusData.stream().map(status -> status.getMessage().getFormattedMessage()).collect(Collectors.toList()), - empty() + anyOf( + emptyCollectionOf(String.class), + contains(startsWith(LOG_4J_MSG_PREFIXES.get(0)), startsWith(LOG_4J_MSG_PREFIXES.get(1))) + ) ); } finally { // we clear the list so that status data from other tests do not interfere with tests within the same JVM