[KYUUBI #2453] [Improvement] checkValue of TypedConfigBuilder shall also print the config name

### _Why are the changes needed?_

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #2465 from zhaomin1423/2453.

Closes #2453

8a624991 [Min Zhao] fix tset
54ee09df [Min Zhao] fix suite
3d434a78 [Min Zhao] [KYUUBI #2453] [Improvement] checkValue of TypedConfigBuilder shall also print the config name
f7c7bf27 [Min Zhao] [KYUUBI #2453] [Improvement] checkValue of TypedConfigBuilder shall also print the config name

Authored-by: Min Zhao <zhaomin1423@163.com>
Signed-off-by: ulysses-you <ulyssesyou@apache.org>
This commit is contained in:
Min Zhao 2022-04-26 09:40:42 +08:00 committed by ulysses-you
parent 40739a9f78
commit 68ac8a19f3
No known key found for this signature in database
GPG Key ID: 4C500BC62D576766
4 changed files with 17 additions and 3 deletions

View File

@ -136,7 +136,9 @@ private[kyuubi] case class TypedConfigBuilder[T](
/** Checks if the user-provided value for the config matches the validator. */
def checkValue(validator: T => Boolean, errMsg: String): TypedConfigBuilder[T] = {
transform { v =>
if (!validator(v)) throw new IllegalArgumentException(errMsg)
if (!validator(v)) {
throw new IllegalArgumentException(s"'$v' in ${parent.key} is invalid. $errMsg")
}
v
}
}

View File

@ -81,4 +81,16 @@ class ConfigBuilderSuite extends KyuubiFunSuite {
val e = intercept[IllegalArgumentException](kyuubiConf.get(timeConf))
assert(e.getMessage startsWith "The formats accepted are 1) based on the ISO-8601")
}
test("invalid config") {
val intConf = ConfigBuilder("kyuubi.invalid.config")
.intConf
.checkValue(t => t > 0, "must be positive integer")
.createWithDefault(3)
assert(intConf.key === "kyuubi.invalid.config")
assert(intConf.defaultVal.get === 3)
val kyuubiConf = KyuubiConf().set(intConf.key, "-1")
val e = intercept[IllegalArgumentException](kyuubiConf.get(intConf))
assert(e.getMessage equals "'-1' in kyuubi.invalid.config is invalid. must be positive integer")
}
}

View File

@ -58,7 +58,7 @@ class KyuubiAuthenticationFactorySuite extends KyuubiFunSuite {
test("AuthType Other") {
val conf = KyuubiConf().set(KyuubiConf.AUTHENTICATION_METHOD, Seq("INVALID"))
val e = intercept[IllegalArgumentException](new KyuubiAuthenticationFactory(conf))
assert(e.getMessage === "the authentication type should be one or more of" +
assert(e.getMessage contains "the authentication type should be one or more of" +
" NOSASL,NONE,LDAP,KERBEROS,CUSTOM")
}

View File

@ -92,7 +92,7 @@ class KyuubiServerSuite extends KyuubiFunSuite {
test("invalid port") {
val conf = KyuubiConf().set(KyuubiConf.FRONTEND_THRIFT_BINARY_BIND_PORT, 100)
val e = intercept[IllegalArgumentException](new KyuubiServer().initialize(conf))
assert(e.getMessage === "Invalid Port number")
assert(e.getMessage contains "Invalid Port number")
}
test("invalid zookeeper quorum") {