Skip to content

Commit

Permalink
Revert Text Block changes from "Enhance validation for create connect…
Browse files Browse the repository at this point in the history
…or API" #3260 (#3329)

Text Blcok changes introduced in JDK15. Eventhough our main release is based on JDK21, 2.x is still based on JDK11. So to support autoi bot backport of these test files in the future, reverting Text Block related changes from test cases.

Signed-off-by: Abdul Muneer Kolarkunnu <[email protected]>
  • Loading branch information
akolarkunnu authored Jan 3, 2025
1 parent b5dd5a1 commit bf48f99
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void toXContent_NullValue() throws IOException {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
String content = TestHelper.xContentBuilderToString(builder);
String expctedContent = """
{"action_type":"PREDICT","method":"http","url":"https://test.com",\
"request_body":"{\\"input\\": \\"${parameters.input}\\"}"}\
""";
assertEquals(expctedContent, content);
assertEquals(
"{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\"}",
content
);
}

@Test
Expand All @@ -127,23 +127,21 @@ public void toXContent() throws IOException {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
String content = TestHelper.xContentBuilderToString(builder);
String expctedContent = """
{"action_type":"PREDICT","method":"http","url":"https://test.com","headers":{"key1":"value1"},\
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
"pre_process_function":"connector.pre_process.openai.embedding",\
"post_process_function":"connector.post_process.openai.embedding"}\
""";
assertEquals(expctedContent, content);
assertEquals(
"{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
+ "\"headers\":{\"key1\":\"value1\"},\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}",
content
);
}

@Test
public void parse() throws IOException {
String jsonStr = """
{"action_type":"PREDICT","method":"http","url":"https://test.com","headers":{"key1":"value1"},\
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
"pre_process_function":"connector.pre_process.openai.embedding",\
"post_process_function":"connector.post_process.openai.embedding"}"\
""";
String jsonStr = "{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
+ "\"headers\":{\"key1\":\"value1\"},\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}";
XContentParser parser = XContentType.JSON
.xContent()
.createParser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ public class MLCreateConnectorInputTests {
private static final String TEST_CREDENTIAL_VALUE = "test_key_value";
private static final String TEST_ROLE1 = "role1";
private static final String TEST_ROLE2 = "role2";
private final String expectedInputStr = """
{"name":"test_connector_name","description":"this is a test connector","version":"1","protocol":"http",\
"parameters":{"input":"test input value"},"credential":{"key":"test_key_value"},\
"actions":[{"action_type":"PREDICT","method":"POST","url":"https://test.com",\
"headers":{"api_key":"${credential.key}"},\
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
"pre_process_function":"connector.pre_process.openai.embedding",\
"post_process_function":"connector.post_process.openai.embedding"}],\
"backend_roles":["role1","role2"],"add_all_backend_roles":false,\
"access_mode":"PUBLIC","client_config":{"max_connection":20,\
"connection_timeout":10000,"read_timeout":10000,\
"retry_backoff_millis":10,"retry_timeout_seconds":10,"max_retry_times":-1,"retry_backoff_policy":"constant"}}\
""";
private final String expectedInputStr = "{\"name\":\"test_connector_name\","
+ "\"description\":\"this is a test connector\",\"version\":\"1\",\"protocol\":\"http\","
+ "\"parameters\":{\"input\":\"test input value\"},\"credential\":{\"key\":\"test_key_value\"},"
+ "\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://test.com\","
+ "\"headers\":{\"api_key\":\"${credential.key}\"},"
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}],"
+ "\"backend_roles\":[\"role1\",\"role2\"],\"add_all_backend_roles\":false,"
+ "\"access_mode\":\"PUBLIC\",\"client_config\":{\"max_connection\":20,"
+ "\"connection_timeout\":10000,\"read_timeout\":10000,"
+ "\"retry_backoff_millis\":10,\"retry_timeout_seconds\":10,\"max_retry_times\":-1,\"retry_backoff_policy\":\"constant\"}}";

@Before
public void setUp() {
Expand Down Expand Up @@ -238,15 +237,16 @@ public void testParse() throws Exception {

@Test
public void testParse_ArrayParameter() throws Exception {
String expectedInputStr = """
{"name":"test_connector_name","description":"this is a test connector","version":"1",\
"protocol":"http","parameters":{"input":["test input value"]},"credential":{"key":"test_key_value"},\
"actions":[{"action_type":"PREDICT","method":"POST","url":"https://test.com",\
"headers":{"api_key":"${credential.key}"},"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
"pre_process_function":"connector.pre_process.openai.embedding",\
"post_process_function":"connector.post_process.openai.embedding"}],\
"backend_roles":["role1","role2"],"add_all_backend_roles":false,"access_mode":"PUBLIC"};\
""";
String expectedInputStr = "{\"name\":\"test_connector_name\","
+ "\"description\":\"this is a test connector\",\"version\":\"1\",\"protocol\":\"http\","
+ "\"parameters\":{\"input\":[\"test input value\"]},\"credential\":{\"key\":\"test_key_value\"},"
+ "\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://test.com\","
+ "\"headers\":{\"api_key\":\"${credential.key}\"},"
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}],"
+ "\"backend_roles\":[\"role1\",\"role2\"],\"add_all_backend_roles\":false,"
+ "\"access_mode\":\"PUBLIC\"}";
testParseFromJsonString(expectedInputStr, parsedInput -> {
assertEquals(TEST_CONNECTOR_NAME, parsedInput.getName());
assertEquals(1, parsedInput.getParameters().size());
Expand Down

0 comments on commit bf48f99

Please sign in to comment.