junrao commented on code in PR #13272:
URL: https://github.com/apache/kafka/pull/13272#discussion_r1113490472
##########
core/src/test/scala/kafka/server/LocalLeaderEndPointTest.scala:
##########
@@ -118,6 +120,61 @@ class LocalLeaderEndPointTest {
assertEquals((4, 3L), endPoint.fetchEarliestLocalOffset(topicPartition,
currentLeaderEpoch = 7))
}
+ @Test
+ def testFetchEpochEndOffsets(): Unit = {
+ appendRecords(replicaManager, topicPartition, records)
+ .onFire(response => assertEquals(Errors.NONE, response.error))
+
+ var result = endPoint.fetchEpochEndOffsets(Map(
+ topicPartition -> new OffsetForLeaderPartition()
+ .setPartition(topicPartition.partition)
+ .setLeaderEpoch(0)))
+
+ var expected = Map(
+ topicPartition -> new EpochEndOffset()
+ .setPartition(topicPartition.partition)
+ .setErrorCode(Errors.NONE.code)
+ .setLeaderEpoch(0)
+ .setEndOffset(3L))
+
+ assertEquals(expected, result)
+
+ // Change leader epoch and end offset, and verify the behavior again.
+ val leaderAndIsrRequest = buildLeaderAndIsrRequest(leaderEpoch = 4)
+ replicaManager.becomeLeaderOrFollower(0, leaderAndIsrRequest, (_, _) => ())
+ appendRecords(replicaManager, topicPartition, records)
+ .onFire(response => assertEquals(Errors.NONE, response.error))
+
+ result = endPoint.fetchEpochEndOffsets(Map(
+ topicPartition -> new OffsetForLeaderPartition()
+ .setPartition(topicPartition.partition)
+ .setLeaderEpoch(4)))
+
+ expected = Map(
+ topicPartition -> new EpochEndOffset()
+ .setPartition(topicPartition.partition)
+ .setErrorCode(Errors.NONE.code)
+ .setLeaderEpoch(4)
+ .setEndOffset(6L))
+
+ assertEquals(expected, result)
+
+ // Check missing epoch
+ result = endPoint.fetchEpochEndOffsets(Map(
+ topicPartition -> new OffsetForLeaderPartition()
+ .setPartition(topicPartition.partition)
+ .setLeaderEpoch(5)))
Review Comment:
Could we add another test for the missing epoch in the middle like 3?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]