-
Notifications
You must be signed in to change notification settings - Fork 14.5k
MINOR: Cleanup simplify set initialization with Set.of #19925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java Lines 137 to 138 in 8fd0d33
Keep the above line unchanged to avoid flaky in the kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java Line 1535 in 8fd0d33
|
@@ -893,8 +893,8 @@ public void testAssignEmptyMetadata(final Map<String, Object> parameterizedConfi | |||
// then metadata gets populated | |||
assignments = partitionAssignor.assign(metadata, new GroupSubscription(subscriptions)).groupAssignment(); | |||
// check assigned partitions | |||
assertEquals(Set.of(new HashSet<>(List.of(t1p0, t2p0, t1p0, t2p0, t1p1, t2p1, t1p2, t2p2))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remove unnecessary duplicates t1p0, t2p0.
tools/src/test/java/org/apache/kafka/tools/TopicCommandTest.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Could you also change new HashSet<>(Collections.singletonList())
to Set.of()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank @Yunyung for this patch, left a comment.
ClassicGroupTest
L423 also can update
Thanks @FrankYang0529 and @m1a2st for the review. Update according to the comments. |
Simplify Set initialization and reduce the overhead of creating extra
collections.
The changes mostly include:
HashSet<>(singletonList())
This change takes the following into account, and we will not change to
Set.of in these scenarios:
mutability
(UnsupportedOperationException).duplicate
elements (IllegalArgumentException).null
elements (NullPointerException).Ordering
.Set.of
does not guarantee order, so it couldmake tests flaky or break public interfaces.
Reviewers: Ken Huang s7133700@gmail.com, PoAn Yang
payang@apache.org, Chia-Ping Tsai chia7712@gmail.com