KAFKA-14589 [1/3] Tests of ConsoleGroupCommand rewritten in java#15256
Conversation
|
Will take a look next week. Thanks. |
showuon
left a comment
There was a problem hiding this comment.
Thanks for the PR. Left some comments.
|
|
||
| String output = kafka.utils.TestUtils.grabConsoleOutput(() -> { | ||
| service.deleteGroups(); | ||
| return null; |
There was a problem hiding this comment.
Will it have compiling failure after removing return null?
| System.arraycopy(cgcArgs, 0, cgcArgs2, 0, cgcArgs.length); | ||
| cgcArgs2[cgcArgs2.length - 2] = "--group"; | ||
| cgcArgs2[cgcArgs2.length - 1] = missingGroup; |
There was a problem hiding this comment.
I know we did that in scala like this, but after rewriting in Java it becomes more unreadable. Maybe we can just do this:
String[] cgcArgs2 = new String[]{"--bootstrap-server", bootstrapServers(listenerName()), "--delete", "--group", GROUP, "--group", missingGroup};
| String[] cgcArgs2 = new String[cgcArgs.length + 2]; | ||
|
|
||
| System.arraycopy(cgcArgs, 0, cgcArgs2, 0, cgcArgs.length); | ||
| cgcArgs2[cgcArgs2.length - 2] = "--group"; | ||
| cgcArgs2[cgcArgs2.length - 1] = missingGroup; |
| }; | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Should we add these?
@ParameterizedTest(name = TEST_WITH_PARAMETERIZED_QUORUM_NAME)
@ValueSource(strings = {"zk", "kraft"})
Same for below tests.
There was a problem hiding this comment.
Great catch. Thanks. Fixed.
This was added 2 weeks ago and I missed to reflect that change in java test version.
| scala.collection.Set<ConsumerGroupListing> expectedListing = set(Arrays.asList( | ||
| new ConsumerGroupListing(simpleGroup, true, Optional.of(ConsumerGroupState.EMPTY)), | ||
| new ConsumerGroupListing(GROUP, false, Optional.of(ConsumerGroupState.STABLE)))); | ||
|
|
||
| final scala.collection.Set[] foundListing = new scala.collection.Set[1]; |
There was a problem hiding this comment.
Could we use java collection here?
There was a problem hiding this comment.
It seems that usage of scala collections is more convinient for now.
But, of course, when java version of command will be merged we will use java collections here and everywhere in test. You can see how this don for already mereged tests:
| result = ConsumerGroupCommand.consumerGroupStatesFromString("stable"); | ||
| assertEquals(set(Arrays.asList(ConsumerGroupState.STABLE)), result); | ||
|
|
||
| result = ConsumerGroupCommand.consumerGroupStatesFromString("stable, assigning"); | ||
| assertEquals(set(Arrays.asList(ConsumerGroupState.STABLE, ConsumerGroupState.ASSIGNING)), result); | ||
|
|
||
| result = ConsumerGroupCommand.consumerGroupStatesFromString("dead,reconciling,"); | ||
| assertEquals(set(Arrays.asList(ConsumerGroupState.DEAD, ConsumerGroupState.RECONCILING)), result); |
There was a problem hiding this comment.
I didn't see these tests in scala. Did you add them?
| assertThrows(IllegalArgumentException.class, () -> ConsumerGroupCommand.consumerGroupStatesFromString("bad, wrong")); | ||
|
|
||
| assertThrows(IllegalArgumentException.class, () -> ConsumerGroupCommand.consumerGroupStatesFromString(" bad, Stable")); | ||
|
|
||
| assertThrows(IllegalArgumentException.class, () -> ConsumerGroupCommand.consumerGroupStatesFromString(" , ,")); |
There was a problem hiding this comment.
Double checked and can't spot missing test. Can you, please, clarify what test are missing?
There was a problem hiding this comment.
Ah, there's some update in the test. Please ignore it. Thanks.
| String simpleGroup = "simple-group"; | ||
| addSimpleGroupExecutor(simpleGroup); | ||
| addConsumerGroupExecutor(1); | ||
| final String[] out = {""}; |
There was a problem hiding this comment.
Why can't we declare as String directly?
final String out = ""?
There was a problem hiding this comment.
out value changed in java lambda
out = grabConsoleOutput() and only final variable (which can't be changed) can be used inside java lambda.
I can rework String array to usage of AtomicReference.
What do you think?
There was a problem hiding this comment.
Reworked to AtomicReference.
| String[] cgcArgs3 = new String[]{"--bootstrap-server", bootstrapServers(listenerName()), "--list", "--state", "Stable"}; | ||
| TestUtils.waitForCondition(() -> { | ||
| out[0] = kafka.utils.TestUtils.grabConsoleOutput(() -> { | ||
| ConsumerGroupCommand.main(cgcArgs3); | ||
| return null; | ||
| }); | ||
| return out[0].contains("STATE") && out[0].contains(GROUP) && out[0].contains("Stable"); | ||
| }, "Expected to find " + GROUP + " in state Stable and the header, but found " + out[0]); | ||
|
|
||
| String[] cgcArgs4 = new String[]{"--bootstrap-server", bootstrapServers(listenerName()), "--list", "--state", "stable"}; | ||
| TestUtils.waitForCondition(() -> { | ||
| out[0] = kafka.utils.TestUtils.grabConsoleOutput(() -> { | ||
| ConsumerGroupCommand.main(cgcArgs4); | ||
| return null; | ||
| }); | ||
| return out[0].contains("STATE") && out[0].contains(GROUP) && out[0].contains("Stable"); | ||
| }, "Expected to find " + GROUP + " in state Stable and the header, but found " + out[0]); |
There was a problem hiding this comment.
No, case of parameter differs - "Stable", "stable".
| String[] cgcArgs = new String[]{"--bootstrap-server", bootstrapServers(listenerName()), "--list"}; | ||
| ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(cgcArgs); | ||
| scala.collection.Set<String> expectedGroups = set(Arrays.asList(GROUP, simpleGroup)); | ||
| final scala.collection.Set[] foundGroups = new scala.collection.Set[1]; |
There was a problem hiding this comment.
Could we use java set? It's weird we compare the 1st element only below. That is, you create a Set, and then, you just verify the 1st element of the Set. Then, why do you need a set if only 1 element?
|
@showuon Thanks for review. Answered to all your comments. Please, take a look one more time. |
|
Re-running the CI build. |
|
CI results looks good for me. |
|
Hello @showuon CI is OK for me. Are you ready to merge this PR or have other questions, comments? |
|
@nizhikov , thanks for the reminder, I forgot about this PR. |
|
@showuon I run |
|
@nizhikov , could you rebase with the latest trunk branch and let's see if it fixed the test?
OK, let's wait and see if the latest CI build fixes the test. |
PR currently merged with the latest trunk changes. 74980be |
|
@showuon CI results are ready. AFAICS other tests of |
…nIntegrationTest`
|
Hello @showuon I found that I fixed Take a look one more time, please. |
Nice find! Thanks for the fix! |
|
@showuon Thank you for review and merging! |
…ache#15256) This PR is part of apache#14471 Is contains some of ConsoleGroupCommand tests rewritten in java. Intention of separate PR is to reduce changes and simplify review. Reviewers: Luke Chen <showuon@gmail.com>
…ache#15256) This PR is part of apache#14471 Is contains some of ConsoleGroupCommand tests rewritten in java. Intention of separate PR is to reduce changes and simplify review. Reviewers: Luke Chen <showuon@gmail.com>
…ache#15256) This PR is part of apache#14471 Is contains some of ConsoleGroupCommand tests rewritten in java. Intention of separate PR is to reduce changes and simplify review. Reviewers: Luke Chen <showuon@gmail.com>

This PR is part of #14471
Is contains some of
ConsoleGroupCommandtests rewritten in java.Intention of separate PR is to reduce changes and simplify review.
Committer Checklist (excluded from commit message)