From 7c8f0f617fbae50aeb8360d424ff619ba8e0c0ac Mon Sep 17 00:00:00 2001 From: Ewen Cheslack-Postava Date: Mon, 26 Jun 2017 11:20:19 -0700 Subject: [PATCH] MINOR: Make JmxMixin wait for the monitored process to be listening on the JMX port before launching JmxTool --- tests/kafkatest/services/monitor/jmx.py | 9 +++++++++ tests/kafkatest/tests/produce_consume_validate.py | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/kafkatest/services/monitor/jmx.py b/tests/kafkatest/services/monitor/jmx.py index e64d03afd48d7..0859bb44d2f8e 100644 --- a/tests/kafkatest/services/monitor/jmx.py +++ b/tests/kafkatest/services/monitor/jmx.py @@ -50,6 +50,15 @@ def start_jmx_tool(self, idx, node): self.logger.debug("%s: jmx tool has been started already on this node" % node.account) return + # JmxTool is not particularly robust to slow-starting processes. In order to ensure JmxTool doesn't fail if the + # process we're trying to monitor takes awhile before listening on the JMX port, wait until we can see that port + # listening before even launching JmxTool + def check_jmx_port_listening(): + return 0 == node.account.ssh("nc -z 127.0.0.1 %d" % self.jmx_port, allow_fail=True) + + wait_until(check_jmx_port_listening, timeout_sec=30, backoff_sec=.1, + err_msg="%s: Never saw JMX port for %s start listening" % (node.account, self)) + cmd = "%s kafka.tools.JmxTool " % self.path.script("kafka-run-class.sh", node) cmd += "--reporting-interval 1000 --jmx-url service:jmx:rmi:///jndi/rmi://127.0.0.1:%d/jmxrmi" % self.jmx_port for jmx_object_name in self.jmx_object_names: diff --git a/tests/kafkatest/tests/produce_consume_validate.py b/tests/kafkatest/tests/produce_consume_validate.py index 079305c8c7ff4..7a78da3c5f09c 100644 --- a/tests/kafkatest/tests/produce_consume_validate.py +++ b/tests/kafkatest/tests/produce_consume_validate.py @@ -59,12 +59,6 @@ def start_producer_and_consumer(self): err_msg="Consumer process took more than %d s to fork" %\ self.consumer_init_timeout_sec) end = int(time.time()) - # If `JMXConnectFactory.connect` is invoked during the - # initialization of the JMX server, it may fail to throw the - # specified IOException back to the calling code. The sleep is a - # workaround that should allow initialization to complete before we - # try to connect. See KAFKA-4620 for more details. - time.sleep(1) remaining_time = self.consumer_init_timeout_sec - (end - start) if remaining_time < 0 : remaining_time = 0