Skip to content

Commit 65a272f

Browse files
zwangshengulysses-you
authored andcommitted
[KYUUBI #2359] [Test] Build WithKyuubiServerOnKuberntes
### _Why are the changes needed?_ Refactor KyuubiOnKubernetesTestsSuite Build WithKyuubiServerOnKuberntes like WithKyuubiServerOnYarn ### _How was this patch tested?_ - [x] 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 #2359 from zwangsheng/test/kyuubi_on_kubernetes. Closes #2359 c1048c6 [zwangsheng] fix 81c98cd [zwangsheng] unused import 976f909 [zwangsheng] fix bad6720 [zwangsheng] fix 98d8995 [zwangsheng] refactor 628de55 [zwangsheng] style check 9dc6675 [zwangsheng] Build WithKyuubiServerOnKubernetes Authored-by: zwangsheng <2213335496@qq.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent 6d14789 commit 65a272f

File tree

2 files changed

+69
-31
lines changed

2 files changed

+69
-31
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.kyuubi.kubernetes.test
19+
20+
import io.fabric8.kubernetes.client.DefaultKubernetesClient
21+
22+
import org.apache.kyuubi.WithKyuubiServer
23+
import org.apache.kyuubi.config.KyuubiConf
24+
25+
trait WithKyuubiServerOnKubernetes extends WithKyuubiServer {
26+
protected val kyuubiServerConf: KyuubiConf = KyuubiConf()
27+
protected val connectionConf: Map[String, String]
28+
private var miniKubernetesClient: DefaultKubernetesClient = _
29+
30+
final override protected lazy val conf: KyuubiConf = {
31+
connectionConf.foreach { case (k, v) => kyuubiServerConf.set(k, v) }
32+
kyuubiServerConf
33+
}
34+
35+
override def beforeAll(): Unit = {
36+
miniKubernetesClient = MiniKube.getKubernetesClient
37+
super.beforeAll()
38+
}
39+
40+
override def afterAll(): Unit = super.afterAll()
41+
42+
override protected def getJdbcUrl: String = {
43+
val kyuubiServers =
44+
miniKubernetesClient.pods().list().getItems
45+
assert(kyuubiServers.size() == 1)
46+
val kyuubiServer = kyuubiServers.get(0)
47+
// Kyuubi server state should be running since mvn compile is quite slowly..
48+
if (!"running".equalsIgnoreCase(kyuubiServer.getStatus.getPhase)) {
49+
val log =
50+
miniKubernetesClient
51+
.pods()
52+
.withName(kyuubiServer.getMetadata.getName)
53+
.getLog
54+
throw new IllegalStateException(
55+
s"Kyuubi server pod state error: ${kyuubiServer.getStatus.getPhase}, log:\n$log")
56+
}
57+
val kyuubiServerIp = MiniKube.getIp
58+
val kyuubiServerPort =
59+
kyuubiServer.getSpec.getContainers.get(0).getPorts.get(0).getHostPort
60+
s"jdbc:hive2://$kyuubiServerIp:$kyuubiServerPort/;"
61+
}
62+
}

integration-tests/kyuubi-kubernetes-it/src/test/scala/org/apache/kyuubi/kubernetes/test/deployment/KyuubiOnKubernetesTestsSuite.scala

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
package org.apache.kyuubi.kubernetes.test.deployment
1919

20-
import org.apache.kyuubi.Logging
21-
import org.apache.kyuubi.kubernetes.test.MiniKube
20+
import org.apache.kyuubi.kubernetes.test.WithKyuubiServerOnKubernetes
2221
import org.apache.kyuubi.operation.SparkQueryTests
2322

2423
/**
@@ -31,34 +30,11 @@ import org.apache.kyuubi.operation.SparkQueryTests
3130
* | | | |
3231
* ------------ -----------------------------------------------------
3332
*/
34-
class KyuubiOnKubernetesTestsSuite extends SparkQueryTests with Logging {
35-
private lazy val _jdbcUrl: String = {
36-
val kubernetesclient = MiniKube.getKubernetesClient
37-
val kyuubiServers =
38-
kubernetesclient
39-
.pods()
40-
.list()
41-
.getItems
42-
assert(kyuubiServers.size() == 1)
43-
val kyuubiServer = kyuubiServers.get(0)
44-
// Kyuubi server state should be running since mvn compile is quite slowly..
45-
if (!"running".equalsIgnoreCase(kyuubiServer.getStatus.getPhase)) {
46-
val log =
47-
kubernetesclient
48-
.pods()
49-
.withName(kyuubiServer.getMetadata.getName)
50-
.getLog
51-
throw new IllegalStateException(
52-
s"Kyuubi server pod state error: ${kyuubiServer.getStatus.getPhase}, log:\n$log")
53-
}
54-
val kyuubiServerIp = MiniKube.getIp
55-
val kyuubiServerPort =
56-
kyuubiServer.getSpec.getContainers.get(0).getPorts.get(0).getHostPort
57-
s"jdbc:hive2://$kyuubiServerIp:$kyuubiServerPort/;"
58-
}
33+
class KyuubiOnKubernetesWithLocalSparkTestsSuite extends WithKyuubiServerOnKubernetes
34+
with SparkQueryTests {
35+
override protected val connectionConf: Map[String, String] = Map(
36+
"spark.master" -> "local",
37+
"spark.executor.instances" -> "1")
5938

60-
override protected def jdbcUrl: String = {
61-
assert(_jdbcUrl != null, "Failed to get Kyuubi server")
62-
_jdbcUrl
63-
}
39+
override protected def jdbcUrl: String = getJdbcUrl
6440
}

0 commit comments

Comments
 (0)