Source:
<code><START> public void testIgnoreLeaderEpochInOlderMetadataResponse() { <END> TopicPartition tp = new TopicPartition("topic", 0); MetadataResponsePartition partitionMetadata = new MetadataResponsePartition() .setPartitionIndex(tp.partition()) .setLeaderId(5) .setLeaderEpoch(10) .setReplicaNodes(Arrays.asList(1, 2, 3)) .setIsrNodes(Arrays.asList(1, 2, 3)) .setOfflineReplicas(Collections.emptyList()) .setErrorCode(Errors.NONE.code()); MetadataResponseTopic topicMetadata = new MetadataResponseTopic() .setName(tp.topic()) .setErrorCode(Errors.NONE.code()) .setPartitions(Collections.singletonList(partitionMetadata)) .setIsInternal(false); MetadataResponseTopicCollection topics = new MetadataResponseTopicCollection(); topics.add(topicMetadata); MetadataResponseData data = new MetadataResponseData() .setClusterId("clusterId") .setControllerId(0) .setTopics(topics) .setBrokers(new MetadataResponseBrokerCollection()); for (short version = ApiKeys.METADATA.oldestVersion(); version < 9; version++) { Struct struct = data.toStruct(version); MetadataResponse response = new MetadataResponse(struct, version); assertFalse(response.hasReliableLeaderEpochs()); metadata.update(response, 100); assertTrue(metadata.partitionInfoIfCurrent(tp).isPresent()); MetadataCache.PartitionInfoAndEpoch info = metadata.partitionInfoIfCurrent(tp).get(); assertEquals(-1, info.epoch()); } for (short version = 9; version <= ApiKeys.METADATA.oldestVersion(); version++) { Struct struct = data.toStruct(version); MetadataResponse response = new MetadataResponse(struct, version); assertTrue(response.hasReliableLeaderEpochs()); metadata.update(response, 100); assertTrue(metadata.partitionInfoIfCurrent(tp).isPresent()); MetadataCache.PartitionInfoAndEpoch info = metadata.partitionInfoIfCurrent(tp).get(); assertEquals(10, info.epoch()); } }</code><technical_language>nit: briefly explain issue in tests? Personally, I tend read tests understand expected behavior issue versions earlier 9 is immediately apparent</technical_language>

Target:
public void testIgnoreLeaderEpochInOlderMetadataResponse() { TopicPartition tp = new TopicPartition("topic", 0); MetadataResponsePartition partitionMetadata = new MetadataResponsePartition() .setPartitionIndex(tp.partition()) .setLeaderId(5) .setLeaderEpoch(10) .setReplicaNodes(Arrays.asList(1, 2, 3)) .setIsrNodes(Arrays.asList(1, 2, 3)) .setOfflineReplicas(Collections.emptyList()) .setErrorCode(Errors.NONE.code()); MetadataResponseTopic topicMetadata = new MetadataResponseTopic() .setName(tp.topic()) .setErrorCode(Errors.NONE.code()) .setPartitions(Collections.singletonList(partitionMetadata)) .setIsInternal(false); MetadataResponseTopicCollection topics = new MetadataResponseTopicCollection(); topics.add(topicMetadata); MetadataResponseData data = new MetadataResponseData() .setClusterId("clusterId") .setControllerId(0) .setTopics(topics) .setBrokers(new MetadataResponseBrokerCollection()); for (short version = ApiKeys.METADATA.oldestVersion(); version < 9; version++) { Struct struct = data.toStruct(version); MetadataResponse response = new MetadataResponse(struct, version); assertFalse(response.hasReliableLeaderEpochs()); metadata.update(response, 100); assertTrue(metadata.partitionInfoIfCurrent(tp).isPresent()); MetadataCache.PartitionInfoAndEpoch info = metadata.partitionInfoIfCurrent(tp).get(); assertEquals(-1, info.epoch()); } for (short version = 9; version <= ApiKeys.METADATA.latestVersion(); version++) { Struct struct = data.toStruct(version); MetadataResponse response = new MetadataResponse(struct, version); assertTrue(response.hasReliableLeaderEpochs()); metadata.update(response, 100); assertTrue(metadata.partitionInfoIfCurrent(tp).isPresent()); MetadataCache.PartitionInfoAndEpoch info = metadata.partitionInfoIfCurrent(tp).get(); assertEquals(10, info.epoch()); } }