You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/02/03 14:57:39 UTC
[GitHub] [kafka] tombentley commented on a change in pull request #11672: KAFKA-13577: Replace easymock with mockito in kafka:core - part 1
tombentley commented on a change in pull request #11672:
URL: https://github.com/apache/kafka/pull/11672#discussion_r796754101
##########
File path: core/src/test/scala/unit/kafka/controller/PartitionStateMachineTest.scala
##########
@@ -85,19 +84,17 @@ class PartitionStateMachineTest {
controllerContext.updatePartitionFullReplicaAssignment(partition, ReplicaAssignment(Seq(brokerId)))
controllerContext.putPartitionState(partition, NewPartition)
val leaderIsrAndControllerEpoch = LeaderIsrAndControllerEpoch(LeaderAndIsr(brokerId, List(brokerId)), controllerEpoch)
- EasyMock.expect(mockControllerBrokerRequestBatch.newBatch())
- EasyMock.expect(mockZkClient.createTopicPartitionStatesRaw(Map(partition -> leaderIsrAndControllerEpoch), controllerContext.epochZkVersion))
- .andReturn(Seq(CreateResponse(Code.OK, null, Some(partition), null, ResponseMetadata(0, 0))))
- EasyMock.expect(mockControllerBrokerRequestBatch.addLeaderAndIsrRequestForBrokers(Seq(brokerId),
- partition, leaderIsrAndControllerEpoch, replicaAssignment(Seq(brokerId)), isNew = true))
- EasyMock.expect(mockControllerBrokerRequestBatch.sendRequestsToBrokers(controllerEpoch))
- EasyMock.replay(mockZkClient, mockControllerBrokerRequestBatch)
+ when(mockZkClient.createTopicPartitionStatesRaw(Map(partition -> leaderIsrAndControllerEpoch), controllerContext.epochZkVersion))
+ .thenReturn(Seq(CreateResponse(Code.OK, null, Some(partition), null, ResponseMetadata(0, 0))))
partitionStateMachine.handleStateChanges(
partitions,
OnlinePartition,
Option(OfflinePartitionLeaderElectionStrategy(false))
)
- EasyMock.verify(mockZkClient, mockControllerBrokerRequestBatch)
+ verify(mockControllerBrokerRequestBatch).newBatch()
+ verify(mockControllerBrokerRequestBatch).addLeaderAndIsrRequestForBrokers(Seq(brokerId),
+ partition, leaderIsrAndControllerEpoch, replicaAssignment(Seq(brokerId)), isNew = true)
+ verify(mockControllerBrokerRequestBatch).sendRequestsToBrokers(controllerEpoch)
Review comment:
I know we mocked it, but shouldn't we also verify `createTopicPartitionStatesRaw` here?
##########
File path: core/src/test/scala/unit/kafka/controller/PartitionStateMachineTest.scala
##########
@@ -165,22 +158,20 @@ class PartitionStateMachineTest {
controllerContext.putPartitionLeadershipInfo(partition, leaderIsrAndControllerEpoch)
val stat = new Stat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
- EasyMock.expect(mockControllerBrokerRequestBatch.newBatch())
- EasyMock.expect(mockZkClient.getTopicPartitionStatesRaw(partitions))
- .andReturn(Seq(GetDataResponse(Code.OK, null, Some(partition),
+ when(mockZkClient.getTopicPartitionStatesRaw(partitions))
+ .thenReturn(Seq(GetDataResponse(Code.OK, null, Some(partition),
TopicPartitionStateZNode.encode(leaderIsrAndControllerEpoch), stat, ResponseMetadata(0, 0))))
val leaderAndIsrAfterElection = leaderAndIsr.newLeader(brokerId)
val updatedLeaderAndIsr = leaderAndIsrAfterElection.withZkVersion(2)
- EasyMock.expect(mockZkClient.updateLeaderAndIsr(Map(partition -> leaderAndIsrAfterElection), controllerEpoch, controllerContext.epochZkVersion))
- .andReturn(UpdateLeaderAndIsrResult(Map(partition -> Right(updatedLeaderAndIsr)), Seq.empty))
- EasyMock.expect(mockControllerBrokerRequestBatch.addLeaderAndIsrRequestForBrokers(Seq(brokerId),
- partition, LeaderIsrAndControllerEpoch(updatedLeaderAndIsr, controllerEpoch), replicaAssignment(Seq(brokerId)), isNew = false))
- EasyMock.expect(mockControllerBrokerRequestBatch.sendRequestsToBrokers(controllerEpoch))
- EasyMock.replay(mockZkClient, mockControllerBrokerRequestBatch)
+ when(mockZkClient.updateLeaderAndIsr(Map(partition -> leaderAndIsrAfterElection), controllerEpoch, controllerContext.epochZkVersion))
+ .thenReturn(UpdateLeaderAndIsrResult(Map(partition -> Right(updatedLeaderAndIsr)), Seq.empty))
partitionStateMachine.handleStateChanges(partitions, OnlinePartition, Option(PreferredReplicaPartitionLeaderElectionStrategy))
- EasyMock.verify(mockZkClient, mockControllerBrokerRequestBatch)
+ verify(mockControllerBrokerRequestBatch).newBatch()
Review comment:
Again, verify the `...Raw()` call?
##########
File path: core/src/test/scala/unit/kafka/controller/PartitionStateMachineTest.scala
##########
@@ -165,22 +158,20 @@ class PartitionStateMachineTest {
controllerContext.putPartitionLeadershipInfo(partition, leaderIsrAndControllerEpoch)
val stat = new Stat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
- EasyMock.expect(mockControllerBrokerRequestBatch.newBatch())
- EasyMock.expect(mockZkClient.getTopicPartitionStatesRaw(partitions))
- .andReturn(Seq(GetDataResponse(Code.OK, null, Some(partition),
+ when(mockZkClient.getTopicPartitionStatesRaw(partitions))
+ .thenReturn(Seq(GetDataResponse(Code.OK, null, Some(partition),
TopicPartitionStateZNode.encode(leaderIsrAndControllerEpoch), stat, ResponseMetadata(0, 0))))
val leaderAndIsrAfterElection = leaderAndIsr.newLeader(brokerId)
val updatedLeaderAndIsr = leaderAndIsrAfterElection.withZkVersion(2)
- EasyMock.expect(mockZkClient.updateLeaderAndIsr(Map(partition -> leaderAndIsrAfterElection), controllerEpoch, controllerContext.epochZkVersion))
- .andReturn(UpdateLeaderAndIsrResult(Map(partition -> Right(updatedLeaderAndIsr)), Seq.empty))
- EasyMock.expect(mockControllerBrokerRequestBatch.addLeaderAndIsrRequestForBrokers(Seq(brokerId),
- partition, LeaderIsrAndControllerEpoch(updatedLeaderAndIsr, controllerEpoch), replicaAssignment(Seq(brokerId)), isNew = false))
- EasyMock.expect(mockControllerBrokerRequestBatch.sendRequestsToBrokers(controllerEpoch))
- EasyMock.replay(mockZkClient, mockControllerBrokerRequestBatch)
+ when(mockZkClient.updateLeaderAndIsr(Map(partition -> leaderAndIsrAfterElection), controllerEpoch, controllerContext.epochZkVersion))
+ .thenReturn(UpdateLeaderAndIsrResult(Map(partition -> Right(updatedLeaderAndIsr)), Seq.empty))
partitionStateMachine.handleStateChanges(partitions, OnlinePartition, Option(PreferredReplicaPartitionLeaderElectionStrategy))
- EasyMock.verify(mockZkClient, mockControllerBrokerRequestBatch)
+ verify(mockControllerBrokerRequestBatch).newBatch()
+ verify(mockControllerBrokerRequestBatch).addLeaderAndIsrRequestForBrokers(Seq(brokerId),
+ partition, LeaderIsrAndControllerEpoch(updatedLeaderAndIsr, controllerEpoch), replicaAssignment(Seq(brokerId)), isNew = false)
+ verify(mockControllerBrokerRequestBatch).sendRequestsToBrokers(controllerEpoch)
Review comment:
And `verify(mockZkClient).updateLeaderAndIsr(..)`?
##########
File path: core/src/test/scala/kafka/common/InterBrokerSendThreadTest.scala
##########
@@ -134,36 +129,33 @@ class InterBrokerSendThreadTest {
val clientRequest = new ClientRequest("dest", request, 0, "1", 0, true, requestTimeoutMs, handler.handler)
- EasyMock.expect(networkClient.newClientRequest(
- EasyMock.eq("1"),
- EasyMock.same(handler.request),
- EasyMock.anyLong(),
- EasyMock.eq(true),
- EasyMock.eq(requestTimeoutMs),
- EasyMock.same(handler.handler)))
- .andReturn(clientRequest)
+ when(networkClient.newClientRequest(
+ ArgumentMatchers.eq("1"),
+ same(handler.request),
+ anyLong(),
+ ArgumentMatchers.eq(true),
+ ArgumentMatchers.eq(requestTimeoutMs),
+ same(handler.handler)))
+ .thenReturn(clientRequest)
- EasyMock.expect(networkClient.ready(node, time.milliseconds()))
- .andReturn(false)
+ when(networkClient.ready(node, time.milliseconds()))
+ .thenReturn(false)
- EasyMock.expect(networkClient.connectionDelay(EasyMock.anyObject(), EasyMock.anyLong()))
- .andReturn(0)
+ when(networkClient.connectionDelay(any[Node], anyLong()))
+ .thenReturn(0)
- EasyMock.expect(networkClient.poll(EasyMock.anyLong(), EasyMock.anyLong()))
- .andReturn(new util.ArrayList())
+ when(networkClient.poll(anyLong(), anyLong()))
+ .thenReturn(new util.ArrayList[ClientResponse]())
- EasyMock.expect(networkClient.connectionFailed(node))
- .andReturn(true)
+ when(networkClient.connectionFailed(node))
+ .thenReturn(true)
- EasyMock.expect(networkClient.authenticationException(node))
- .andReturn(new AuthenticationException(""))
-
- EasyMock.replay(networkClient)
+ when(networkClient.authenticationException(node))
+ .thenReturn(new AuthenticationException(""))
sendThread.enqueue(handler)
sendThread.doWork()
- EasyMock.verify(networkClient)
Review comment:
There's a loss of coverage here, since we can't assume that all the methods we mocked actually get called without a mockito `verify`. Do we think that's OK? This is really a general comment.
##########
File path: core/src/test/scala/unit/kafka/controller/PartitionStateMachineTest.scala
##########
@@ -107,17 +104,15 @@ class PartitionStateMachineTest {
controllerContext.updatePartitionFullReplicaAssignment(partition, ReplicaAssignment(Seq(brokerId)))
controllerContext.putPartitionState(partition, NewPartition)
val leaderIsrAndControllerEpoch = LeaderIsrAndControllerEpoch(LeaderAndIsr(brokerId, List(brokerId)), controllerEpoch)
- EasyMock.expect(mockControllerBrokerRequestBatch.newBatch())
- EasyMock.expect(mockZkClient.createTopicPartitionStatesRaw(Map(partition -> leaderIsrAndControllerEpoch), controllerContext.epochZkVersion))
- .andThrow(new ZooKeeperClientException("test"))
- EasyMock.expect(mockControllerBrokerRequestBatch.sendRequestsToBrokers(controllerEpoch))
- EasyMock.replay(mockZkClient, mockControllerBrokerRequestBatch)
+ when(mockZkClient.createTopicPartitionStatesRaw(Map(partition -> leaderIsrAndControllerEpoch), controllerContext.epochZkVersion))
+ .thenThrow(new ZooKeeperClientException("test"))
partitionStateMachine.handleStateChanges(
partitions,
OnlinePartition,
Option(OfflinePartitionLeaderElectionStrategy(false))
)
- EasyMock.verify(mockZkClient, mockControllerBrokerRequestBatch)
+ verify(mockControllerBrokerRequestBatch).newBatch()
+ verify(mockControllerBrokerRequestBatch).sendRequestsToBrokers(controllerEpoch)
Review comment:
Again, verify the `...Raw()` call?
##########
File path: core/src/test/scala/unit/kafka/controller/PartitionStateMachineTest.scala
##########
@@ -127,17 +122,15 @@ class PartitionStateMachineTest {
controllerContext.updatePartitionFullReplicaAssignment(partition, ReplicaAssignment(Seq(brokerId)))
controllerContext.putPartitionState(partition, NewPartition)
val leaderIsrAndControllerEpoch = LeaderIsrAndControllerEpoch(LeaderAndIsr(brokerId, List(brokerId)), controllerEpoch)
- EasyMock.expect(mockControllerBrokerRequestBatch.newBatch())
- EasyMock.expect(mockZkClient.createTopicPartitionStatesRaw(Map(partition -> leaderIsrAndControllerEpoch), controllerContext.epochZkVersion))
- .andReturn(Seq(CreateResponse(Code.NODEEXISTS, null, Some(partition), null, ResponseMetadata(0, 0))))
- EasyMock.expect(mockControllerBrokerRequestBatch.sendRequestsToBrokers(controllerEpoch))
- EasyMock.replay(mockZkClient, mockControllerBrokerRequestBatch)
+ when(mockZkClient.createTopicPartitionStatesRaw(Map(partition -> leaderIsrAndControllerEpoch), controllerContext.epochZkVersion))
+ .thenReturn(Seq(CreateResponse(Code.NODEEXISTS, null, Some(partition), null, ResponseMetadata(0, 0))))
partitionStateMachine.handleStateChanges(
partitions,
OnlinePartition,
Option(OfflinePartitionLeaderElectionStrategy(false))
)
- EasyMock.verify(mockZkClient, mockControllerBrokerRequestBatch)
+ verify(mockControllerBrokerRequestBatch).newBatch()
+ verify(mockControllerBrokerRequestBatch).sendRequestsToBrokers(controllerEpoch)
Review comment:
Again, verify the `...Raw()` call?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org