diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index c3edc9c8d67..bf2f954bba0 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -96,6 +96,8 @@ public class IndexingIT extends AbstractRollingTestCase { Request createTestIndex = new Request("PUT", "/test_index"); createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}"); client().performRequest(createTestIndex); + allowedWarnings("index [test_index] matches multiple legacy templates [global, prevent-bwc-deprecation-template], " + + "composable templates will only match a single template"); String recoverQuickly = "{\"settings\": {\"index.unassigned.node_left.delayed_timeout\": \"100ms\"}}"; Request createIndexWithReplicas = new Request("PUT", "/index_with_replicas"); 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 2a35cd4fdaf..c85d8ab84b2 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -75,6 +75,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.MockBigArrays; import org.elasticsearch.common.util.MockPageCacheRecycler; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContent; @@ -430,6 +431,33 @@ public abstract class ESTestCase extends LuceneTestCase { assertWarnings(true, expectedWarnings); } + /** + * Allow the given warnings, but don't require their presence. + */ + protected final void allowedWarnings(String... allowedWarnings) { + if (enableWarningsCheck() == false) { + throw new IllegalStateException("unable to check warning headers if the test is not set to do so"); + } + try { + final List actualWarnings = threadContext.getResponseHeaders().get("Warning"); + if (actualWarnings == null) { + return; + } + final Set actualWarningValues = + actualWarnings.stream() + .map(s -> DeprecationLogger.extractWarningValueFromWarningHeader(s, true)) + .map(DeprecationLogger::escapeAndEncode) + .collect(Collectors.toSet()); + Set expectedWarnings = new HashSet<>(Arrays.asList(allowedWarnings)); + final Set warningsNotExpected = Sets.difference(actualWarningValues, expectedWarnings); + assertThat("Found " + warningsNotExpected.size() + " unexpected warnings\nExpected: " + + expectedWarnings + "\nActual: " + actualWarningValues, + warningsNotExpected.size(), equalTo(0)); + } finally { + resetDeprecationLogger(); + } + } + protected final void assertWarnings(boolean stripXContentPosition, String... expectedWarnings) { if (enableWarningsCheck() == false) { throw new IllegalStateException("unable to check warning headers if the test is not set to do so"); diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index 80a21e73595..20406f1386f 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -75,6 +75,8 @@ public class IndexingIT extends AbstractUpgradeTestCase { Request createTestIndex = new Request("PUT", "/test_index"); createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}"); client().performRequest(createTestIndex); + allowedWarnings("index [test_index] matches multiple legacy templates [global, xpack-prevent-bwc-deprecation-template], " + + "composable templates will only match a single template"); String recoverQuickly = "{\"settings\": {\"index.unassigned.node_left.delayed_timeout\": \"100ms\"}}"; Request createIndexWithReplicas = new Request("PUT", "/index_with_replicas"); diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/TokenBackwardsCompatibilityIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/TokenBackwardsCompatibilityIT.java index 035b2821b49..5ef573add0e 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/TokenBackwardsCompatibilityIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/TokenBackwardsCompatibilityIT.java @@ -89,6 +89,8 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase { assertNotNull(refreshToken); storeTokens(client(), 1, accessToken, refreshToken); + allowedWarnings("index [token_backwards_compatibility_it] matches multiple legacy templates " + + "[gen-tokens-old-cluster-template, global], composable templates will only match a single template"); responseMap = createTokens(client(), "test_user", "x-pack-test-password"); accessToken = (String) responseMap.get("access_token"); @@ -175,6 +177,8 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase { assertNotNull(refreshToken); storeTokens(client(), 5, accessToken, refreshToken); + allowedWarnings("index [token_backwards_compatibility_it] matches multiple legacy templates " + + "[global, invalid-tokens-old-cluster-template], composable templates will only match a single template"); // invalidate access token invalidateAccessToken(client(), accessToken);