Răsfoiți Sursa

Remove ExceptionsHelper#detailedMessage in tests (#37921)

With this commit we remove all usages of the deprecated method
`ExceptionsHelper#detailedMessage` in tests. We do not address
production code here but rather in dedicated follow-up PRs to keep the
individual changes manageable.

Relates #19069
Daniel Mitterdorfer 6 ani în urmă
părinte
comite
ae8dee340d
18 a modificat fișierele cu 60 adăugiri și 58 ștergeri
  1. 1 2
      server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java
  2. 2 3
      server/src/test/java/org/elasticsearch/cluster/service/TaskBatcherTests.java
  3. 1 2
      server/src/test/java/org/elasticsearch/common/joda/JodaDateMathParserTests.java
  4. 1 2
      server/src/test/java/org/elasticsearch/common/time/JavaDateMathParserTests.java
  5. 2 3
      server/src/test/java/org/elasticsearch/common/util/concurrent/EsExecutorsTests.java
  6. 5 3
      server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java
  7. 4 2
      server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java
  8. 5 6
      server/src/test/java/org/elasticsearch/index/store/StoreTests.java
  9. 1 2
      server/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java
  10. 3 2
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeTests.java
  11. 3 2
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceRangeTests.java
  12. 3 2
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeTests.java
  13. 1 3
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridParserTests.java
  14. 1 2
      server/src/test/java/org/elasticsearch/search/aggregations/metrics/PercentilesTests.java
  15. 6 7
      server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java
  16. 4 8
      server/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java
  17. 2 1
      server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java
  18. 15 6
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisLimitsTests.java

+ 1 - 2
server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java

@@ -21,7 +21,6 @@ package org.elasticsearch.cluster.service;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.LogManager;
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.Version;
 import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
 import org.elasticsearch.cluster.ClusterChangedEvent;
@@ -523,7 +522,7 @@ public class MasterServiceTests extends ESTestCase {
         final ClusterStateTaskListener listener = new ClusterStateTaskListener() {
             @Override
             public void onFailure(String source, Exception e) {
-                fail(ExceptionsHelper.detailedMessage(e));
+                throw new AssertionError(e);
             }
 
             @Override

+ 2 - 3
server/src/test/java/org/elasticsearch/cluster/service/TaskBatcherTests.java

@@ -21,7 +21,6 @@ package org.elasticsearch.cluster.service;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.cluster.ClusterStateTaskConfig;
 import org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException;
 import org.elasticsearch.common.Priority;
@@ -273,7 +272,7 @@ public class TaskBatcherTests extends TaskExecutorTests {
 
                 @Override
                 public void onFailure(String source, Exception e) {
-                    fail(ExceptionsHelper.detailedMessage(e));
+                    throw new AssertionError(e);
                 }
             });
             usedKeys.add(key);
@@ -304,7 +303,7 @@ public class TaskBatcherTests extends TaskExecutorTests {
 
                 @Override
                 public void onFailure(String source, Exception e) {
-                    fail(ExceptionsHelper.detailedMessage(e));
+                    throw new AssertionError(e);
                 }
             };
 

+ 1 - 2
server/src/test/java/org/elasticsearch/common/joda/JodaDateMathParserTests.java

@@ -20,7 +20,6 @@
 package org.elasticsearch.common.joda;
 
 import org.elasticsearch.ElasticsearchParseException;
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.time.DateFormatter;
 import org.elasticsearch.common.time.DateMathParser;
 import org.elasticsearch.test.ESTestCase;
@@ -278,7 +277,7 @@ public class JodaDateMathParserTests extends ESTestCase {
             parser.parse(date, () -> 0);
             fail("Date: " + date + "\n" + msg);
         } catch (ElasticsearchParseException e) {
-            assertThat(ExceptionsHelper.detailedMessage(e).contains(exc), equalTo(true));
+            assertThat(e.getMessage().contains(exc), equalTo(true));
         }
     }
 

