diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/service/NoopServer.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/NoopServer.scala index 7b80b809c..72ecfa1ff 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/service/NoopServer.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/NoopServer.scala @@ -22,6 +22,13 @@ import org.apache.kyuubi.KyuubiException class NoopServer extends Serverable("noop") { override private[kyuubi] val backendService = new NoopBackendService + override def start(): Unit = { + super.start() + if (getConf.getOption("kyuubi.test.should.fail").exists(_.toBoolean)) { + throw new IllegalArgumentException("should fail") + } + } + override protected def stopServer(): Unit = { throw new KyuubiException("no need to stop me") } diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/service/ServerableSuite.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/ServerableSuite.scala new file mode 100644 index 000000000..f5fdba363 --- /dev/null +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/ServerableSuite.scala @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kyuubi.service + +import org.apache.kyuubi.{KyuubiException, KyuubiFunSuite} +import org.apache.kyuubi.config.KyuubiConf + +class ServerableSuite extends KyuubiFunSuite { + + test("Serverable") { + val serverable = new NoopServer() + serverable.stop() + assert(serverable.getStartTime === 0) + assert(serverable.getConf === null) + assert(serverable.getName === "noop") + intercept[IllegalStateException](serverable.connectionUrl) + assert(serverable.getServiceState === ServiceState.LATENT) + intercept[IllegalStateException](serverable.start()) + + val conf = KyuubiConf().set(KyuubiConf.FRONTEND_BIND_PORT, 0) + serverable.initialize(conf) + serverable.stop() + assert(serverable.getStartTime === 0) + assert(serverable.getConf === conf) + assert(serverable.connectionUrl.nonEmpty) + assert(serverable.getServiceState === ServiceState.INITIALIZED) + serverable.start() + assert(serverable.getStartTime !== 0) + assert(serverable.getConf === conf) + assert(serverable.getServiceState === ServiceState.STARTED) + serverable.stop() + assert(serverable.getStartTime !== 0) + assert(serverable.getConf === conf) + assert(serverable.connectionUrl.nonEmpty) + assert(serverable.getServiceState === ServiceState.STOPPED) + serverable.stop() + } + + test("invalid port") { + val conf = KyuubiConf().set(KyuubiConf.FRONTEND_BIND_PORT, 100) + val e = intercept[KyuubiException](new NoopServer().initialize(conf)) + assert(e.getMessage === "Failed to initialize frontend service") + assert(e.getCause.getMessage === "Invalid Port number") + } + + test("error start child services") { + val conf = KyuubiConf() + .set(KyuubiConf.FRONTEND_BIND_PORT, 0) + .set("kyuubi.test.should.fail", "true") + val server = new NoopServer() + server.initialize(conf) + val e = intercept[IllegalArgumentException](server.start()) + assert(e.getMessage === "should fail") + } +} diff --git a/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthenticationProviderFactorySuite.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/authentication/AuthenticationProviderFactorySuite.scala similarity index 57% rename from kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthenticationProviderFactorySuite.scala rename to kyuubi-common/src/test/scala/org/apache/kyuubi/service/authentication/AuthenticationProviderFactorySuite.scala index 0c5adc545..0bd29ac56 100644 --- a/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthenticationProviderFactorySuite.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/service/authentication/AuthenticationProviderFactorySuite.scala @@ -6,7 +6,7 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,25 +15,24 @@ * limitations under the License. */ -package yaooqinn.kyuubi.auth +package org.apache.kyuubi.service.authentication import javax.security.sasl.AuthenticationException -import org.apache.spark.{SparkConf, SparkFunSuite} +import org.apache.kyuubi.{KyuubiFunSuite, Utils} +import org.apache.kyuubi.config.KyuubiConf -import org.apache.kyuubi.service.authentication.AuthenticationProviderFactory +class AuthenticationProviderFactorySuite extends KyuubiFunSuite { -class AuthenticationProviderFactorySuite extends SparkFunSuite { - - test("testGetAuthenticationProvider") { - val conf = new SparkConf() - val anonymous = AuthenticationProviderFactory.getAuthenticationProvider(AuthMethods.NONE, conf) - anonymous.authenticate("test", "test") - - val ldap = AuthenticationProviderFactory.getAuthenticationProvider(AuthMethods.LDAP, conf) - val exception = intercept[AuthenticationException](ldap.authenticate("test", "test")) - assert(exception.getMessage.contains("Error validating LDAP user:")) + import AuthenticationProviderFactory._ + test("get auth provider") { + val conf = KyuubiConf() + val p1 = getAuthenticationProvider(AuthMethods.withName("NONE"), conf) + p1.authenticate(Utils.currentUser, "") + val p2 = getAuthenticationProvider(AuthMethods.withName("LDAP"), conf) + val e1 = intercept[AuthenticationException](p2.authenticate("test", "test")) + assert(e1.getMessage.contains("Error validating LDAP user:")) val e2 = intercept[AuthenticationException]( AuthenticationProviderFactory.getAuthenticationProvider(null, conf)) assert(e2.getMessage === "Not a valid authentication method") diff --git a/kyuubi-main/src/test/scala/org/apache/kyuubi/server/KyuubiServerSuite.scala b/kyuubi-main/src/test/scala/org/apache/kyuubi/server/KyuubiServerSuite.scala index 2882162d1..4a7078235 100644 --- a/kyuubi-main/src/test/scala/org/apache/kyuubi/server/KyuubiServerSuite.scala +++ b/kyuubi-main/src/test/scala/org/apache/kyuubi/server/KyuubiServerSuite.scala @@ -25,11 +25,13 @@ class KyuubiServerSuite extends KyuubiFunSuite { test("kyuubi server basic") { val server = new KyuubiServer() + server.stop() val conf = KyuubiConf().set(KyuubiConf.FRONTEND_BIND_PORT, 0) assert(server.getServices.isEmpty) assert(server.getServiceState === LATENT) val e = intercept[IllegalStateException](server.connectionUrl) assert(e.getMessage === "Illegal Service State: LATENT") + assert(server.getConf === null) server.initialize(conf) assert(server.getServiceState === INITIALIZED) @@ -37,16 +39,22 @@ class KyuubiServerSuite extends KyuubiFunSuite { assert(backendService.getServiceState == INITIALIZED) assert(backendService.getServices.forall(_.getServiceState === INITIALIZED)) assert(server.connectionUrl.split(":").length === 2) + assert(server.getConf === conf) + assert(server.getStartTime === 0) + server.stop() + server.start() assert(server.getServiceState === STARTED) assert(backendService.getServiceState == STARTED) assert(backendService.getServices.forall(_.getServiceState === STARTED)) + assert(server.getStartTime !== 0) server.stop() assert(server.getServiceState === STOPPED) assert(backendService.getServiceState == STOPPED) assert(backendService.getServices.forall(_.getServiceState === STOPPED)) + server.stop() } test("invalid port") { diff --git a/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthMethodsSuite.scala b/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthMethodsSuite.scala deleted file mode 100644 index 9a2ce20ee..000000000 --- a/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthMethodsSuite.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package yaooqinn.kyuubi.auth - -import javax.security.sasl.AuthenticationException - -import org.apache.spark.SparkFunSuite - -import yaooqinn.kyuubi.auth.AuthMethods._ - -class AuthMethodsSuite extends SparkFunSuite { - - test("get valid auth method") { - assert(getValidAuthMethod("NONE") === NONE) - assert(getValidAuthMethod(NONE.toString) === NONE) - assert(getValidAuthMethod("LDAP") === LDAP) - assert(getValidAuthMethod(LDAP.toString) === LDAP) - - assert(NONE.toString === "NONE") - intercept[AuthenticationException](getValidAuthMethod("ELSE")) - } -} diff --git a/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthTypeSuite.scala b/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthTypeSuite.scala deleted file mode 100644 index a3f16ae19..000000000 --- a/kyuubi-server/src/test/scala/yaooqinn/kyuubi/auth/AuthTypeSuite.scala +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package yaooqinn.kyuubi.auth - -import org.apache.spark.SparkFunSuite - -import yaooqinn.kyuubi.auth.AuthType._ -import yaooqinn.kyuubi.service.ServiceException - -class AuthTypeSuite extends SparkFunSuite { - - test("to auth type") { - assert(toAuthType("NOSASL") === NOSASL) - assert(toAuthType(NOSASL.toString) === NOSASL) - - assert(toAuthType("NONE") === NONE) - assert(toAuthType(NONE.toString) === NONE) - - assert(toAuthType("LDAP") === LDAP) - assert(toAuthType(LDAP.toString) === LDAP) - - assert(toAuthType("KERBEROS") === KERBEROS) - assert(toAuthType(KERBEROS.toString) === KERBEROS) - - intercept[ServiceException](toAuthType("ELSE")) - } -}