Skip to content

Commit

Permalink
[7.16] Tolerate benign log4j status messages in tests (#81851) (#81875)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Dec 18, 2021
1 parent 9983298 commit cfbce64
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> LOG_4J_MSG_PREFIXES = org.elasticsearch.core.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();
Expand All @@ -644,7 +657,11 @@ 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))),
contains(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
Expand Down

0 comments on commit cfbce64

Please sign in to comment.