lucliu1108 commented on code in PR #24338:
URL: https://github.com/apache/kafka/pull/24338#discussion_r4685816772


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/producer/ProducerIntegrationTest.java:
##########
@@ -112,6 +113,34 @@ public void 
testTransactionWithAndWithoutSend(ClusterInstance cluster) {
         }
     }
 
+    @ClusterTests({
+        @ClusterTest(features = {
+            @ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 
0)}),
+        @ClusterTest(features = {
+            @ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 
1)}),
+        @ClusterTest(features = {
+            @ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 
2)}),
+    })
+    public void testCloseWithEmptyTransaction(ClusterInstance cluster) {
+        Map<String, Object> properties = Map.of(
+            ProducerConfig.TRANSACTIONAL_ID_CONFIG, "foobar",
+            ProducerConfig.CLIENT_ID_CONFIG, "test",
+            ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true",
+            ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, "60000");
+        var producer = cluster.producer(properties);
+        try {
+            producer.initTransactions();
+            producer.beginTransaction();
+        } catch (RuntimeException e) {
+            producer.close();
+            throw e;
+        }
+        long start = System.nanoTime();
+        producer.close();

Review Comment:
   Thanks for the suggestion! 
   The original code doesn't actually close the producer twice, since the catch 
block rethrows right after close(). But you're right that this format is 
cleaner and aligns with the other tests, so I've updated the test to use 
try-with-resources.



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