From fc18739bf4742c8a3f3038c7f52151cf62a3d929 Mon Sep 17 00:00:00 2001 From: Brian Flores Date: Tue, 17 Sep 2024 10:42:52 -0700 Subject: [PATCH] fix failing MLRegisterModelInutTest.testToXContent tests Originally this commit was cherry picked from the 2.x branch and as such code changes affected the new build that werent caught on the previous commit 8c006de. Reformatted tests that were failing as the behavior implemented in previous commits was to not display time fields if a connector does not have them in the first place. gradlew build was done to assure the tests passed Signed-off-by: Brian Flores --- .../register/MLRegisterModelInputTest.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/common/src/test/java/org/opensearch/ml/common/transport/register/MLRegisterModelInputTest.java b/common/src/test/java/org/opensearch/ml/common/transport/register/MLRegisterModelInputTest.java index 7651dfa859..13851ebaf8 100644 --- a/common/src/test/java/org/opensearch/ml/common/transport/register/MLRegisterModelInputTest.java +++ b/common/src/test/java/org/opensearch/ml/common/transport/register/MLRegisterModelInputTest.java @@ -9,7 +9,6 @@ import java.util.Collections; import java.util.function.Consumer; -import org.json.JSONObject; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -170,11 +169,7 @@ public void testToXContent() throws Exception { assertNotNull(builder); String jsonStr = builder.toString(); - JSONObject connectorJsonObject = new JSONObject(jsonStr); - long connectorCreatedTime = connectorJsonObject.getJSONObject("connector").getLong("created_time"); - long connectorLastUpdatedTime = connectorJsonObject.getJSONObject("connector").getLong("last_updated_time"); - - String expectedFunctionInputStrFormat = "{\"function_name\":\"LINEAR_REGRESSION\",\"name\":\"modelName\"," + String expectedFunctionInputStr = "{\"function_name\":\"LINEAR_REGRESSION\",\"name\":\"modelName\"," + "\"version\":\"version\",\"model_group_id\":\"modelGroupId\",\"description\":\"test description\"," + "\"url\":\"url\",\"model_content_hash_value\":\"hash_value_test\",\"model_format\":\"ONNX\"," + "\"model_config\":{\"model_type\":\"testModelType\",\"embedding_dimension\":100," @@ -189,11 +184,9 @@ public void testToXContent() throws Exception { + "\"pre_process_function\":\"connector.pre_process.openai.embedding\"," + "\"post_process_function\":\"connector.post_process.openai.embedding\"}]," + "\"backend_roles\":[\"role1\",\"role2\"],\"access\":\"public\"," - + "\"created_time\":%d,\"last_updated_time\":%d," + "\"client_config\":{\"max_connection\":30,\"connection_timeout\":30000,\"read_timeout\":30000," + "\"retry_backoff_millis\":10,\"retry_timeout_seconds\":10,\"max_retry_times\":-1,\"retry_backoff_policy\":\"constant\"}},\"is_hidden\":false}"; - String expectedFunctionInputStr = String.format(expectedFunctionInputStrFormat, connectorCreatedTime, connectorLastUpdatedTime); assertEquals(expectedFunctionInputStr, jsonStr); } @@ -208,11 +201,8 @@ public void testToXContent_Incomplete() throws Exception { assertNotNull(builder); String jsonStr = builder.toString(); - JSONObject connectorJsonObject = new JSONObject(jsonStr); - long connectorCreatedTime = connectorJsonObject.getJSONObject("connector").getLong("created_time"); - long connectorLastUpdatedTime = connectorJsonObject.getJSONObject("connector").getLong("last_updated_time"); - String expectedIncompleteInputStrFormat = "{\"function_name\":\"LINEAR_REGRESSION\"," + String expectedIncompleteInputStr = "{\"function_name\":\"LINEAR_REGRESSION\"," + "\"name\":\"modelName\",\"version\":\"version\",\"model_group_id\":\"modelGroupId\"," + "\"description\":\"test description\",\"model_content_hash_value\":\"hash_value_test\"," + "\"deploy_model\":true,\"connector\":{\"name\":\"test_connector_name\",\"version\":\"1\"," @@ -224,11 +214,9 @@ public void testToXContent_Incomplete() throws Exception { + "\"pre_process_function\":\"connector.pre_process.openai.embedding\"," + "\"post_process_function\":\"connector.post_process.openai.embedding\"}]," + "\"backend_roles\":[\"role1\",\"role2\"],\"access\":\"public\"," - + "\"created_time\":%d,\"last_updated_time\":%d," + "\"client_config\":{\"max_connection\":30,\"connection_timeout\":30000,\"read_timeout\":30000," + "\"retry_backoff_millis\":10,\"retry_timeout_seconds\":10,\"max_retry_times\":-1,\"retry_backoff_policy\":\"constant\"}},\"is_hidden\":false}"; - String expectedIncompleteInputStr = String.format(expectedIncompleteInputStrFormat, connectorCreatedTime, connectorLastUpdatedTime); assertEquals(expectedIncompleteInputStr, jsonStr); }