From 7b932a7c882cbabbc9fcafcd864a39bb161bd122 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Tue, 25 Jul 2023 17:15:01 -0700 Subject: [PATCH] Fix create_index/create_index_with_IOException issue caused by OpenSearch PR change (#1899) * Added setDefaultMediaType for create_index and create_index_with_IOException Signed-off-by: Mitchell Gale --- .../sql/opensearch/client/OpenSearchRestClientTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java index b521c6605c..cceb6de995 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.opensearch.core.xcontent.MediaTypeParserRegistry.setDefaultMediaType; import static org.opensearch.sql.opensearch.client.OpenSearchClient.META_CLUSTER_NAME; import static org.opensearch.sql.opensearch.data.type.OpenSearchDataType.MappingType; @@ -34,6 +35,7 @@ import lombok.SneakyThrows; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.lucene.search.TotalHits; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -101,6 +103,11 @@ void setUp() { client = new OpenSearchRestClient(restClient); } + @BeforeAll + static void setUpJSON() { + setDefaultMediaType(XContentType.JSON); + } + @Test void is_index_exist() throws IOException { when(restClient.indices() @@ -142,7 +149,6 @@ void create_index() throws IOException { @Test void create_index_with_IOException() throws IOException { when(restClient.indices().create(any(), any())).thenThrow(IOException.class); - assertThrows(IllegalStateException.class, () -> client.createIndex("test", ImmutableMap.of())); }