m1a2st commented on code in PR #19355: URL: https://github.com/apache/kafka/pull/19355#discussion_r2045837695
########## clients/src/test/java/org/apache/kafka/clients/admin/internals/ListTransactionsHandlerTest.java: ########## @@ -86,6 +87,32 @@ public void testBuildRequestWithFilteredState() { assertEquals(Collections.emptyList(), request.data().producerIdFilters()); } + + @Test + public void testBuildRequestWithFilteredTransactionalIdPattern() { + int brokerId = 1; + BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId)); + String filteredTransactionalIdPattern = "^special-.*"; + ListTransactionsOptions options = new ListTransactionsOptions() + .filterOnTransactionalIdPattern(filteredTransactionalIdPattern); + ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext); + ListTransactionsRequest request = handler.buildBatchedRequest(brokerId, singleton(brokerKey)).build(); + assertEquals(filteredTransactionalIdPattern, request.data().transactionalIdPatternFilter()); + assertEquals(Collections.emptyList(), request.data().stateFilters()); Review Comment: `Collections.emptyList()` can instead of `List.of()` ########## clients/src/test/java/org/apache/kafka/clients/admin/internals/ListTransactionsHandlerTest.java: ########## @@ -86,6 +87,32 @@ public void testBuildRequestWithFilteredState() { assertEquals(Collections.emptyList(), request.data().producerIdFilters()); } + + @Test + public void testBuildRequestWithFilteredTransactionalIdPattern() { + int brokerId = 1; + BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId)); + String filteredTransactionalIdPattern = "^special-.*"; + ListTransactionsOptions options = new ListTransactionsOptions() + .filterOnTransactionalIdPattern(filteredTransactionalIdPattern); + ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext); + ListTransactionsRequest request = handler.buildBatchedRequest(brokerId, singleton(brokerKey)).build(); + assertEquals(filteredTransactionalIdPattern, request.data().transactionalIdPatternFilter()); + assertEquals(Collections.emptyList(), request.data().stateFilters()); + } + + @Test + public void testBuildRequestWithEmptyFilteredTransactionalIdPattern() { + int brokerId = 1; + BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId)); + String filteredTransactionalIdPattern = ""; + ListTransactionsOptions options = new ListTransactionsOptions() + .filterOnTransactionalIdPattern(filteredTransactionalIdPattern); + ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext); + ListTransactionsRequest request = handler.buildBatchedRequest(brokerId, singleton(brokerKey)).build(); Review Comment: `singleton()` can instead of `Set.of()` ########## tools/src/test/java/org/apache/kafka/tools/TransactionsCommandTest.java: ########## @@ -304,6 +304,42 @@ public void testDescribeTransaction() throws Exception { assertEquals(expectedRow, table.get(1)); } + @Test + public void testListTransactionsWithTransactionalIdPattern() throws Exception { + String[] args = new String[] { + "--bootstrap-server", + "localhost:9092", + "list", + "--transactional-id-pattern-filter", + "ba.*" + }; + + Map<Integer, Collection<TransactionListing>> transactions = new HashMap<>(); + transactions.put(0, asList( + new TransactionListing("bar", 98765L, TransactionState.PREPARE_ABORT) + )); + transactions.put(1, singletonList( + new TransactionListing("baz", 13579L, TransactionState.COMPLETE_COMMIT) + )); + + expectListTransactions(new ListTransactionsOptions().filterOnTransactionalIdPattern("ba.*"), transactions); + + execute(args); + assertNormalExit(); + + List<List<String>> table = readOutputAsTable(); + assertEquals(3, table.size()); + + // Assert expected headers + List<String> expectedHeaders = TransactionsCommand.ListTransactionsCommand.HEADERS; + assertEquals(expectedHeaders, table.get(0)); + Set<List<String>> expectedRows = Set.of( + asList("bar", "0", "98765", "PrepareAbort"), Review Comment: `asList()` can instead of `List.of()` ########## tools/src/test/java/org/apache/kafka/tools/TransactionsCommandTest.java: ########## @@ -304,6 +304,42 @@ public void testDescribeTransaction() throws Exception { assertEquals(expectedRow, table.get(1)); } + @Test + public void testListTransactionsWithTransactionalIdPattern() throws Exception { + String[] args = new String[] { + "--bootstrap-server", + "localhost:9092", + "list", + "--transactional-id-pattern-filter", + "ba.*" + }; + + Map<Integer, Collection<TransactionListing>> transactions = new HashMap<>(); + transactions.put(0, asList( + new TransactionListing("bar", 98765L, TransactionState.PREPARE_ABORT) + )); + transactions.put(1, singletonList( + new TransactionListing("baz", 13579L, TransactionState.COMPLETE_COMMIT) + )); Review Comment: `asList()` and `singletonList` can instead of `List.of()` -- 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