Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/src/main/scala/kafka/zookeeper/ZooKeeperClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ class ZooKeeperClient(connectString: String,
metricNames += "SessionState"

expiryScheduler.startup()
waitUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)
try waitUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)
catch {
case e: Throwable =>
close()
throw e
}

override def metricName(name: String, metricTags: scala.collection.Map[String, String]): MetricName = {
explicitMetricName(metricGroup, metricType, name, metricTags)
Expand Down
16 changes: 13 additions & 3 deletions core/src/test/scala/unit/kafka/zookeeper/ZooKeeperClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,22 @@ class ZooKeeperClientTest extends ZooKeeperTestHarness {
System.clearProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM)
}

@Test(expected = classOf[ZooKeeperClientTimeoutException])
@Test
def testUnresolvableConnectString(): Unit = {
new ZooKeeperClient("some.invalid.hostname.foo.bar.local", zkSessionTimeout, connectionTimeoutMs = 10,
Int.MaxValue, time, "testMetricGroup", "testMetricType").close()
try {
new ZooKeeperClient("some.invalid.hostname.foo.bar.local", zkSessionTimeout, connectionTimeoutMs = 10,
Int.MaxValue, time, "testMetricGroup", "testMetricType")
} catch {
case e: ZooKeeperClientTimeoutException =>
assertEquals("ZooKeeper client threads still running", Set.empty, runningZkSendThreads)
}
}

private def runningZkSendThreads: collection.Set[String] = Thread.getAllStackTraces.keySet.asScala
.filter(_.isAlive)
.map(_.getName)
.filter(t => t.contains("SendThread()"))

@Test(expected = classOf[ZooKeeperClientTimeoutException])
def testConnectionTimeout(): Unit = {
zookeeper.shutdown()
Expand Down