+ 1 - 2
server/src/test/java/org/elasticsearch/common/time/JavaDateMathParserTests.java

@@ -20,7 +20,6 @@
 package org.elasticsearch.common.time;
 
 import org.elasticsearch.ElasticsearchParseException;
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.test.ESTestCase;
 
 import java.time.Instant;
@@ -251,7 +250,7 @@ public class JavaDateMathParserTests extends ESTestCase {
 
     void assertParseException(String msg, String date, String exc) {
         ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> parser.parse(date, () -> 0));
-        assertThat(msg, ExceptionsHelper.detailedMessage(e), containsString(exc));
+        assertThat(msg, e.getMessage(), containsString(exc));
     }
 
     public void testIllegalMathFormat() {

+ 2 - 3
server/src/test/java/org/elasticsearch/common/util/concurrent/EsExecutorsTests.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.common.util.concurrent;
 
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.test.ESTestCase;
 import org.hamcrest.Matcher;
@@ -276,7 +275,7 @@ public class EsExecutorsTests extends ESTestCase {
                 fail("Didn't get a rejection when we expected one.");
             } catch (EsRejectedExecutionException e) {
                 assertFalse("Thread pool registering as terminated when it isn't", e.isExecutorShutdown());
-                String message = ExceptionsHelper.detailedMessage(e);
+                String message = e.getMessage();
                 assertThat(message, containsString("of dummy runnable"));
                 assertThat(message, containsString("on EsThreadPoolExecutor[name = " + getName()));
                 assertThat(message, containsString("queue capacity = " + queue));
@@ -316,7 +315,7 @@ public class EsExecutorsTests extends ESTestCase {
             fail("Didn't get a rejection when we expected one.");
         } catch (EsRejectedExecutionException e) {
             assertTrue("Thread pool not registering as terminated when it is", e.isExecutorShutdown());
-            String message = ExceptionsHelper.detailedMessage(e);
+            String message = e.getMessage();
             assertThat(message, containsString("of dummy runnable"));
             assertThat(message, containsString("on EsThreadPoolExecutor[name = " + getName()));
             assertThat(message, containsString("queue capacity = " + queue));

+ 5 - 3
server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.index.mapper;
 
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.Version;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.common.Strings;
@@ -51,6 +50,7 @@ import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.instanceOf;
 import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
 
 // TODO: make this a real unit test
 public class DocumentParserTests extends ESSingleNodeTestCase {
@@ -1443,7 +1443,8 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
 
         MapperParsingException err = expectThrows(MapperParsingException.class, () ->
                 client().prepareIndex("idx", "type").setSource(bytes, XContentType.JSON).get());
-        assertThat(ExceptionsHelper.detailedMessage(err), containsString("field name cannot be an empty string"));
+        assertThat(err.getCause(), notNullValue());
+        assertThat(err.getCause().getMessage(), containsString("field name cannot be an empty string"));
 
         final BytesReference bytes2 = BytesReference.bytes(XContentFactory.jsonBuilder()
                 .startObject()
@@ -1454,7 +1455,8 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
 
         err = expectThrows(MapperParsingException.class, () ->
                 client().prepareIndex("idx", "type").setSource(bytes2, XContentType.JSON).get());
-        assertThat(ExceptionsHelper.detailedMessage(err), containsString("field name cannot be an empty string"));
+        assertThat(err.getCause(), notNullValue());
+        assertThat(err.getCause().getMessage(), containsString("field name cannot be an empty string"));
     }
 
     public void testWriteToFieldAlias() throws Exception {

+ 4 - 2
server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java

@@ -125,6 +125,7 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
 
 public class IndexShardIT extends ESSingleNodeTestCase {
 
@@ -625,8 +626,9 @@ public class IndexShardIT extends ESSingleNodeTestCase {
         Exception e = expectThrows(Exception.class,
                 () -> client().prepareSearch("test")
                     .addAggregation(AggregationBuilders.terms("foo_terms").field("foo.keyword")).get());
-        logger.info("--> got: {}", ExceptionsHelper.detailedMessage(e));
-        assertThat(ExceptionsHelper.detailedMessage(e), containsString("[parent] Data too large, data for [<agg [foo_terms]>]"));
+        logger.info("--> got an expected exception", e);
+        assertThat(e.getCause(), notNullValue());
+        assertThat(e.getCause().getMessage(), containsString("[parent] Data too large, data for [<agg [foo_terms]>]"));
 
         client().admin().cluster().prepareUpdateSettings()
                 .setTransientSettings(Settings.builder()

+ 5 - 6
server/src/test/java/org/elasticsearch/index/store/StoreTests.java

@@ -96,6 +96,7 @@ import static org.hamcrest.Matchers.hasKey;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.startsWith;
 
 public class StoreTests extends ESTestCase {
 
@@ -977,7 +978,7 @@ public class StoreTests extends ESTestCase {
         String uuid = Store.CORRUPTED + UUIDs.randomBase64UUID();
         try (IndexOutput output = dir.createOutput(uuid, IOContext.DEFAULT)) {
             CodecUtil.writeHeader(output, Store.CODEC, Store.VERSION_STACK_TRACE);
-            output.writeString(ExceptionsHelper.detailedMessage(exception));
+            output.writeString(exception.getMessage());
             output.writeString(ExceptionsHelper.stackTrace(exception));
             CodecUtil.writeFooter(output);
         }
@@ -985,8 +986,7 @@ public class StoreTests extends ESTestCase {
             store.failIfCorrupted();
             fail("should be corrupted");
         } catch (CorruptIndexException e) {
-            assertTrue(e.getMessage().startsWith("[index][1] Preexisting corrupted index [" + uuid +
-                "] caused by: CorruptIndexException[foo (resource=bar)]"));
+            assertThat(e.getMessage(), startsWith("[index][1] Preexisting corrupted index [" + uuid + "] caused by: foo (resource=bar)"));
             assertTrue(e.getMessage().contains(ExceptionsHelper.stackTrace(exception)));
         }
 
@@ -994,15 +994,14 @@ public class StoreTests extends ESTestCase {
 
         try (IndexOutput output = dir.createOutput(uuid, IOContext.DEFAULT)) {
             CodecUtil.writeHeader(output, Store.CODEC, Store.VERSION_START);
-            output.writeString(ExceptionsHelper.detailedMessage(exception));
+            output.writeString(exception.getMessage());
             CodecUtil.writeFooter(output);
         }
         try {
             store.failIfCorrupted();
             fail("should be corrupted");
         } catch (CorruptIndexException e) {
-            assertTrue(e.getMessage().startsWith("[index][1] Preexisting corrupted index [" + uuid +
-                "] caused by: CorruptIndexException[foo (resource=bar)]"));
+            assertThat(e.getMessage(), startsWith("[index][1] Preexisting corrupted index [" + uuid + "] caused by: foo (resource=bar)"));
             assertFalse(e.getMessage().contains(ExceptionsHelper.stackTrace(exception)));
         }
 

+ 1 - 2
server/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java

@@ -20,7 +20,6 @@
 package org.elasticsearch.indices.store;
 
 import org.apache.logging.log4j.Logger;
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
 import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
 import org.elasticsearch.cluster.ClusterState;
@@ -456,7 +455,7 @@ public class IndicesStoreIntegrationIT extends ESIntegTestCase {
             @Override
             public void onFailure(String source, Exception e) {
                 latch.countDown();
-                fail("Excepted proper response " + ExceptionsHelper.detailedMessage(e));
+                throw new AssertionError("Expected a proper response", e);
             }
         });
         latch.await();

+ 3 - 2
server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeTests.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.search.aggregations.bucket;
 
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.xcontent.XContentParseException;
 import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.common.xcontent.json.JsonXContent;
@@ -30,6 +29,7 @@ import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range;
 import java.io.IOException;
 
 import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.notNullValue;
 
 public class DateRangeTests extends BaseAggregationTestCase<DateRangeAggregationBuilder> {
 
@@ -81,7 +81,8 @@ public class DateRangeTests extends BaseAggregationTestCase<DateRangeAggregation
         XContentParser parser = createParser(JsonXContent.jsonXContent, rangeAggregation);
         XContentParseException ex = expectThrows(XContentParseException.class,
                 () -> DateRangeAggregationBuilder.parse("aggregationName", parser));
-        assertThat(ExceptionsHelper.detailedMessage(ex), containsString("badField"));
+        assertThat(ex.getCause(), notNullValue());
+        assertThat(ex.getCause().getMessage(), containsString("badField"));
     }
 
 }

+ 3 - 2
server/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceRangeTests.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.search.aggregations.bucket;
 
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.geo.GeoDistance;
 import org.elasticsearch.common.geo.GeoPoint;
 import org.elasticsearch.common.unit.DistanceUnit;
@@ -34,6 +33,7 @@ import org.elasticsearch.test.geo.RandomShapeGenerator;
 import java.io.IOException;
 
 import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.notNullValue;
 
 public class GeoDistanceRangeTests extends BaseAggregationTestCase<GeoDistanceAggregationBuilder> {
 
@@ -81,7 +81,8 @@ public class GeoDistanceRangeTests extends BaseAggregationTestCase<GeoDistanceAg
         XContentParser parser = createParser(JsonXContent.jsonXContent, rangeAggregation);
         XContentParseException ex = expectThrows(XContentParseException.class,
             () -> GeoDistanceAggregationBuilder.parse("aggregationName", parser));
-        assertThat(ExceptionsHelper.detailedMessage(ex), containsString("badField"));
+        assertThat(ex.getCause(), notNullValue());
+        assertThat(ex.getCause().getMessage(), containsString("badField"));
     }
 
     /**

+ 3 - 2
server/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeTests.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.search.aggregations.bucket;
 
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.xcontent.XContentParseException;
 import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.common.xcontent.json.JsonXContent;
@@ -30,6 +29,7 @@ import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range;
 import java.io.IOException;
 
 import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.notNullValue;
 
 public class RangeTests extends BaseAggregationTestCase<RangeAggregationBuilder> {
 
@@ -77,7 +77,8 @@ public class RangeTests extends BaseAggregationTestCase<RangeAggregationBuilder>
         XContentParser parser = createParser(JsonXContent.jsonXContent, rangeAggregation);
         XContentParseException ex = expectThrows(XContentParseException.class,
                 () -> RangeAggregationBuilder.parse("aggregationName", parser));
-        assertThat(ExceptionsHelper.detailedMessage(ex), containsString("badField"));
+        assertThat(ex.getCause(), notNullValue());
+        assertThat(ex.getCause().getMessage(), containsString("badField"));
     }
 
     /**

+ 1 - 3
server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridParserTests.java

@@ -18,7 +18,6 @@
  */
 package org.elasticsearch.search.aggregations.bucket.geogrid;
 
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.unit.DistanceUnit;
 import org.elasticsearch.common.xcontent.XContentParseException;
 import org.elasticsearch.common.xcontent.XContentParser;
@@ -99,8 +98,7 @@ public class GeoHashGridParserTests extends ESTestCase {
         assertSame(XContentParser.Token.START_OBJECT, token);
         XContentParseException e = expectThrows(XContentParseException.class,
                 () -> GeoHashGridAggregationBuilder.parse("geohash_grid", stParser));
-        assertThat(ExceptionsHelper.detailedMessage(e),
-                containsString("[geohash_grid] precision doesn't support values of type: VALUE_BOOLEAN"));
+        assertThat(e.getMessage(), containsString("[geohash_grid] precision doesn't support values of type: VALUE_BOOLEAN"));
     }
 
     public void testParseErrorOnPrecisionOutOfRange() throws Exception {

+ 1 - 2
server/src/test/java/org/elasticsearch/search/aggregations/metrics/PercentilesTests.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.search.aggregations.metrics;
 
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.xcontent.XContentParseException;
 import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.common.xcontent.json.JsonXContent;
@@ -89,6 +88,6 @@ public class PercentilesTests extends BaseAggregationTestCase<PercentilesAggrega
         assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
         XContentParseException e = expectThrows(XContentParseException.class,
                 () -> PercentilesAggregationBuilder.parse("myPercentiles", parser));
-        assertThat(ExceptionsHelper.detailedMessage(e), containsString("[percentiles] failed to parse field [hdr]"));
+        assertThat(e.getMessage(), containsString("[percentiles] failed to parse field [hdr]"));
     }
 }

+ 6 - 7
server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java

@@ -22,9 +22,9 @@ package org.elasticsearch.search.query;
 import org.apache.lucene.analysis.TokenFilter;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
 import org.elasticsearch.action.index.IndexRequestBuilder;
+import org.elasticsearch.action.search.SearchPhaseExecutionException;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
@@ -564,11 +564,10 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
         prepareCreate("test").setSource(indexBody, XContentType.JSON).get();
         ensureGreen("test");
 
-        Exception e = expectThrows(Exception.class, () ->
+        SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () ->
                 client().prepareSearch("test").setQuery(
                         simpleQueryStringQuery("foo123").lenient(false)).get());
-        assertThat(ExceptionsHelper.detailedMessage(e),
-                containsString("NumberFormatException[For input string: \"foo123\"]"));
+        assertThat(e.getDetailedMessage(), containsString("NumberFormatException[For input string: \"foo123\"]"));
     }
 
     public void testLimitOnExpandedFields() throws Exception {
@@ -591,15 +590,15 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
         client().prepareIndex("toomanyfields", "type1", "1").setSource("field1", "foo bar baz").get();
         refresh();
 
-        Exception e = expectThrows(Exception.class, () -> {
+        SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () -> {
                 SimpleQueryStringBuilder qb = simpleQueryStringQuery("bar");
                 if (randomBoolean()) {
                     qb.field("*");
                 }
                 client().prepareSearch("toomanyfields").setQuery(qb).get();
                 });
-        assertThat(ExceptionsHelper.detailedMessage(e),
-                containsString("field expansion matches too many fields, limit: " + CLUSTER_MAX_CLAUSE_COUNT + ", got: "
+        assertThat(e.getDetailedMessage(),
+            containsString("field expansion matches too many fields, limit: " + CLUSTER_MAX_CLAUSE_COUNT + ", got: "
                         + (CLUSTER_MAX_CLAUSE_COUNT + 1)));
     }
 

+ 4 - 8
server/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java

@@ -27,7 +27,6 @@ import org.apache.lucene.document.StoredField;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.search.suggest.document.ContextSuggestField;
 import org.apache.lucene.util.BytesRef;
-import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.compress.CompressedXContent;
@@ -412,8 +411,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
             CategoryContextMapping mapping = ContextBuilder.category("cat").build();
 
             XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser));
-            assertThat(ExceptionsHelper.detailedMessage(e),
-                    containsString("category context must be an object, string, number or boolean"));
+            assertThat(e.getMessage(), containsString("category context must be an object, string, number or boolean"));
         }
     }
 
@@ -473,8 +471,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
             CategoryContextMapping mapping = ContextBuilder.category("cat").build();
 
             XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser));
-            assertThat(ExceptionsHelper.detailedMessage(e),
-                    containsString("category context must be an object, string, number or boolean"));
+            assertThat(e.getMessage(), containsString("category context must be an object, string, number or boolean"));
         }
     }
 
@@ -640,7 +637,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
             CategoryContextMapping mapping = ContextBuilder.category("cat").build();
 
             XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser));
