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

[2.x] Fixing breaking changes from core #1189

Closed
wants to merge 2 commits into from
Closed
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 @@ -14,7 +14,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.opensearch.common.util.CollectionUtils;
import org.opensearch.core.common.util.CollectionUtils;
import org.opensearch.commons.authuser.User;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.text.StringSubstitutor;
import org.opensearch.common.Strings;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
Expand Down Expand Up @@ -93,7 +93,7 @@ static Connector fromStream(StreamInput in) throws IOException {
}

static Connector createConnector(XContentBuilder builder, String connectorProtocol) throws IOException {
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
return createConnector(jsonStr, connectorProtocol);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.common.util.CollectionUtils;
import org.opensearch.core.common.util.CollectionUtils;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

package org.opensearch.ml.common;

import org.opensearch.common.Strings;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.ToXContentObject;
Expand All @@ -26,15 +25,15 @@ public static <T> void testParse(ToXContentObject obj, Function<XContentParser,
}

public static <T> void testParse(ToXContentObject obj, Function<XContentParser, T> function, boolean wrapWithObject) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
if (wrapWithObject) {
builder.startObject();
}
obj.toXContent(builder, ToXContent.EMPTY_PARAMS);
if (wrapWithObject) {
builder.endObject();
}
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
testParseFromString(obj, jsonStr, function);
}

Expand All @@ -46,7 +45,7 @@ public static <T> void testParseFromString(ToXContentObject obj, String jsonStr,
}

public static String contentObjectToString(ToXContentObject obj) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
obj.toXContent(builder, ToXContent.EMPTY_PARAMS);
return xContentBuilderToString(builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package org.opensearch.ml.common.dataframe;

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.XContentBuilder;

import java.io.IOException;
Expand All @@ -29,11 +29,11 @@ public void booleanValue() {
@Test
public void testToXContent() throws IOException {
BooleanValue value = new BooleanValue(true);
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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 @@ -7,10 +7,9 @@

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;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.ml.common.TestHelper;
Expand Down Expand Up @@ -51,11 +50,11 @@ public void writeToAndReadStream() throws IOException {

@Test
public void testToXContent() throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
columnMeta.toXContent(builder);

assertNotNull(builder);
String jsonStr = 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,11 +14,11 @@
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.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.ml.common.TestHelper;
Expand Down Expand Up @@ -227,13 +227,13 @@ public void select_Exception_InvalidColumn(){

@Test
public void testToXContent() throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
builder.startObject();
defaultDataFrame.toXContent(builder);
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,10 +8,10 @@
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.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -47,11 +47,11 @@ public void writeTo() throws IOException {
@Test
public void testToXContent() throws IOException {
DoubleValue doubleValue = new DoubleValue(5.0D);
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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,9 +6,9 @@
package org.opensearch.ml.common.dataframe;

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.XContentBuilder;

import java.io.IOException;
Expand All @@ -30,11 +30,11 @@ public void floatValue() {
@Test
public void testToXContent() throws IOException {
FloatValue floatValue = new FloatValue(2.1f);
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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,9 +6,8 @@
package org.opensearch.ml.common.dataframe;

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.XContentBuilder;

import java.io.IOException;
Expand All @@ -29,11 +28,11 @@ public void intValue() {
@Test
public void testToXContent() throws IOException {
IntValue intValue = new IntValue(2);
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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,9 +6,8 @@
package org.opensearch.ml.common.dataframe;

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.XContentBuilder;

import java.io.IOException;
Expand All @@ -29,11 +28,11 @@ public void longValue() {
@Test
public void testToXContent() throws IOException {
LongValue longValue = new LongValue((long)2);
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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,9 +6,9 @@
package org.opensearch.ml.common.dataframe;

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;
import org.opensearch.core.xcontent.XContentBuilder;

Expand All @@ -30,11 +30,11 @@ public void getValue() {
@Test
public void testToXContent() throws IOException {
NullValue value = new NullValue();
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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,10 +13,10 @@
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.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;

Expand Down Expand Up @@ -133,11 +133,11 @@ public void select() {

@Test
public void testToXContent() throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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,9 +6,9 @@
package org.opensearch.ml.common.dataframe;

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.XContentBuilder;

import java.io.IOException;
Expand All @@ -29,11 +29,11 @@ public void shortValue() {
@Test
public void testToXContent() throws IOException {
ShortValue shortValue = new ShortValue((short)2);
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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,9 +6,9 @@
package org.opensearch.ml.common.dataframe;

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;
import org.opensearch.core.xcontent.XContentBuilder;

Expand All @@ -34,11 +34,11 @@ public void stringValue_NullPointerException() {
@Test
public void testToXContent() throws IOException {
StringValue value = new StringValue("str");
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
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 @@ -10,12 +10,11 @@
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.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -150,10 +149,10 @@ public void parse_TextEmbedding_NullResultFilter() throws IOException {

private void testParse(FunctionName algorithm, MLInputDataset inputDataset, String expectedInputStr, Consumer<MLInput> verify) throws IOException {
MLInput input = MLInput.builder().inputDataset(inputDataset).algorithm(algorithm).build();
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
input.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals(expectedInputStr, jsonStr);

XContentParser parser = XContentType.JSON.xContent().createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY,
Expand Down
Loading