From 3128499b946ee1ba4612dbe3a6ab016f8d1caeaa Mon Sep 17 00:00:00 2001 From: Chen Dai Date: Thu, 5 Oct 2023 14:17:30 -0700 Subject: [PATCH] Add more UT on config class Signed-off-by: Chen Dai --- .../SparkExecutionEngineConfigTest.java | 49 +++++++++++++++++++ .../dispatcher/SparkQueryDispatcherTest.java | 2 - 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 spark/src/test/java/org/opensearch/sql/spark/config/SparkExecutionEngineConfigTest.java diff --git a/spark/src/test/java/org/opensearch/sql/spark/config/SparkExecutionEngineConfigTest.java b/spark/src/test/java/org/opensearch/sql/spark/config/SparkExecutionEngineConfigTest.java new file mode 100644 index 0000000000..29b69ea830 --- /dev/null +++ b/spark/src/test/java/org/opensearch/sql/spark/config/SparkExecutionEngineConfigTest.java @@ -0,0 +1,49 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.spark.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +public class SparkExecutionEngineConfigTest { + + @Test + public void testToSparkExecutionEngineConfigWithoutAllFields() { + String json = + "{" + + "\"applicationId\": \"app-1\"," + + "\"executionRoleARN\": \"role-1\"," + + "\"region\": \"us-west-1\"" + + "}"; + SparkExecutionEngineConfig config = + SparkExecutionEngineConfig.toSparkExecutionEngineConfig(json); + + assertEquals("app-1", config.getApplicationId()); + assertEquals("role-1", config.getExecutionRoleARN()); + assertEquals("us-west-1", config.getRegion()); + assertNull(config.getSparkSubmitParameters()); + } + + @Test + public void testToSparkExecutionEngineConfigWithAllFields() { + String json = + "{" + + "\"applicationId\": \"app-1\"," + + "\"executionRoleARN\": \"role-1\"," + + "\"region\": \"us-west-1\"," + + "\"sparkSubmitParameters\": \"--conf A=1\"" + + "}"; + SparkExecutionEngineConfig config = + SparkExecutionEngineConfig.toSparkExecutionEngineConfig(json); + + assertEquals("app-1", config.getApplicationId()); + assertEquals("role-1", config.getExecutionRoleARN()); + assertEquals("us-west-1", config.getRegion()); + assertEquals("--conf A=1", config.getSparkSubmitParameters()); + } +} diff --git a/spark/src/test/java/org/opensearch/sql/spark/dispatcher/SparkQueryDispatcherTest.java b/spark/src/test/java/org/opensearch/sql/spark/dispatcher/SparkQueryDispatcherTest.java index 5858227552..7d97cc6c50 100644 --- a/spark/src/test/java/org/opensearch/sql/spark/dispatcher/SparkQueryDispatcherTest.java +++ b/spark/src/test/java/org/opensearch/sql/spark/dispatcher/SparkQueryDispatcherTest.java @@ -574,8 +574,6 @@ void testGetQueryResponseWithSuccess() { dataSourceUserAuthorizationHelper, jobExecutionResponseReader, flintIndexMetadataReader); - when(emrServerlessClient.getJobRunResult(EMRS_APPLICATION_ID, EMR_JOB_ID)) - .thenReturn(new GetJobRunResult().withJobRun(new JobRun().withState(JobRunState.SUCCESS))); JSONObject queryResult = new JSONObject(); Map resultMap = new HashMap<>(); resultMap.put(STATUS_FIELD, "SUCCESS");