|
26 | 26 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
27 | 27 | import static org.mockito.Mockito.any;
|
28 | 28 | import static org.mockito.Mockito.anyInt;
|
| 29 | +import static org.mockito.Mockito.doReturn; |
| 30 | +import static org.mockito.Mockito.doThrow; |
29 | 31 | import static org.mockito.Mockito.mock;
|
30 | 32 | import static org.mockito.Mockito.never;
|
31 | 33 | import static org.mockito.Mockito.reset;
|
|
69 | 71 | import org.junit.jupiter.params.ParameterizedTest;
|
70 | 72 | import org.junit.jupiter.params.provider.Arguments;
|
71 | 73 | import org.junit.jupiter.params.provider.MethodSource;
|
72 |
| -import org.mockito.stubbing.OngoingStubbing; |
73 | 74 | import org.slf4j.event.Level;
|
74 | 75 |
|
75 | 76 | /**
|
@@ -296,18 +297,18 @@ void refreshesPipelineOnReadFailure(IOException ex) throws Exception {
|
296 | 297 | // GIVEN
|
297 | 298 | Pipeline pipeline = MockPipeline.createSingleNodePipeline();
|
298 | 299 | BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class);
|
299 |
| - when(blockLocationInfo.getPipeline()).thenReturn(pipeline); |
| 300 | + doReturn(pipeline).when(blockLocationInfo.getPipeline()); |
300 | 301 | Pipeline newPipeline = MockPipeline.createSingleNodePipeline();
|
301 | 302 | BlockLocationInfo newBlockLocationInfo = mock(BlockLocationInfo.class);
|
302 | 303 |
|
303 | 304 | testRefreshesPipelineOnReadFailure(ex, blockLocationInfo,
|
304 | 305 | id -> newBlockLocationInfo);
|
305 | 306 |
|
306 |
| - when(newBlockLocationInfo.getPipeline()).thenReturn(newPipeline); |
| 307 | + doReturn(newPipeline).when(newBlockLocationInfo.getPipeline()); |
307 | 308 | testRefreshesPipelineOnReadFailure(ex, blockLocationInfo,
|
308 | 309 | id -> blockLocationInfo);
|
309 | 310 |
|
310 |
| - when(newBlockLocationInfo.getPipeline()).thenReturn(null); |
| 311 | + doReturn(null).when(newBlockLocationInfo.getPipeline()); |
311 | 312 | testRefreshesPipelineOnReadFailure(ex, blockLocationInfo,
|
312 | 313 | id -> newBlockLocationInfo);
|
313 | 314 | }
|
@@ -352,14 +353,11 @@ private static Stream<Arguments> exceptionsNotTriggerRefresh() {
|
352 | 353 | private static ChunkInputStream throwingChunkInputStream(IOException ex,
|
353 | 354 | int len, boolean succeedOnRetry) throws IOException {
|
354 | 355 | final ChunkInputStream stream = mock(ChunkInputStream.class);
|
355 |
| - OngoingStubbing<Integer> stubbing = |
356 |
| - when(stream.read(any(), anyInt(), anyInt())) |
357 |
| - .thenThrow(ex); |
| 356 | + doThrow(ex).doReturn(len).when(stream.read(any(), anyInt(), anyInt())); |
358 | 357 | if (succeedOnRetry) {
|
359 |
| - stubbing.thenReturn(len); |
| 358 | + doReturn(len).when(stream).read(any(), anyInt(), anyInt()); |
360 | 359 | }
|
361 |
| - when(stream.getRemaining()) |
362 |
| - .thenReturn((long) len); |
| 360 | + doReturn((long) len).when(stream.getRemaining()); |
363 | 361 | return stream;
|
364 | 362 | }
|
365 | 363 |
|
@@ -415,15 +413,13 @@ public void testRefreshOnReadFailureAfterUnbuffer(IOException ex)
|
415 | 413 | XceiverClientFactory clientFactory = mock(XceiverClientFactory.class);
|
416 | 414 | XceiverClientSpi client = mock(XceiverClientSpi.class);
|
417 | 415 | BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class);
|
418 |
| - when(clientFactory.acquireClientForReadData(pipeline)) |
419 |
| - .thenReturn(client); |
| 416 | + doReturn(client).when(clientFactory.acquireClientForReadData(pipeline)); |
420 | 417 |
|
421 | 418 | final int len = 200;
|
422 | 419 | final ChunkInputStream stream = throwingChunkInputStream(ex, len, true);
|
423 | 420 |
|
424 |
| - when(refreshFunction.apply(blockID)) |
425 |
| - .thenReturn(blockLocationInfo); |
426 |
| - when(blockLocationInfo.getPipeline()).thenReturn(newPipeline); |
| 421 | + doReturn(blockLocationInfo).when(refreshFunction.apply(blockID)); |
| 422 | + doReturn(newPipeline).when(blockLocationInfo.getPipeline()); |
427 | 423 |
|
428 | 424 | OzoneClientConfig clientConfig = conf.getObject(OzoneClientConfig.class);
|
429 | 425 | clientConfig.setChecksumVerify(false);
|
|
0 commit comments