Skip to content

Commit

Permalink
Reverts back model tests that were modified incorrectly by connector …
Browse files Browse the repository at this point in the history
…change

When creating a code change to the connector it propagated the new change of the object that affected many UTs, but after changing the logic of indexing the new connector, change the old changes for the unit test involving models with connectors had to be reverted back. UTs specifically for the indexed connectors have been created in UpdateConnectorTransportActionTests were done to capture this

Signed-off-by: Brian Flores <[email protected]>
  • Loading branch information
brianf-aws committed Sep 18, 2024
1 parent c606ffa commit 15aa958
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import static org.opensearch.core.xcontent.ToXContent.EMPTY_PARAMS;

import java.io.IOException;
import java.time.Instant;

import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.opensearch.common.io.stream.BytesStreamOutput;
Expand All @@ -21,7 +19,6 @@
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.ml.common.connector.AbstractConnector;
import org.opensearch.ml.common.connector.Connector;
import org.opensearch.ml.common.connector.HttpConnectorTest;

Expand Down Expand Up @@ -52,30 +49,21 @@ public void toXContent_ConnectorId() throws IOException {
@Test
public void toXContent_InternalConnector() throws IOException {
Connector connector = HttpConnectorTest.createHttpConnector();
Instant testTime = Instant.now();

MLModel mlModel = MLModel
.builder()
.algorithm(FunctionName.REMOTE)
.name("test_model_name")
.version("1.0.0")
.modelGroupId("test_group_id")
.description("test model")
.createdTime(testTime)
.lastUpdateTime(testTime)
.connector(connector)
.build();
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
mlModel.toXContent(builder, EMPTY_PARAMS);
String mlModelContent = TestHelper.xContentBuilderToString(builder);

JSONObject mlModelJsonObject = new JSONObject(mlModelContent);
long mlModelCreatedTime = mlModelJsonObject.getLong(AbstractConnector.CREATED_TIME_FIELD);
long mlModelLastUpdatedTime = mlModelJsonObject.getLong(AbstractConnector.LAST_UPDATED_TIME_FIELD);

String expectedConnectorResponseFormat = "{\"name\":\"test_model_name\",\"model_group_id\":\"test_group_id\","
String expectedConnectorResponse = "{\"name\":\"test_model_name\",\"model_group_id\":\"test_group_id\","
+ "\"algorithm\":\"REMOTE\",\"model_version\":\"1.0.0\",\"description\":\"test model\","
+ "\"created_time\":%d,\"last_updated_time\":%d,"
+ "\"connector\":{\"name\":\"test_connector_name\",\"version\":\"1\","
+ "\"description\":\"this is a test connector\",\"protocol\":\"http\","
+ "\"parameters\":{\"input\":\"test input value\"},\"credential\":{\"key\":\"test_key_value\"},"
Expand All @@ -88,7 +76,6 @@ public void toXContent_InternalConnector() throws IOException {
+ "\"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\"}}}";

String expectedConnectorResponse = String.format(expectedConnectorResponseFormat, mlModelCreatedTime, mlModelLastUpdatedTime);
assertEquals(expectedConnectorResponse, mlModelContent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class MLRegisterModelInputTest {
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}],"
+ "\"backend_roles\":[\"role1\",\"role2\"],\"access\":\"public\","
+ "\"created_time\":1725914397441,\"last_updated_time\":1725914397441,"
+ "\"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}";
private final FunctionName functionName = FunctionName.LINEAR_REGRESSION;
Expand Down

0 comments on commit 15aa958

Please sign in to comment.