m1a2st commented on code in PR #20334:
URL: https://github.com/apache/kafka/pull/20334#discussion_r2326391978


##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -716,26 +716,27 @@ public void testInterceptorConstructorClose(GroupProtocol 
groupProtocol) {
     @ParameterizedTest
     @EnumSource(GroupProtocol.class)
     public void 
testInterceptorConstructorConfigurationWithExceptionShouldCloseRemainingInstances(GroupProtocol
 groupProtocol) {
-        final int targetInterceptor = 3;
+        final int targetInterceptor = 1;
 
         try {
             Properties props = new Properties();
             props.setProperty(ConsumerConfig.GROUP_PROTOCOL_CONFIG, 
groupProtocol.name());
             props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, 
"localhost:9999");
-            props.setProperty(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG,  
MockConsumerInterceptor.class.getName() + ", "
-                    + MockConsumerInterceptor.class.getName() + ", "
-                    + MockConsumerInterceptor.class.getName());
+            props.setProperty(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, 
+                    CloseInterceptor.class.getName() + "," + 
MockConsumerInterceptor.class.getName());
 
             
MockConsumerInterceptor.setThrowOnConfigExceptionThreshold(targetInterceptor);
 
             assertThrows(KafkaException.class, () -> newConsumer(
                     props, new StringDeserializer(), new 
StringDeserializer()));
 
-            assertEquals(3, MockConsumerInterceptor.CONFIG_COUNT.get());
-            assertEquals(3, MockConsumerInterceptor.CLOSE_COUNT.get());
+            assertEquals(1, MockConsumerInterceptor.CONFIG_COUNT.get());
+            assertEquals(1, MockConsumerInterceptor.CLOSE_COUNT.get());
 
+            assertEquals(1, CloseInterceptor.CLOSE_COUNT.get());

Review Comment:
   ~~Yes, this is an existing issue, I can file a Jira issue to trace it.~~
   
   Updated: If the ordering is changed so that `MockConsumerInterceptor` comes 
first and `CloseInterceptor` second, then when `MockConsumerInterceptor` throws 
an exception, `CloseInterceptor` will not be initialized. As a result, its 
`close()` method will not be executed. The following test will be passed
   ```
       @EnumSource(GroupProtocol.class)
       public void 
testInterceptorConstructorConfigurationWithExceptionShouldCloseRemainingInstances(GroupProtocol
 groupProtocol) {
           final int targetInterceptor = 1;
   
           try {
               Properties props = new Properties();
               // skip
               props.setProperty(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG,
                       MockConsumerInterceptor.class.getName() + "," + 
CloseInterceptor.class.getName());
   
               
MockConsumerInterceptor.setThrowOnConfigExceptionThreshold(targetInterceptor);
   
               assertThrows(KafkaException.class, () -> newConsumer(
                       props, new StringDeserializer(), new 
StringDeserializer()));
   
               assertEquals(1, MockConsumerInterceptor.CONFIG_COUNT.get());
               assertEquals(1, MockConsumerInterceptor.CLOSE_COUNT.get());
   
               assertEquals(0, CloseInterceptor.INIT_COUNT.get());
               assertEquals(0, CloseInterceptor.CONFIG_COUNT.get());
               assertEquals(0, CloseInterceptor.CLOSE_COUNT.get());
           } finally {
               MockConsumerInterceptor.resetCounters();
               CloseInterceptor.resetCounters();
           }
       }
       
       public static class CloseInterceptor implements 
ConsumerInterceptor<String, String> {
   
           public static final AtomicInteger CLOSE_COUNT = new AtomicInteger(0);
           public static final AtomicInteger INIT_COUNT = new AtomicInteger(0);
           public static final AtomicInteger CONFIG_COUNT = new 
AtomicInteger(0);
   
           public CloseInterceptor() {
               INIT_COUNT.incrementAndGet();
           }
   
          // skip
   
           @Override
           public void close() {
               CLOSE_COUNT.incrementAndGet();
           }
   
           @Override
           public void configure(Map<String, ?> configs) {
               CONFIG_COUNT.incrementAndGet();
           }
   
           public static void resetCounters() {
               CLOSE_COUNT.set(0);
           }
       }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to