-            assertThat(ExceptionsHelper.detailedMessage(e), containsString("category context must be a string, number or boolean"));
+            assertThat(e.getMessage(), containsString("category context must be a string, number or boolean"));
         }
     }
 
@@ -699,8 +696,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
             CategoryContextMapping mapping = ContextBuilder.category("cat").build();
 
             XContentParseException e = expectThrows(XContentParseException.class, () -> mapping.parseQueryContext(parser));
-            assertThat(ExceptionsHelper.detailedMessage(e),
-                    containsString("category context must be an object, string, number or boolean"));
+            assertThat(e.getMessage(), containsString("category context must be an object, string, number or boolean"));
         }
     }
 

+ 2 - 1
server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java

@@ -817,7 +817,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
         } catch (Exception ex) {
             logger.info("--> caught a top level exception, asserting what's expected", ex);
             assertThat(getFailureCount("test-repo"), greaterThan(0L));
-            assertThat(ExceptionsHelper.detailedMessage(ex), containsString("IOException"));
+            assertThat(ex.getCause(), notNullValue());
+            assertThat(ex.getCause().getMessage(), containsString("Random IOException"));
         }
     }
 

+ 15 - 6
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisLimitsTests.java

@@ -6,7 +6,7 @@
 package org.elasticsearch.xpack.core.ml.job.config;
 
 import org.elasticsearch.ElasticsearchException;
