Skip to content

Commit cfbce64

Browse files
authored
[7.16] Tolerate benign log4j status messages in tests (#81851) (#81875)
1 parent 9983298 commit cfbce64

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,13 @@
150150

151151
import static java.util.Collections.emptyMap;
152152
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
153+
import static org.hamcrest.Matchers.anyOf;
154+
import static org.hamcrest.Matchers.contains;
153155
import static org.hamcrest.Matchers.empty;
156+
import static org.hamcrest.Matchers.emptyCollectionOf;
154157
import static org.hamcrest.Matchers.equalTo;
155158
import static org.hamcrest.Matchers.hasItem;
159+
import static org.hamcrest.Matchers.startsWith;
156160

157161
/**
158162
* Base testcase for randomized unit testing with Elasticsearch
@@ -631,6 +635,15 @@ public void log(StatusData data) {
631635
});
632636
}
633637

638+
// Tolerate the absence or otherwise denial of these specific lookup classes.
639+
// At some future time, we should require the JDNI warning.
640+
private static final List<String> LOG_4J_MSG_PREFIXES = org.elasticsearch.core.List.of(
641+
"JNDI lookup class is not available because this JRE does not support JNDI. "
642+
+ "JNDI string lookups will not be available, continuing configuration.",
643+
"JMX runtime input lookup class is not available because this JRE does not support JMX. "
644+
+ "JMX lookups will not be available, continuing configuration. "
645+
);
646+
634647
// separate method so that this can be checked again after suite scoped cluster is shut down
635648
protected static void checkStaticState() throws Exception {
636649
LeakTracker.INSTANCE.reportLeak();
@@ -644,7 +657,11 @@ protected static void checkStaticState() throws Exception {
644657
// StatusData instances to Strings as otherwise their toString output is useless
645658
assertThat(
646659
statusData.stream().map(status -> status.getMessage().getFormattedMessage()).collect(Collectors.toList()),
647-
empty()
660+
anyOf(
661+
emptyCollectionOf(String.class),
662+
contains(startsWith(LOG_4J_MSG_PREFIXES.get(0)), startsWith(LOG_4J_MSG_PREFIXES.get(1))),
663+
contains(startsWith(LOG_4J_MSG_PREFIXES.get(1)))
664+
)
648665
);
649666
} finally {
650667
// we clear the list so that status data from other tests do not interfere with tests within the same JVM

0 commit comments

Comments
 (0)