From 2e45f326fddbf6310513f21dd6e589807fb229ff Mon Sep 17 00:00:00 2001 From: Martin Gaievski Date: Mon, 7 Aug 2023 10:42:46 -0700 Subject: [PATCH] Fixed compilation errors after refactoring in core Strings class Signed-off-by: Martin Gaievski --- ...ValidateDependentPluginInstallationIT.java | 49 +++++++++---------- .../common/BaseNeuralSearchIT.java | 10 ++-- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/test/java/org/opensearch/neuralsearch/ValidateDependentPluginInstallationIT.java b/src/test/java/org/opensearch/neuralsearch/ValidateDependentPluginInstallationIT.java index 84707e868..b277f9a8f 100644 --- a/src/test/java/org/opensearch/neuralsearch/ValidateDependentPluginInstallationIT.java +++ b/src/test/java/org/opensearch/neuralsearch/ValidateDependentPluginInstallationIT.java @@ -15,7 +15,6 @@ import org.junit.Assert; import org.opensearch.client.Request; import org.opensearch.client.Response; -import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.rest.RestRequest; @@ -62,21 +61,20 @@ public void testValidateMLPluginSetup() throws IOException { } private void createBasicKnnIndex() throws IOException { - String mapping = Strings.toString( - XContentFactory.jsonBuilder() - .startObject() - .startObject("properties") - .startObject(KNN_VECTOR_FIELD_NAME) - .field("type", "knn_vector") - .field("dimension", Integer.toString(3)) - .startObject("method") - .field("engine", "lucene") - .field("name", "hnsw") - .endObject() - .endObject() - .endObject() - .endObject() - ); + String mapping = XContentFactory.jsonBuilder() + .startObject() + .startObject("properties") + .startObject(KNN_VECTOR_FIELD_NAME) + .field("type", "knn_vector") + .field("dimension", Integer.toString(3)) + .startObject("method") + .field("engine", "lucene") + .field("name", "hnsw") + .endObject() + .endObject() + .endObject() + .endObject() + .toString(); mapping = mapping.substring(1, mapping.length() - 1); createIndex(KNN_INDEX_NAME, Settings.EMPTY, mapping); } @@ -99,16 +97,15 @@ private Set getAllInstalledPlugins() throws IOException { } private void indexDocument() throws IOException { - final String indexRequestBody = Strings.toString( - XContentFactory.jsonBuilder() - .startObject() - .startArray(KNN_VECTOR_FIELD_NAME) - .value(1.0) - .value(2.0) - .value(4.0) - .endArray() - .endObject() - ); + final String indexRequestBody = XContentFactory.jsonBuilder() + .startObject() + .startArray(KNN_VECTOR_FIELD_NAME) + .value(1.0) + .value(2.0) + .value(4.0) + .endArray() + .endObject() + .toString(); final Request indexRequest = new Request(RestRequest.Method.POST.name(), KNN_DOCUMENT_URL); indexRequest.setJsonEntity(indexRequestBody); assertOK(client().performRequest(indexRequest)); diff --git a/src/test/java/org/opensearch/neuralsearch/common/BaseNeuralSearchIT.java b/src/test/java/org/opensearch/neuralsearch/common/BaseNeuralSearchIT.java index f4daed549..db5dd1fa6 100644 --- a/src/test/java/org/opensearch/neuralsearch/common/BaseNeuralSearchIT.java +++ b/src/test/java/org/opensearch/neuralsearch/common/BaseNeuralSearchIT.java @@ -39,7 +39,6 @@ import org.opensearch.client.Response; import org.opensearch.client.RestClient; import org.opensearch.client.WarningsHandler; -import org.opensearch.common.Strings; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentType; @@ -92,7 +91,7 @@ protected void updateClusterSettings(String settingKey, Object value) { "PUT", "_cluster/settings", null, - toHttpEntity(Strings.toString(builder)), + toHttpEntity(builder.toString()), ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) ); @@ -324,7 +323,7 @@ protected Map search( if (requestParams != null && !requestParams.isEmpty()) { requestParams.forEach(request::addParameter); } - request.setJsonEntity(Strings.toString(builder)); + request.setJsonEntity(builder.toString()); Response response = client().performRequest(request); assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode())); @@ -376,7 +375,7 @@ protected void addKnnDoc( } builder.endObject(); - request.setJsonEntity(Strings.toString(builder)); + request.setJsonEntity(builder.toString()); Response response = client().performRequest(request); assertEquals(request.getEndpoint() + ": failed", RestStatus.CREATED, RestStatus.fromCode(response.getStatusLine().getStatusCode())); } @@ -477,7 +476,8 @@ private String buildIndexConfiguration(List knnFieldConfigs, int .endObject() .endObject(); } - return Strings.toString(xContentBuilder.endObject().endObject().endObject()); + xContentBuilder.endObject().endObject().endObject(); + return xContentBuilder.toString(); } protected static Response makeRequest(