mimaison commented on code in PR #13122:
URL: https://github.com/apache/kafka/pull/13122#discussion_r1179318267


##########
tools/src/test/java/org/apache/kafka/tools/LogDirsCommandTest.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools;
+
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.MockAdminClient;
+import org.apache.kafka.common.Node;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class LogDirsCommandTest {
+
+    @Test
+    public void shouldThrowWhenQueryingNonExistentBrokers() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            assertThrows(RuntimeException.class, () -> 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--broker-list", 
"0,1,2", "--describe"), adminClient));
+        }
+    }
+
+    @Test
+    public void shouldThrowWhenDuplicatedBrokers() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            assertThrows(RuntimeException.class, () -> 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--broker-list", 
"0,0,1,2,2", "--describe"), adminClient));

Review Comment:
   This does not throw because duplicate broker ids have been provided but 
instead because broker 0 and 2 don't exist:
   ```
   ERROR: The given brokers do not exist from --broker-list: 0,2. Current 
existent brokers: 1
   ```



##########
tools/src/test/java/org/apache/kafka/tools/LogDirsCommandTest.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools;
+
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.MockAdminClient;
+import org.apache.kafka.common.Node;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class LogDirsCommandTest {
+
+    @Test
+    public void shouldThrowWhenQueryingNonExistentBrokers() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            assertThrows(RuntimeException.class, () -> 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--broker-list", 
"0,1,2", "--describe"), adminClient));
+        }
+    }
+
+    @Test
+    public void shouldThrowWhenDuplicatedBrokers() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            assertThrows(RuntimeException.class, () -> 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--broker-list", 
"0,0,1,2,2", "--describe"), adminClient));
+        }
+    }
+
+    @Test
+    public void shouldQueryAllBrokersIfNonSpecified() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            String standardOutput = 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--describe"), 
adminClient);
+            String[] standardOutputLines = standardOutput.split("\n");
+            assertTrue(standardOutputLines.length != 0);
+            assertTrue(standardOutputLines[0].contains("Querying brokers for 
log directories information"));

Review Comment:
   This message is also printed if you specify a specific broker id. Actually 
the test pass if I had `"--broker-list", "1"` to the arguments



##########
tools/src/test/java/org/apache/kafka/tools/LogDirsCommandTest.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools;
+
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.MockAdminClient;
+import org.apache.kafka.common.Node;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class LogDirsCommandTest {
+
+    @Test
+    public void shouldThrowWhenQueryingNonExistentBrokers() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            assertThrows(RuntimeException.class, () -> 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--broker-list", 
"0,1,2", "--describe"), adminClient));
+        }
+    }
+
+    @Test
+    public void shouldThrowWhenDuplicatedBrokers() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            assertThrows(RuntimeException.class, () -> 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--broker-list", 
"0,0,1,2,2", "--describe"), adminClient));
+        }
+    }
+
+    @Test
+    public void shouldQueryAllBrokersIfNonSpecified() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            String standardOutput = 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--describe"), 
adminClient);
+            String[] standardOutputLines = standardOutput.split("\n");
+            assertTrue(standardOutputLines.length != 0);
+            assertTrue(standardOutputLines[0].contains("Querying brokers for 
log directories information"));
+        }
+    }
+
+    @Test
+    public void shouldQuerySpecifiedBroker() {
+        Node broker = new Node(1, "hostname", 9092);
+        try (MockAdminClient adminClient = new 
MockAdminClient(Collections.singletonList(broker), broker)) {
+            String standardOutput = 
execute(fromArgsToOptions("--bootstrap-server", "EMPTY", "--broker-list", "1", 
"--describe"), adminClient);
+            String[] standardOutputLines = standardOutput.split("\n");
+            assertTrue(standardOutputLines.length != 0);
+            assertTrue(standardOutputLines[0].contains("Querying brokers for 
log directories information"));

Review Comment:
   This test has the same assertions than the test above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to