Skip to content

Commit 4f9922b

Browse files
committed
[KYUUBI #1730] Use getHostName instead of getCanonicalHostName
<!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html 2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'. 3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'. --> ### _Why are the changes needed?_ <!-- Please clarify why the changes are needed. For instance, 1. If you add a feature, you can talk about the use case of it. 2. If you fix a bug, you can clarify why it is a bug. --> ### _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 - [x] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1730 from yaooqinn/zk. Closes #1730 37bfe10 [Kent Yao] do not merge fbf05df [Kent Yao] do not merge Authored-by: Kent Yao <yao@apache.org> Signed-off-by: Kent Yao <yao@apache.org>
1 parent 4c682df commit 4f9922b

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
4343
val maxClientCnxns = conf.get(ZK_MAX_CLIENT_CONNECTIONS)
4444
val minSessionTimeout = conf.get(ZK_MIN_SESSION_TIMEOUT)
4545
val maxSessionTimeout = conf.get(ZK_MAX_SESSION_TIMEOUT)
46-
host = conf.get(ZK_CLIENT_PORT_ADDRESS)
47-
.getOrElse(findLocalInetAddress.getCanonicalHostName)
46+
host = conf.get(ZK_CLIENT_PORT_ADDRESS).getOrElse(findLocalInetAddress.getHostName)
4847

4948
zks = new ZooKeeperServer(dataDirectory, dataDirectory, tickTime)
5049
zks.setMinSessionTimeout(minSessionTimeout)
@@ -75,6 +74,6 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
7574

7675
def getConnectString: String = synchronized {
7776
assert(zks != null, s"$getName is in $getServiceState")
78-
s"${host}:${serverFactory.getLocalPort}"
77+
s"$host:${serverFactory.getLocalPort}"
7978
}
8079
}

kyuubi-zookeeper/src/test/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeperSuite.scala

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,18 @@ import org.apache.curator.retry.ExponentialBackoffRetry
2323

2424
import org.apache.kyuubi.KyuubiFunSuite
2525
import org.apache.kyuubi.config.KyuubiConf
26-
import org.apache.kyuubi.service.ServiceState._
2726
import org.apache.kyuubi.zookeeper.ZookeeperConf.{ZK_CLIENT_PORT, ZK_CLIENT_PORT_ADDRESS}
2827

2928
class EmbeddedZookeeperSuite extends KyuubiFunSuite {
29+
private var zkServer: EmbeddedZookeeper = _
3030

31-
test("embedded zookeeper server") {
32-
val zkServer = new EmbeddedZookeeper()
33-
assert(zkServer.getConf == null)
34-
assert(zkServer.getName === zkServer.getClass.getSimpleName)
35-
assert(zkServer.getServiceState === LATENT)
36-
val conf = KyuubiConf()
37-
conf.set(ZookeeperConf.ZK_CLIENT_PORT, 0)
38-
zkServer.stop() // only for test coverage
39-
zkServer.initialize(conf)
40-
assert(zkServer.getConf === conf)
41-
assert(zkServer.getServiceState === INITIALIZED)
42-
assert(zkServer.getStartTime === 0)
43-
zkServer.start()
44-
assert(zkServer.getServiceState === STARTED)
45-
assert(zkServer.getStartTime !== 0)
46-
zkServer.stop()
47-
assert(zkServer.getServiceState === STOPPED)
31+
override def afterEach(): Unit = {
32+
if (zkServer != null) zkServer.stop()
33+
super.afterEach()
4834
}
4935

5036
test("connect test with embedded zookeeper") {
51-
val zkServer = new EmbeddedZookeeper()
37+
zkServer = new EmbeddedZookeeper()
5238
intercept[AssertionError](zkServer.getConnectString)
5339
zkServer.initialize(KyuubiConf().set(ZookeeperConf.ZK_CLIENT_PORT, 0))
5440
zkServer.start()
@@ -65,7 +51,7 @@ class EmbeddedZookeeperSuite extends KyuubiFunSuite {
6551
}
6652

6753
test("use zookeeper.embedded.client.port.address cover default hostname") {
68-
var zkServer = new EmbeddedZookeeper()
54+
zkServer = new EmbeddedZookeeper()
6955
// cover default hostname
7056
var conf = KyuubiConf()
7157
.set(ZK_CLIENT_PORT, 0)

0 commit comments

Comments
 (0)