bbejeck commented on code in PR #17021:
URL: https://github.com/apache/kafka/pull/17021#discussion_r1813710019


##########
clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java:
##########
@@ -8073,18 +8103,21 @@ public void testFenceProducers() throws Exception {
 
     @Test
     public void testClientInstanceId() {
-        try (AdminClientUnitTestEnv env = 
mockClientEnv(AdminClientConfig.ENABLE_METRICS_PUSH_CONFIG, "true")) {
-            Uuid expected = Uuid.randomUuid();
-
-            GetTelemetrySubscriptionsResponseData responseData =
-                new 
GetTelemetrySubscriptionsResponseData().setClientInstanceId(expected).setErrorCode(Errors.NONE.code());
 
-            env.kafkaClient().prepareResponse(
-                request -> request instanceof GetTelemetrySubscriptionsRequest,
-                new GetTelemetrySubscriptionsResponse(responseData));
-
-            Uuid result = 
env.adminClient().clientInstanceId(Duration.ofSeconds(1));
-            assertEquals(expected, result);
+        try (MockedStatic<CommonClientConfigs> mockedCommonClientConfigs = 
mockStatic(CommonClientConfigs.class, new CallsRealMethods())) {
+            ClientTelemetryReporter clientTelemetryReporter = 
mock(ClientTelemetryReporter.class);
+            clientTelemetryReporter.configure(any());
+            mockedCommonClientConfigs.when(() -> 
CommonClientConfigs.telemetryReporter(anyString(), 
any())).thenReturn(Optional.of(clientTelemetryReporter));
+            
+            try (AdminClientUnitTestEnv env = 
mockClientEnv(AdminClientConfig.ENABLE_METRICS_PUSH_CONFIG, "true")) {

Review Comment:
   I used nested try-with-resources to enable mocking`CommonClientConfigs` 
first before the creation of the admin client, which executes 
`CommonClientConfigs.telemetryReporter` 



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