Skip to content

Commit

Permalink
Merge branch 'develop' into feature/133-replace-spark-test-base
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinwallimann authored Jun 10, 2020
2 parents 1aa1223 + a4e8c1b commit d38e5bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import za.co.absa.hyperdrive.driver.utils.DriverUtil
object CommandLineIngestionDriver extends IngestionDriver {

private val logger = LogManager.getLogger
private val PropertyDelimiter = "="

def main(args: Array[String]): Unit = {
if (args.isEmpty) {
Expand All @@ -52,10 +53,11 @@ object CommandLineIngestionDriver extends IngestionDriver {
}

private def setOrThrow(setting: String, configuration: Configuration): Unit = {
val settingKeyValue = setting.trim.split("=", 2)
if (settingKeyValue.length != 2 || settingKeyValue.exists(_.isEmpty)) {
if(!setting.contains(PropertyDelimiter)) {
throw new IllegalArgumentException(s"Invalid setting format: $setting")
} else {
val settingKeyValue = setting.split(PropertyDelimiter, 2)
configuration.setProperty(settingKeyValue(0).trim, settingKeyValue(1).trim)
}
configuration.setProperty(settingKeyValue(0), settingKeyValue(1))
}
}
2 changes: 2 additions & 0 deletions driver/src/test/resources/ingestion.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ key.equals.sign.in.value=value1=value2
some.long = 3000000000
some.interpolated.value=${some.long}999
some.properties = key1 = value1, key2=value2, key3=value3
key.with.whitespace = the-value
key.without.value=
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class TestCommandLineIngestionDriver extends FlatSpec with Matchers {
config.getString("key.equals.sign.in.value") shouldBe "value1=value2"
config.getLong("some.long") shouldBe 3000000000L
config.getLong("some.interpolated.value") shouldBe 3000000000999L
config.getString("key.with.whitespace") shouldBe "the-value"
config.containsKey("key.without.value") shouldBe true

val properties = config.getProperties("some.properties")
properties.getProperty("key1") shouldBe "value1"
Expand All @@ -44,7 +46,7 @@ class TestCommandLineIngestionDriver extends FlatSpec with Matchers {
}

it should "throw if any configuration is malformed" in {
val invalidSetting = "key2="
val invalidSetting = "key2"
val invalidConfString = Array("key1=value1,value2", invalidSetting, "key3=value3")
val throwable = intercept[IllegalArgumentException](CommandLineIngestionDriver.parseConfiguration(invalidConfString))
assert(throwable.getMessage.toLowerCase.contains(invalidSetting))
Expand All @@ -61,7 +63,9 @@ class TestCommandLineIngestionDriver extends FlatSpec with Matchers {
"key.equals.sign.in.value=value1=value2",
"some.long=3000000000",
"some.interpolated.value=${some.long}999",
"some.properties=key1 = value1, key2=value2, key3=value3"
"some.properties=key1 = value1, key2=value2, key3=value3",
" key.with.whitespace = the-value",
"key.without.value="
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class TestPropertiesIngestionDriver extends FlatSpec with Matchers {
config.getString("key.equals.sign.in.value") shouldBe "value1=value2"
config.getLong("some.long") shouldBe 3000000000L
config.getLong("some.interpolated.value") shouldBe 3000000000999L
config.getString("key.with.whitespace") shouldBe "the-value"
config.containsKey("key.without.value") shouldBe true

val properties = config.getProperties("some.properties")
properties.getProperty("key1") shouldBe "value1"
Expand Down

0 comments on commit d38e5bd

Please sign in to comment.