-import org.elasticsearch.ExceptionsHelper;
+import org.elasticsearch.ElasticsearchParseException;
 import org.elasticsearch.common.io.stream.Writeable;
 import org.elasticsearch.common.xcontent.DeprecationHandler;
 import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@@ -21,6 +21,8 @@ import java.io.IOException;
 
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.notNullValue;
 
 public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLimits> {
 
@@ -49,7 +51,8 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
         XContentParser parser = XContentFactory.xContent(XContentType.JSON)
                 .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
         XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.STRICT_PARSER.apply(parser, null));
-        assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = -1"));
+        assertThat(e.getCause(), notNullValue());
+        assertThat(e.getCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = -1"));
     }
 
     public void testParseModelMemoryLimitGivenZero() throws IOException {
@@ -57,7 +60,8 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
         XContentParser parser = XContentFactory.xContent(XContentType.JSON)
                 .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
         XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.STRICT_PARSER.apply(parser, null));
-        assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
+        assertThat(e.getCause(), notNullValue());
+        assertThat(e.getCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
     }
 
     public void testParseModelMemoryLimitGivenPositiveNumber() throws IOException {
@@ -75,7 +79,10 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
         XContentParser parser = XContentFactory.xContent(XContentType.JSON)
                 .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
         XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.STRICT_PARSER.apply(parser, null));
