From 22251a9baa00c2ddd1a93afbb24ee57caf0fb0d9 Mon Sep 17 00:00:00 2001 From: Ismael Juma Date: Thu, 9 Jun 2022 07:25:39 -0700 Subject: [PATCH] MINOR: Remove ReplicaManagerTest.initializeLogAndTopicId The workaround is not required with mockito. --- .../kafka/server/ReplicaManagerTest.scala | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala b/core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala index e5eef65d0aa0e..dc1954cf54a7e 100644 --- a/core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala +++ b/core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala @@ -1187,8 +1187,6 @@ class ReplicaManagerTest { val tp0 = new TopicPartition(topic, 0) val tidp0 = new TopicIdPartition(topicId, tp0) - initializeLogAndTopicId(replicaManager, tp0, topicId) - // Make this replica the follower val leaderAndIsrRequest2 = new LeaderAndIsrRequest.Builder(ApiKeys.LEADER_AND_ISR.latestVersion, 0, 0, brokerEpoch, Seq(new LeaderAndIsrPartitionState() @@ -1245,8 +1243,6 @@ class ReplicaManagerTest { val tp0 = new TopicPartition(topic, 0) val tidp0 = new TopicIdPartition(topicId, tp0) - initializeLogAndTopicId(replicaManager, tp0, topicId) - // Make this replica the leader val leaderAndIsrRequest2 = new LeaderAndIsrRequest.Builder(ApiKeys.LEADER_AND_ISR.latestVersion, 0, 0, brokerEpoch, Seq(new LeaderAndIsrPartitionState() @@ -1293,7 +1289,6 @@ class ReplicaManagerTest { val topicId = Uuid.randomUuid() val tp0 = new TopicPartition(topic, 0) val tidp0 = new TopicIdPartition(topicId, tp0) - initializeLogAndTopicId(replicaManager, tp0, topicId) // Make this replica the follower val leaderAndIsrRequest = new LeaderAndIsrRequest.Builder(ApiKeys.LEADER_AND_ISR.latestVersion, 0, 0, brokerEpoch, @@ -1343,8 +1338,6 @@ class ReplicaManagerTest { val tp0 = new TopicPartition(topic, 0) val tidp0 = new TopicIdPartition(topicId, tp0) - initializeLogAndTopicId(replicaManager, tp0, topicId) - when(replicaManager.metadataCache.getPartitionReplicaEndpoints( tp0, new ListenerName("default") @@ -1418,8 +1411,6 @@ class ReplicaManagerTest { val tp0 = new TopicPartition(topic, 0) val tidp0 = new TopicIdPartition(topicId, tp0) - initializeLogAndTopicId(replicaManager, tp0, topicId) - // Make this replica the follower val leaderAndIsrRequest2 = new LeaderAndIsrRequest.Builder(ApiKeys.LEADER_AND_ISR.latestVersion, 0, 0, brokerEpoch, Seq(new LeaderAndIsrPartitionState() @@ -1489,15 +1480,6 @@ class ReplicaManagerTest { leaderBrokerId, countDownLatch, expectTruncation = true, extraProps = props)) } - // Due to some limitations to EasyMock, we need to create the log so that the Partition.topicId does not call - // LogManager.getLog with a default argument - // TODO: convert tests to using Mockito to avoid this issue. - private def initializeLogAndTopicId(replicaManager: ReplicaManager, topicPartition: TopicPartition, topicId: Uuid): Unit = { - val partition = replicaManager.createPartition(new TopicPartition(topic, 0)) - val log = replicaManager.logManager.getOrCreateLog(topicPartition, false, false, Some(topicId)) - partition.log = Some(log) - } - @Test def testDefaultReplicaSelector(): Unit = { val topicPartition = 0 @@ -1953,6 +1935,7 @@ class ReplicaManagerTest { val mockLogMgr: LogManager = mock(classOf[LogManager]) when(mockLogMgr.liveLogDirs).thenReturn(config.logDirs.map(new File(_).getAbsoluteFile)) when(mockLogMgr.getOrCreateLog(ArgumentMatchers.eq(topicPartitionObj), ArgumentMatchers.eq(false), ArgumentMatchers.eq(false), any())).thenReturn(mockLog) + when(mockLogMgr.getLog(topicPartitionObj, isFuture = false)).thenReturn(Some(mockLog)) when(mockLogMgr.getLog(topicPartitionObj, isFuture = true)).thenReturn(None) val aliveBrokerIds = Seq[Integer](followerBrokerId, leaderBrokerId)