@@ -101,9 +101,7 @@ public void testRejectVotesFromSameEpochAfterResigningLeadership() throws Except
101
101
int epoch = 2 ;
102
102
103
103
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
104
- .updateRandom (random -> {
105
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
106
- })
104
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
107
105
.withElectedLeader (epoch , localId )
108
106
.build ();
109
107
@@ -126,9 +124,7 @@ public void testRejectVotesFromSameEpochAfterResigningCandidacy() throws Excepti
126
124
int epoch = 2 ;
127
125
128
126
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
129
- .updateRandom (random -> {
130
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
131
- })
127
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
132
128
.withVotedCandidate (epoch , localId )
133
129
.build ();
134
130
@@ -151,11 +147,9 @@ public void testGrantVotesFromHigherEpochAfterResigningLeadership() throws Excep
151
147
int epoch = 2 ;
152
148
153
149
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
154
- .updateRandom (random -> {
155
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
156
- })
157
- .withElectedLeader (epoch , localId )
158
- .build ();
150
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
151
+ .withElectedLeader (epoch , localId )
152
+ .build ();
159
153
160
154
// Resign from leader, will restart in resigned state
161
155
assertTrue (context .client .quorum ().isResigned ());
@@ -181,11 +175,9 @@ public void testGrantVotesFromHigherEpochAfterResigningCandidacy() throws Except
181
175
int epoch = 2 ;
182
176
183
177
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
184
- .updateRandom (random -> {
185
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
186
- })
187
- .withVotedCandidate (epoch , localId )
188
- .build ();
178
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
179
+ .withVotedCandidate (epoch , localId )
180
+ .build ();
189
181
190
182
// Resign from candidate, will restart in candidate state
191
183
assertTrue (context .client .quorum ().isCandidate ());
@@ -235,11 +227,9 @@ public void testInitializeAsResignedAndBecomeCandidate() throws Exception {
235
227
int epoch = 2 ;
236
228
237
229
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
238
- .updateRandom (random -> {
239
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
240
- })
241
- .withElectedLeader (epoch , localId )
242
- .build ();
230
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
231
+ .withElectedLeader (epoch , localId )
232
+ .build ();
243
233
244
234
// Resign from leader, will restart in resigned state
245
235
assertTrue (context .client .quorum ().isResigned ());
@@ -262,9 +252,7 @@ public void testInitializeAsResignedLeaderFromStateStore() throws Exception {
262
252
int epoch = 2 ;
263
253
264
254
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
265
- .updateRandom (random -> {
266
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
267
- })
255
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
268
256
.withElectedLeader (epoch , localId )
269
257
.build ();
270
258
@@ -728,9 +716,7 @@ public void testEndQuorumIgnoredAsCandidateIfOlderEpoch() throws Exception {
728
716
Set <Integer > voters = Utils .mkSet (localId , otherNodeId );
729
717
730
718
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
731
- .updateRandom (random -> {
732
- Mockito .doReturn (jitterMs ).when (random ).nextInt (Mockito .anyInt ());
733
- })
719
+ .updateRandom (r -> r .mockNextInt (jitterMs ))
734
720
.withUnknownLeader (epoch - 1 )
735
721
.build ();
736
722
@@ -1238,9 +1224,7 @@ public void testRetryElection() throws Exception {
1238
1224
Set <Integer > voters = Utils .mkSet (localId , otherNodeId );
1239
1225
1240
1226
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
1241
- .updateRandom (random -> {
1242
- Mockito .doReturn (exponentialFactor ).when (random ).nextInt (Mockito .anyInt ());
1243
- })
1227
+ .updateRandom (r -> r .mockNextInt (exponentialFactor ))
1244
1228
.build ();
1245
1229
1246
1230
context .assertUnknownLeader (0 );
@@ -2184,9 +2168,7 @@ public void testFetchShouldBeTreatedAsLeaderAcknowledgement() throws Exception {
2184
2168
Set <Integer > voters = Utils .mkSet (localId , otherNodeId );
2185
2169
2186
2170
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
2187
- .updateRandom (random -> {
2188
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
2189
- })
2171
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
2190
2172
.withUnknownLeader (epoch - 1 )
2191
2173
.build ();
2192
2174
@@ -2395,9 +2377,7 @@ public void testClusterAuthorizationFailedInBeginQuorumEpoch() throws Exception
2395
2377
Set <Integer > voters = Utils .mkSet (localId , otherNodeId );
2396
2378
2397
2379
RaftClientTestContext context = new RaftClientTestContext .Builder (localId , voters )
2398
- .updateRandom (random -> {
2399
- Mockito .doReturn (0 ).when (random ).nextInt (DEFAULT_ELECTION_TIMEOUT_MS );
2400
- })
2380
+ .updateRandom (r -> r .mockNextInt (DEFAULT_ELECTION_TIMEOUT_MS , 0 ))
2401
2381
.withUnknownLeader (epoch - 1 )
2402
2382
.build ();
2403
2383
@@ -2799,4 +2779,5 @@ public void testObserverFetchWithNoLocalId() throws Exception {
2799
2779
private static KafkaMetric getMetric (final Metrics metrics , final String name ) {
2800
2780
return metrics .metrics ().get (metrics .metricName (name , "raft-metrics" ));
2801
2781
}
2782
+
2802
2783
}
0 commit comments