forked from opensearch-project/opensearch-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation for index options (opensearch-project#66)
* Add validation for index options Signed-off-by: Chen Dai <[email protected]> * Add options with default method Signed-off-by: Chen Dai <[email protected]> * Change IT for options with default Signed-off-by: Chen Dai <[email protected]> * Add IT for invalid option test Signed-off-by: Chen Dai <[email protected]> * Remove toString and add more UT Signed-off-by: Chen Dai <[email protected]> * Update doc Signed-off-by: Chen Dai <[email protected]> * Refactor validate method Signed-off-by: Chen Dai <[email protected]> --------- Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
Showing
9 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...k-integration/src/test/scala/org/opensearch/flint/spark/FlintSparkIndexOptionsSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark | ||
|
||
import org.opensearch.flint.spark.FlintSparkIndexOptions.OptionName.{AUTO_REFRESH, CHECKPOINT_LOCATION, INDEX_SETTINGS, REFRESH_INTERVAL} | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import org.apache.spark.FlintSuite | ||
|
||
class FlintSparkIndexOptionsSuite extends FlintSuite with Matchers { | ||
|
||
test("should return lowercase name as option name") { | ||
AUTO_REFRESH.toString shouldBe "auto_refresh" | ||
REFRESH_INTERVAL.toString shouldBe "refresh_interval" | ||
CHECKPOINT_LOCATION.toString shouldBe "checkpoint_location" | ||
INDEX_SETTINGS.toString shouldBe "index_settings" | ||
} | ||
|
||
test("should return specified option value") { | ||
val options = FlintSparkIndexOptions( | ||
Map( | ||
"auto_refresh" -> "true", | ||
"refresh_interval" -> "1 Minute", | ||
"checkpoint_location" -> "s3://test/", | ||
"index_settings" -> """{"number_of_shards": 3}""")) | ||
|
||
options.autoRefresh() shouldBe true | ||
options.refreshInterval() shouldBe Some("1 Minute") | ||
options.checkpointLocation() shouldBe Some("s3://test/") | ||
options.indexSettings() shouldBe Some("""{"number_of_shards": 3}""") | ||
} | ||
|
||
test("should return default option value if unspecified") { | ||
val options = FlintSparkIndexOptions(Map.empty) | ||
|
||
options.autoRefresh() shouldBe false | ||
options.refreshInterval() shouldBe empty | ||
options.checkpointLocation() shouldBe empty | ||
options.indexSettings() shouldBe empty | ||
options.optionsWithDefault should contain("auto_refresh" -> "false") | ||
} | ||
|
||
test("should return default option value if unspecified with specified value") { | ||
val options = FlintSparkIndexOptions(Map("refresh_interval" -> "1 Minute")) | ||
|
||
options.optionsWithDefault shouldBe Map( | ||
"auto_refresh" -> "false", | ||
"refresh_interval" -> "1 Minute") | ||
} | ||
|
||
test("should report error if any unknown option name") { | ||
the[IllegalArgumentException] thrownBy | ||
FlintSparkIndexOptions(Map("autoRefresh" -> "true")) | ||
|
||
the[IllegalArgumentException] thrownBy | ||
FlintSparkIndexOptions(Map("AUTO_REFRESH" -> "true")) | ||
|
||
the[IllegalArgumentException] thrownBy { | ||
FlintSparkIndexOptions(Map("auto_refresh" -> "true", "indexSetting" -> "test")) | ||
} should have message "requirement failed: option name indexSetting is invalid" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters