Skip to content

Commit

Permalink
[Main] Fixing breaking changes from core in 3.0 (#1191)
Browse files Browse the repository at this point in the history
* Fixing breaking changes to main

Signed-off-by: Sarat Vemulapalli <[email protected]>

* Removing extra lines

Signed-off-by: Sarat Vemulapalli <[email protected]>

---------

Signed-off-by: Sarat Vemulapalli <[email protected]>
  • Loading branch information
saratvemulapalli authored Aug 7, 2023
1 parent 0e5a0ec commit 730f21c
Show file tree
Hide file tree
Showing 35 changed files with 40 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static <T> void testParse(ToXContentObject obj, Function<XContentParser,
if (wrapWithObject) {
builder.endObject();
}
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
testParseFromString(obj, jsonStr, function);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.common.dataframe;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
Expand All @@ -33,7 +32,7 @@ public void testToXContent() throws IOException {
value.toXContent(builder);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"BOOLEAN\",\"value\":true}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
*/

package org.opensearch.ml.common.dataframe;

import org.junit.Before;
import org.junit.Test;
import org.opensearch.core.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -56,7 +53,7 @@ public void testToXContent() throws IOException {
columnMeta.toXContent(builder);

assertNotNull(builder);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"name\":\"columnMetaName\",\"column_type\":\"STRING\"}", jsonStr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -233,7 +232,7 @@ public void testToXContent() throws IOException {
builder.endObject();

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_metas\":[" +
"{\"name\":\"c1\",\"column_type\":\"STRING\"}," +
"{\"name\":\"c2\",\"column_type\":\"INTEGER\"}," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.IOException;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void testToXContent() throws IOException {
doubleValue.toXContent(builder);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"DOUBLE\",\"value\":5.0}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.common.dataframe;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -34,7 +33,7 @@ public void testToXContent() throws IOException {
floatValue.toXContent(builder);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"FLOAT\",\"value\":2.1}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.common.dataframe;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
Expand All @@ -33,7 +32,7 @@ public void testToXContent() throws IOException {
intValue.toXContent(builder);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"INTEGER\",\"value\":2}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.common.dataframe;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
Expand All @@ -33,7 +32,7 @@ public void testToXContent() throws IOException {
longValue.toXContent(builder);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"LONG\",\"value\":2}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.common.dataframe;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.ToXContent;
Expand Down Expand Up @@ -34,7 +33,7 @@ public void testToXContent() throws IOException {
value.toXContent(builder, ToXContent.EMPTY_PARAMS);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"NULL\"}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
Expand Down Expand Up @@ -137,7 +136,7 @@ public void testToXContent() throws IOException {
row.toXContent(builder);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();

assertEquals("{\"values\":[{\"column_type\":\"INTEGER\",\"value\":0}]}", jsonStr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.common.dataframe;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
Expand All @@ -33,7 +32,7 @@ public void testToXContent() throws IOException {
shortValue.toXContent(builder);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"SHORT\",\"value\":2}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.common.dataframe;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.ToXContent;
Expand Down Expand Up @@ -38,7 +37,7 @@ public void testToXContent() throws IOException {
value.toXContent(builder, ToXContent.EMPTY_PARAMS);

assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"column_type\":\"STRING\",\"value\":\"str\"}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void testParse(FunctionName algorithm, MLInputDataset inputDataset, Stri
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
input.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals(expectedInputStr, jsonStr);

XContentParser parser = XContentType.JSON.xContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testXContentFullObject() throws Exception {
Optional.of(QueryBuilders.matchAllQuery()));
XContentBuilder builder = XContentFactory.jsonBuilder();
builder = input.toXContent(builder, null);
String json = org.opensearch.common.Strings.toString(builder);
String json = builder.toString();

XContentParser parser = XContentType.JSON.xContent()
.createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY,
Expand All @@ -56,7 +56,7 @@ public void testXContentMissingAnomalyStartFilter() throws Exception {
"@timestamp", 0L, 10L, 1L, 2, Optional.empty(), Optional.empty());
XContentBuilder builder = XContentFactory.jsonBuilder();
builder = input.toXContent(builder, null);
String json = org.opensearch.common.Strings.toString(builder);
String json = builder.toString();

XContentParser parser = XContentType.JSON.xContent()
.createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setUp() throws Exception {
public void parseTextDocsMLInput() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
input.toXContent(builder, ToXContent.EMPTY_PARAMS);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
System.out.println(jsonStr);
parseMLInput(jsonStr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setUp() {
public void toXContent() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
output.toXContent(builder, ToXContent.EMPTY_PARAMS);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"task_id\":\"test_task_id\",\"status\":\"test_status\",\"prediction_result\":" +
"{\"column_metas\":[{\"name\":\"test\",\"column_type\":\"INTEGER\"}],\"rows\":[{\"values\":" +
"[{\"column_type\":\"INTEGER\",\"value\":1}]},{\"values\":[{\"column_type\":\"INTEGER\"," +
Expand All @@ -63,7 +63,7 @@ public void toXContent_EmptyOutput() throws IOException {
MLPredictionOutput output = MLPredictionOutput.builder().build();
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
output.toXContent(builder, ToXContent.EMPTY_PARAMS);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{}", jsonStr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
package org.opensearch.ml.common.output;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.ToXContent;
Expand All @@ -24,7 +22,7 @@ public void parse_MLTrain() throws IOException {
.modelId("test_modelId").status("test_status").build();
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
output.toXContent(builder, ToXContent.EMPTY_PARAMS);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"model_id\":\"test_modelId\",\"status\":\"test_status\"}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.junit.Before;
import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void testXContent() throws Exception {
builder.startObject();
builder = output.toXContent(builder, null);
builder.endObject();
String json = Strings.toString(builder);
String json = builder.toString();
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, null, json);
AnomalyLocalizationOutput newOutput = AnomalyLocalizationOutput.parse(parser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void toXContent() throws IOException {
builder.startObject();
output.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"result\":1.0}", jsonStr);
}

Expand All @@ -48,7 +48,7 @@ public void toXContent_EmptyOutput() throws IOException {
builder.startObject();
output.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{}", jsonStr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void setUp() {
public void toXContent() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
output.toXContent(builder, ToXContent.EMPTY_PARAMS);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"sample_result\":1.0}", jsonStr);
}

Expand All @@ -44,7 +44,7 @@ public void toXContent_EmptyOutput() throws IOException {
SampleAlgoOutput output = SampleAlgoOutput.builder().build();
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
output.toXContent(builder, ToXContent.EMPTY_PARAMS);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{}", jsonStr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testToXContent() throws IOException {
MLDeployModelNodesResponse response = new MLDeployModelNodesResponse(clusterName, nodes, failures);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals(
"{\"foo1\":{\"stats\":{\"modelName:version1\":\"response\"}},\"foo2\":{\"stats\":{\"modelName:version2\":\"response\"}}}",
jsonStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testToXContent() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
// Verify the results
assertEquals("{\"task_id\":\"test_id\"," +
"\"status\":\"test\"}", jsonStr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.opensearch.ml.common.transport.execute;

import org.junit.Test;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -91,7 +90,7 @@ public void toXContentTest() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"function_name\":\"METRICS_CORRELATION\"," +
"\"output\":{\"inference_results\":[{" +
"\"event_window\":[4.0,5.0,6.0]," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testToXContent() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
// Verify the results
assertEquals(
"{\"result\":{\"task_id\":\"taskId\",\"status\":\"Success\",\"prediction_result\":{\"column_metas\":[{\"name\":\"key1\",\"column_type\":\"DOUBLE\"}],\"rows\":[{\"values\":[{\"column_type\":\"DOUBLE\",\"value\":2.0}]}]}}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void toXContentTest() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
mlModelGetResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"name\":\"model\"," +
"\"algorithm\":\"KMEANS\"," +
"\"model_version\":\"1.0.0\"," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void toXContentTest() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = org.opensearch.common.Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"task_id\":\"b5009b99-268f-476d-a676-379a30f82457\"," +
"\"status\":\"Success\"," +
"\"prediction_result\":{" +
Expand Down
Loading

0 comments on commit 730f21c

Please sign in to comment.