Browse Source

MINOR: Fix Jmxtool to honour wait option when MBean is not yet avaibale in MBean server (#13995)

In JmxTool.scala, we will wait till all the object names are available from MBean server. But in the newer version, we only wait for subset of object names. Due to this, we may not enforce wait option and prematurely return the result if the objects are not yet registered in MBean sever.

Reviewers: Luke Chen <showuon@gmail.com>, Federico Valeri <fvaleri@redhat.com>
pull/14007/head
Manikumar Reddy 1 year ago committed by GitHub
parent
commit
4e85bc9f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      tools/src/main/java/org/apache/kafka/tools/JmxTool.java
  2. 13
      tools/src/test/java/org/apache/kafka/tools/JmxToolTest.java

2
tools/src/main/java/org/apache/kafka/tools/JmxTool.java

@ -169,7 +169,7 @@ public class JmxTool { @@ -169,7 +169,7 @@ public class JmxTool {
long waitTimeoutMs = 10_000;
Set<ObjectName> result = new HashSet<>();
Set<ObjectName> querySet = new HashSet<>(queries);
BiPredicate<Set<ObjectName>, Set<ObjectName>> foundAllObjects = Set::containsAll;
BiPredicate<Set<ObjectName>, Set<ObjectName>> foundAllObjects = Set::equals;
long start = System.currentTimeMillis();
do {
if (!result.isEmpty()) {

13
tools/src/test/java/org/apache/kafka/tools/JmxToolTest.java

@ -337,6 +337,19 @@ public class JmxToolTest { @@ -337,6 +337,19 @@ public class JmxToolTest {
assertTrue(validDateFormat(dateFormat, csv.get("time")));
}
@Test
public void unknownObjectName() {
String[] args = new String[]{
"--jmx-url", jmxUrl,
"--object-name", "kafka.server:type=DummyMetrics,name=MessagesInPerSec",
"--wait"
};
String err = executeAndGetErr(args);
assertCommandFailure();
assertTrue(err.contains("Could not find all requested object names after 10000 ms"));
}
private static int findRandomOpenPortOnAllLocalInterfaces() throws Exception {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();

Loading…
Cancel
Save