Parkerhiphop commented on code in PR #19213:
URL: https://github.com/apache/kafka/pull/19213#discussion_r2008773293


##########
tools/src/test/java/org/apache/kafka/tools/ClientMetricsCommandTest.java:
##########
@@ -156,6 +168,41 @@ public void testAlterGenerateName() {
         assertTrue(capturedOutput.contains("Altered client metrics config"));
     }
 
+    @Test
+    public void testAlterResetConfigs() {
+        Admin adminClient = mock(Admin.class);
+        ClientMetricsCommand.ClientMetricsService service = new 
ClientMetricsCommand.ClientMetricsService(adminClient);
+
+        AlterConfigsResult result = 
AdminClientTestUtils.alterConfigsResult(new 
ConfigResource(ConfigResource.Type.CLIENT_METRICS, clientMetricsName));
+        @SuppressWarnings("unchecked")
+        final ArgumentCaptor<Map<ConfigResource, Collection<AlterConfigOp>>> 
configCaptor = ArgumentCaptor.forClass(Map.class);
+        when(adminClient.incrementalAlterConfigs(configCaptor.capture(), 
any())).thenReturn(result);

Review Comment:
   This test verifies the behavior of resetting (deleting) client metrics 
configurations, simulating a scenario where a user wants to reset all 
configurations by passing empty values:
   ```
   "--metrics", "",
   "--interval", "",
   "--match", ""
   ```
   The `ArgumentCaptor` is used to inspect the exact configuration changes sent 
to Kafka, ensuring that the command-line tool correctly translates user input 
into the appropriate admin client operations.
   
   In `when(adminClient.incrementalAlterConfigs(configCaptor.capture(), 
any()))`, the `capture()` method captures the argument passed to 
`incrementalAlterConfigs()` for later verification.
   
   The test performs the following checks:
   - Ensures that exactly one `ConfigResource` is being modified.
   - Verifies that exactly three operations (one for each config: `metrics`, 
`interval`, and `match`) are performed.
   - Confirms that all operations are of type `DELETE`, meaning the 
configurations are being removed.
   - Validates that the command outputs a success message indicating the 
configurations were altered.
   
   Let me know if you need any further explanation.



-- 
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