Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.16] Tolerate benign log4j status messages in tests (#81851) #81875

Merged
merged 3 commits into from
Dec 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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