diff --git a/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/JdbcResponseFormatterTest.java b/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/JdbcResponseFormatterTest.java index 208f4cc902..e421016c00 100644 --- a/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/JdbcResponseFormatterTest.java +++ b/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/JdbcResponseFormatterTest.java @@ -39,6 +39,7 @@ import com.google.common.collect.ImmutableMap; import com.google.gson.JsonParser; import java.util.Arrays; +import org.elasticsearch.ElasticsearchException; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -154,6 +155,25 @@ void format_server_error_response() { ); } + @Test + void format_server_error_response_due_to_elasticsearch() { + assertJsonEquals( + "{\"error\":" + + "{\"" + + "type\":\"ElasticsearchException\"," + + "\"reason\":\"Error occurred in Elasticsearch engine: all shards failed\"," + + "\"details\":\"ElasticsearchException[all shards failed]; " + + "nested: IllegalStateException[Execution error];; " + + "java.lang.IllegalStateException: Execution error\\n" + + "For more details, please send request for Json format to see the raw response " + + "from elasticsearch engine.\"" + + "}," + + "\"status\":503}", + formatter.format(new ElasticsearchException("all shards failed", + new IllegalStateException("Execution error"))) + ); + } + private static void assertJsonEquals(String expected, String actual) { assertEquals( JsonParser.parseString(expected),