-        assertThat(ExceptionsHelper.detailedMessage(e), containsString("Values less than -1 bytes are not supported: -4mb"));
+        // the root cause is wrapped in an intermediate ElasticsearchParseException
+        assertThat(e.getCause(), instanceOf(ElasticsearchParseException.class));
+        assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
+        assertThat(e.getCause().getCause().getMessage(), containsString("Values less than -1 bytes are not supported: -4mb"));
     }
 
     public void testParseModelMemoryLimitGivenZeroString() throws IOException {
@@ -83,7 +90,8 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
         XContentParser parser = XContentFactory.xContent(XContentType.JSON)
                 .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
         XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.STRICT_PARSER.apply(parser, null));
-        assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
+        assertThat(e.getCause(), notNullValue());
+        assertThat(e.getCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
     }
 
     public void testParseModelMemoryLimitGivenLessThanOneMBString() throws IOException {
@@ -91,7 +99,8 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
         XContentParser parser = XContentFactory.xContent(XContentType.JSON)
                 .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
         XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.STRICT_PARSER.apply(parser, null));
-        assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
+        assertThat(e.getCause(), notNullValue());
+        assertThat(e.getCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
     }
 
     public void testParseModelMemoryLimitGivenStringMultipleOfMBs() throws IOException {