Skip to content

KAFKA-19009: Move MetadataCacheTest to metadata module#22118

Open
FrankYang0529 wants to merge 1 commit intoapache:trunkfrom
FrankYang0529:KAFKA-19009
Open

KAFKA-19009: Move MetadataCacheTest to metadata module#22118
FrankYang0529 wants to merge 1 commit intoapache:trunkfrom
FrankYang0529:KAFKA-19009

Conversation

@FrankYang0529
Copy link
Copy Markdown
Member

@FrankYang0529 FrankYang0529 commented Apr 22, 2026

Migrate MetadataCacheTest to metadata module.

Reviewers: Mickael Maison (@mimaison)

@github-actions github-actions Bot added core Kafka Broker tests Test fixes (including flaky tests) kraft labels Apr 22, 2026
Signed-off-by: PoAn Yang <payang@apache.org>
Copy link
Copy Markdown
Member

@mimaison mimaison left a 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. I left a few suggestions


public class MetadataCacheTest {

protected final long brokerEpoch = 0L;
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.

This can be private static

Comment on lines +70 to +71
if (cache instanceof KRaftMetadataCache) {
KRaftMetadataCache c = (KRaftMetadataCache) cache;
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.

We can use pattern matching if (cache instanceof KRaftMetadataCache c) {

String topic0 = "topic-0";
String topic1 = "topic-1";

Map<String, Uuid> topicIds = new HashMap<>();
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.

We can use Map.of() here

public void getTopicMetadataPartitionLeaderNotAvailable(MetadataCache cache) {
SecurityProtocol securityProtocol = SecurityProtocol.PLAINTEXT;
ListenerName listenerName = ListenerName.forSecurityProtocol(securityProtocol);
List<RegisterBrokerRecord> brokers = Collections.singletonList(
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.

We can replace all the Collections calls with Set

MetadataResponseData.MetadataResponsePartition partitionMetadata = partitionMetadatas.get(0);
assertEquals(0, partitionMetadata.partitionIndex());
assertEquals(Errors.NONE.code(), partitionMetadata.errorCode());
assertEquals(new HashSet<>(List.of(0, 1)), new HashSet<>(partitionMetadata.replicaNodes()));
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.

new HashSet<>(List.of(0, 1)) -> Set.of(0, 1)

Same below and in other tests

String topic0 = "test0";
String topic1 = "test1";

Map<String, Uuid> topicIds = new HashMap<>();
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.

Again Map.of can be used here and for partitionMap just below
It seems we can get rid of all the new HashMap call

Comment on lines +990 to +1000
private static class BrokerInfo {
final int id;
final List<Uuid> dirs;

BrokerInfo(int id, List<Uuid> dirs) {
this.id = id;
this.dirs = dirs;
}
}

private static class PartitionInfo2 {
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 record classes?

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.

Also let's keep the original names Broker and Partition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Kafka Broker kraft tests Test fixes (including flaky tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants