Skip to content

KAFKA-14589 [1/3] Tests of ConsoleGroupCommand rewritten in java#15256

Merged
showuon merged 35 commits into
apache:trunkfrom
nizhikov:KAFKA-14589_test2
Feb 13, 2024
Merged

KAFKA-14589 [1/3] Tests of ConsoleGroupCommand rewritten in java#15256
showuon merged 35 commits into
apache:trunkfrom
nizhikov:KAFKA-14589_test2

Conversation

@nizhikov

@nizhikov nizhikov commented Jan 24, 2024

Copy link
Copy Markdown
Contributor

This PR is part of #14471
Is contains some of ConsoleGroupCommand tests rewritten in java.
Intention of separate PR is to reduce changes and simplify review.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@nizhikov nizhikov changed the title KAFKA-14589 [1/3][WIP] Tests of ConsoleGroupCommand rewritten in java KAFKA-14589 [1/3] Tests of ConsoleGroupCommand rewritten in java Jan 24, 2024
@showuon showuon self-assigned this Jan 26, 2024
@showuon

showuon commented Jan 26, 2024

Copy link
Copy Markdown
Member

Will take a look next week. Thanks.

@showuon showuon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Left some comments.


String output = kafka.utils.TestUtils.grabConsoleOutput(() -> {
service.deleteGroups();
return null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it have compiling failure after removing return null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Comment on lines +259 to +261
System.arraycopy(cgcArgs, 0, cgcArgs2, 0, cgcArgs.length);
cgcArgs2[cgcArgs2.length - 2] = "--group";
cgcArgs2[cgcArgs2.length - 1] = missingGroup;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +296 to +300
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

};
}

@Test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add these?

    @ParameterizedTest(name = TEST_WITH_PARAMETERIZED_QUORUM_NAME)
    @ValueSource(strings = {"zk", "kraft"})

Same for below tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. Thanks. Fixed.
This was added 2 weeks ago and I missed to reflect that change in java test version.

Comment on lines +70 to +74
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];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use java collection here?

@nizhikov nizhikov Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

https://github.com/apache/kafka/pull/14471/files#diff-4e22e01d567ea1b5087aa60354fa127bb25b892b430a6b86ab39a10edd393c0a

Снимок экрана 2024-01-30 в 16 32 26

Comment on lines +103 to +110
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see these tests in scala. Did you add them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fresh changes from 82920ff

Comment on lines +112 to +116
assertThrows(IllegalArgumentException.class, () -> ConsumerGroupCommand.consumerGroupStatesFromString("bad, wrong"));

assertThrows(IllegalArgumentException.class, () -> ConsumerGroupCommand.consumerGroupStatesFromString(" bad, Stable"));

assertThrows(IllegalArgumentException.class, () -> ConsumerGroupCommand.consumerGroupStatesFromString(" , ,"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems 1 test is missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checked and can't spot missing test. Can you, please, clarify what test are missing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, there's some update in the test. Please ignore it. Thanks.

String simpleGroup = "simple-group";
addSimpleGroupExecutor(simpleGroup);
addConsumerGroupExecutor(1);
final String[] out = {""};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we declare as String directly?
final String out = ""?

@nizhikov nizhikov Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked to AtomicReference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment on lines +145 to +161
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]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, case of parameter differs - "Stable", "stable".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's why.

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

@showuon showuon Jan 30, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@nizhikov

Copy link
Copy Markdown
Contributor Author

@showuon Thanks for review. Answered to all your comments. Please, take a look one more time.

@showuon showuon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@showuon

showuon commented Jan 31, 2024

Copy link
Copy Markdown
Member

Re-running the CI build.

@nizhikov

Copy link
Copy Markdown
Contributor Author

CI results looks good for me.

@nizhikov

nizhikov commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

Hello @showuon

CI is OK for me. Are you ready to merge this PR or have other questions, comments?

@showuon

showuon commented Feb 1, 2024

Copy link
Copy Markdown
Member

@nizhikov , thanks for the reminder, I forgot about this PR.
I just checked https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-15256/8 and https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-15256/7, the test: kafka.server.DynamicBrokerReconfigurationTest.testThreadPoolResize() failed on each job once. But it didn't appear in earlier run, https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-15256/4/, as well as the Kafka trunk build: https://ci-builds.apache.org/job/Kafka/job/kafka/job/trunk/2607/ . Could you help check that? Thanks.

@dajac

dajac commented Feb 1, 2024

Copy link
Copy Markdown
Member

@nizhikov I merged #15253. I am not sure if it has any impact on this PR. Does it?

@nizhikov

nizhikov commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

@dajac It has impact, for sure :)

I reflect your changes in the main PR #14471 and will merge them to this PR in the nearest time.

@nizhikov

nizhikov commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

@showuon I run DynamicBrokerReconfigurationTest locally and it passed.
Not sure, how those failures can relate to this PR as I change only specific tests classes.

@showuon

showuon commented Feb 1, 2024

Copy link
Copy Markdown
Member

@nizhikov , could you rebase with the latest trunk branch and let's see if it fixed the test?

@showuon I run DynamicBrokerReconfigurationTest locally and it passed. Not sure, how those failures can relate to this PR as I change only specific tests classes.

OK, let's wait and see if the latest CI build fixes the test.

@nizhikov

nizhikov commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

could you rebase with the latest trunk branch and let's see if it fixed the test?

PR currently merged with the latest trunk changes. 74980be

@nizhikov

nizhikov commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

@showuon CI results are ready.

AFAICS other tests of DynamicBrokerReconfigurationTest failed in the latest trunk:
https://ci-builds.apache.org/blue/organizations/jenkins/Kafka%2Fkafka/detail/trunk/2609/tests

@nizhikov

Copy link
Copy Markdown
Contributor Author

Hello @showuon

I found that DeleteTopicTest.scala don't close resources allocated in case of kraft run.
It was hided by removed tests and lead to the tests failures we observed earlier.

I fixed DeleteTopicTest and now it seems that CI is OK.

Take a look one more time, please.

@nizhikov

Copy link
Copy Markdown
Contributor Author

Hello, @mimaison @jolshan

Can you, please, take a look.
Looks like this PR are ready to merge.

@showuon

showuon commented Feb 13, 2024

Copy link
Copy Markdown
Member

Hello @showuon

I found that DeleteTopicTest.scala don't close resources allocated in case of kraft run. It was hided by removed tests and lead to the tests failures we observed earlier.

I fixed DeleteTopicTest and now it seems that CI is OK.

Take a look one more time, please.

Nice find! Thanks for the fix!

@showuon showuon merged commit 88c5543 into apache:trunk Feb 13, 2024
@nizhikov

Copy link
Copy Markdown
Contributor Author

@showuon Thank you for review and merging!

yyu1993 pushed a commit to yyu1993/kafka that referenced this pull request Feb 15, 2024
…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>
clolov pushed a commit to clolov/kafka that referenced this pull request Apr 5, 2024
…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>
Phuc-Hong-Tran pushed a commit to Phuc-Hong-Tran/kafka that referenced this pull request Jun 6, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants