Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed compilation errors after refactoring in core Strings class #243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -99,16 +97,15 @@ private Set<String> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, ""))
);

Expand Down Expand Up @@ -324,7 +323,7 @@ protected Map<String, Object> 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()));
Expand Down Expand Up @@ -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()));
}
Expand Down Expand Up @@ -477,7 +476,8 @@ private String buildIndexConfiguration(List<KNNFieldConfig> knnFieldConfigs, int
.endObject()
.endObject();
}
return Strings.toString(xContentBuilder.endObject().endObject().endObject());
xContentBuilder.endObject().endObject().endObject();
return xContentBuilder.toString();
}

protected static Response makeRequest(
Expand Down