jolshan commented on a change in pull request #11170: URL: https://github.com/apache/kafka/pull/11170#discussion_r714226694
########## File path: core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala ########## @@ -2810,4 +2811,132 @@ class ReplicaManagerTest { Replicas.NONE, Replicas.NONE, 2, 123, 456)))), replicaManager.calculateDeltaChanges(TEST_DELTA)) } + + @Test + def testPartitionFetchStateUpdatesWithTopicIdAdded(): Unit = { + val aliveBrokersIds = Seq(0, 1) + val replicaManager = setupReplicaManagerWithMockedPurgatories(new MockTimer(time), + brokerId = 0, aliveBrokersIds) + try { + val tp = new TopicPartition(topic, 0) + val replicas = aliveBrokersIds.toList.map(Int.box).asJava + + def leaderAndIsrRequest(epoch: Int, topicIds: util.Map[String, Uuid]): LeaderAndIsrRequest = + new LeaderAndIsrRequest.Builder(ApiKeys.LEADER_AND_ISR.latestVersion, 0, 0, brokerEpoch, + Seq(new LeaderAndIsrPartitionState() + .setTopicName(topic) + .setPartitionIndex(0) + .setControllerEpoch(0) + .setLeader(1) + .setLeaderEpoch(epoch) + .setIsr(replicas) + .setZkVersion(0) + .setReplicas(replicas) + .setIsNew(true)).asJava, + topicIds, + Set(new Node(0, "host1", 0), new Node(1, "host2", 1)).asJava).build() + + val leaderAndIsrRequest1 = leaderAndIsrRequest(0, Collections.emptyMap()) + val leaderAndIsrResponse = replicaManager.becomeLeaderOrFollower(0, leaderAndIsrRequest1, (_, _) => ()) + assertEquals(Errors.NONE, leaderAndIsrResponse.error) + + val fetchState = replicaManager.replicaFetcherManager.getFetcher(tp).flatMap(fetcher => fetcher.fetchState(tp)) + assertTrue(fetchState.isDefined) + assertEquals(None, fetchState.get.topicId) + + val leaderAndIsrRequest2 = leaderAndIsrRequest(0, topicIds.asJava) + val leaderAndIsrResponse2 = replicaManager.becomeLeaderOrFollower(0, leaderAndIsrRequest2, (_, _) => ()) + assertEquals(Errors.NONE, leaderAndIsrResponse2.error) + + val fetchState2 = replicaManager.replicaFetcherManager.getFetcher(tp).flatMap(fetcher => fetcher.fetchState(tp)) + assertTrue(fetchState2.isDefined) + assertEquals(Some(topicId), fetchState2.get.topicId) + + } finally { + replicaManager.shutdown(checkpointHW = false) + } + } + + @Test + def testReplicaAlterLogDirsWithAndWithoutIds(): Unit = { Review comment: With only 3 parameters changing based on two cases, I decided to make this a parameterized test instead. Hopefully it is clearer. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org