From 4f49afd3f7500052126dc3a5c0b9b590965261a5 Mon Sep 17 00:00:00 2001 From: Chia-Chuan Yu Date: Sat, 8 Mar 2025 18:35:03 +0800 Subject: [PATCH 1/7] HDDS-12505. Use Mockito doReturn() in hadoop-hdds/client --- .../DummyBlockInputStreamWithRetry.java | 4 +-- .../scm/storage/TestBlockInputStream.java | 26 ++++++++----------- .../TestBlockOutputStreamCorrectness.java | 8 +++--- .../scm/storage/TestChunkInputStream.java | 10 +++---- .../io/TestBlockInputStreamFactoryImpl.java | 3 ++- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java index 1aa36c3ce0d9..4e0f3f4a8ed6 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java @@ -18,8 +18,8 @@ package org.apache.hadoop.hdds.scm.storage; import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.CONTAINER_NOT_FOUND; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import java.io.IOException; import java.util.List; @@ -63,7 +63,7 @@ final class DummyBlockInputStreamWithRetry try { BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class); Pipeline mockPipeline = MockPipeline.createPipeline(1); - when(blockLocationInfo.getPipeline()).thenReturn(mockPipeline); + doReturn(mockPipeline).when(blockLocationInfo.getPipeline()); return blockLocationInfo; } catch (IOException e) { throw new RuntimeException(e); diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java index 423eedae495e..e6bf8f0ed350 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java @@ -26,6 +26,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; @@ -69,7 +71,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.stubbing.OngoingStubbing; import org.slf4j.event.Level; /** @@ -296,18 +297,18 @@ void refreshesPipelineOnReadFailure(IOException ex) throws Exception { // GIVEN Pipeline pipeline = MockPipeline.createSingleNodePipeline(); BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class); - when(blockLocationInfo.getPipeline()).thenReturn(pipeline); + doReturn(pipeline).when(blockLocationInfo.getPipeline()); Pipeline newPipeline = MockPipeline.createSingleNodePipeline(); BlockLocationInfo newBlockLocationInfo = mock(BlockLocationInfo.class); testRefreshesPipelineOnReadFailure(ex, blockLocationInfo, id -> newBlockLocationInfo); - when(newBlockLocationInfo.getPipeline()).thenReturn(newPipeline); + doReturn(newPipeline).when(newBlockLocationInfo.getPipeline()); testRefreshesPipelineOnReadFailure(ex, blockLocationInfo, id -> blockLocationInfo); - when(newBlockLocationInfo.getPipeline()).thenReturn(null); + doReturn(null).when(newBlockLocationInfo.getPipeline()); testRefreshesPipelineOnReadFailure(ex, blockLocationInfo, id -> newBlockLocationInfo); } @@ -352,14 +353,11 @@ private static Stream exceptionsNotTriggerRefresh() { private static ChunkInputStream throwingChunkInputStream(IOException ex, int len, boolean succeedOnRetry) throws IOException { final ChunkInputStream stream = mock(ChunkInputStream.class); - OngoingStubbing stubbing = - when(stream.read(any(), anyInt(), anyInt())) - .thenThrow(ex); + doThrow(ex).doReturn(len).when(stream.read(any(), anyInt(), anyInt())); if (succeedOnRetry) { - stubbing.thenReturn(len); + doReturn(len).when(stream).read(any(), anyInt(), anyInt()); } - when(stream.getRemaining()) - .thenReturn((long) len); + doReturn((long) len).when(stream.getRemaining()); return stream; } @@ -415,15 +413,13 @@ public void testRefreshOnReadFailureAfterUnbuffer(IOException ex) XceiverClientFactory clientFactory = mock(XceiverClientFactory.class); XceiverClientSpi client = mock(XceiverClientSpi.class); BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class); - when(clientFactory.acquireClientForReadData(pipeline)) - .thenReturn(client); + doReturn(client).when(clientFactory.acquireClientForReadData(pipeline)); final int len = 200; final ChunkInputStream stream = throwingChunkInputStream(ex, len, true); - when(refreshFunction.apply(blockID)) - .thenReturn(blockLocationInfo); - when(blockLocationInfo.getPipeline()).thenReturn(newPipeline); + doReturn(blockLocationInfo).when(refreshFunction.apply(blockID)); + doReturn(newPipeline).when(blockLocationInfo.getPipeline()); OzoneClientConfig clientConfig = conf.getObject(OzoneClientConfig.class); clientConfig.setChecksumVerify(false); diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java index 7724c50283f3..a8ef3d36b249 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java @@ -20,8 +20,8 @@ import static java.util.concurrent.Executors.newFixedThreadPool; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -157,8 +157,7 @@ private BlockOutputStream createBlockOutputStream(BufferPool bufferPool) final Pipeline pipeline = MockPipeline.createRatisPipeline(); final XceiverClientManager xcm = mock(XceiverClientManager.class); - when(xcm.acquireClient(any())) - .thenReturn(new MockXceiverClientSpi(pipeline)); + doReturn(new MockXceiverClientSpi(pipeline)).when(xcm.acquireClient(any())); OzoneClientConfig config = new OzoneClientConfig(); config.setStreamBufferSize(4 * 1024 * 1024); @@ -186,8 +185,7 @@ private BlockOutputStream createBlockOutputStream(BufferPool bufferPool) private ECBlockOutputStream createECBlockOutputStream(OzoneClientConfig clientConfig, ECReplicationConfig repConfig, BlockID blockID, Pipeline pipeline) throws IOException { final XceiverClientManager xcm = mock(XceiverClientManager.class); - when(xcm.acquireClient(any())) - .thenReturn(new MockXceiverClientSpi(pipeline)); + doReturn(new MockXceiverClientSpi(pipeline)).when(xcm.acquireClient(any())); ContainerClientMetrics clientMetrics = ContainerClientMetrics.acquire(); StreamBufferArgs streamBufferArgs = diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java index 248ea8655223..d229056e6b65 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -244,19 +245,16 @@ public void connectsToNewPipeline() throws Exception { Pipeline newPipeline = MockPipeline.createSingleNodePipeline(); Token token = mock(Token.class); - when(token.encodeToUrlString()) - .thenReturn("oldToken"); + doReturn("oldToken").when(token.encodeToUrlString()); Token newToken = mock(Token.class); - when(newToken.encodeToUrlString()) - .thenReturn("newToken"); + doReturn("newToken").when(newToken.encodeToUrlString()); AtomicReference pipelineRef = new AtomicReference<>(pipeline); AtomicReference> tokenRef = new AtomicReference<>(token); XceiverClientFactory clientFactory = mock(XceiverClientFactory.class); XceiverClientSpi client = mock(XceiverClientSpi.class); - when(clientFactory.acquireClientForReadData(any())) - .thenReturn(client); + doReturn(client).when(clientFactory.acquireClientForReadData(any())); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(ContainerCommandRequestProto.class); when(client.getPipeline()) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java index dbc42816036e..cd4ae2757f6d 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import java.io.IOException; import java.util.ArrayList; @@ -59,7 +60,7 @@ public void testNonECGivesBlockInputStream() throws IOException { 1024 * 1024 * 10); Pipeline pipeline = Mockito.spy(blockInfo.getPipeline()); blockInfo.setPipeline(pipeline); - Mockito.when(pipeline.getReplicaIndex(any(DatanodeDetails.class))).thenReturn(1); + doReturn(1).when(pipeline.getReplicaIndex(any(DatanodeDetails.class))); OzoneClientConfig clientConfig = conf.getObject(OzoneClientConfig.class); clientConfig.setChecksumVerify(true); BlockExtendedInputStream stream = From 4a23d3a095e7f305e9788aa6241e7c34bf36c653 Mon Sep 17 00:00:00 2001 From: Chia-Chuan Yu Date: Sat, 8 Mar 2025 18:51:38 +0800 Subject: [PATCH 2/7] Fixed findingBugs --- .../hadoop/hdds/scm/storage/TestBlockInputStream.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java index e6bf8f0ed350..a5ea3fe696ed 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java @@ -27,7 +27,6 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; @@ -71,6 +70,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.stubbing.OngoingStubbing; import org.slf4j.event.Level; /** @@ -353,9 +353,11 @@ private static Stream exceptionsNotTriggerRefresh() { private static ChunkInputStream throwingChunkInputStream(IOException ex, int len, boolean succeedOnRetry) throws IOException { final ChunkInputStream stream = mock(ChunkInputStream.class); - doThrow(ex).doReturn(len).when(stream.read(any(), anyInt(), anyInt())); + OngoingStubbing stubbing = + when(stream.read(any(), anyInt(), anyInt())) + .thenThrow(ex); if (succeedOnRetry) { - doReturn(len).when(stream).read(any(), anyInt(), anyInt()); + stubbing.thenReturn(len); } doReturn((long) len).when(stream.getRemaining()); return stream; From 4d837b0d8af698e0c6e9b9799fbfdbc34cc37833 Mon Sep 17 00:00:00 2001 From: Chia-Chuan Yu Date: Sat, 8 Mar 2025 22:19:58 +0800 Subject: [PATCH 3/7] Fixed syntax --- .../storage/DummyBlockInputStreamWithRetry.java | 2 +- .../hdds/scm/storage/TestBlockInputStream.java | 14 +++++++------- .../storage/TestBlockOutputStreamCorrectness.java | 4 ++-- .../hdds/scm/storage/TestChunkInputStream.java | 6 +++--- .../client/io/TestBlockInputStreamFactoryImpl.java | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java index 4e0f3f4a8ed6..5beeefdd655e 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java @@ -63,7 +63,7 @@ final class DummyBlockInputStreamWithRetry try { BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class); Pipeline mockPipeline = MockPipeline.createPipeline(1); - doReturn(mockPipeline).when(blockLocationInfo.getPipeline()); + doReturn(mockPipeline).when(blockLocationInfo).getPipeline(); return blockLocationInfo; } catch (IOException e) { throw new RuntimeException(e); diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java index a5ea3fe696ed..8940b6feba9e 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java @@ -297,18 +297,18 @@ void refreshesPipelineOnReadFailure(IOException ex) throws Exception { // GIVEN Pipeline pipeline = MockPipeline.createSingleNodePipeline(); BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class); - doReturn(pipeline).when(blockLocationInfo.getPipeline()); + doReturn(pipeline).when(blockLocationInfo).getPipeline(); Pipeline newPipeline = MockPipeline.createSingleNodePipeline(); BlockLocationInfo newBlockLocationInfo = mock(BlockLocationInfo.class); testRefreshesPipelineOnReadFailure(ex, blockLocationInfo, id -> newBlockLocationInfo); - doReturn(newPipeline).when(newBlockLocationInfo.getPipeline()); + doReturn(newPipeline).when(newBlockLocationInfo).getPipeline(); testRefreshesPipelineOnReadFailure(ex, blockLocationInfo, id -> blockLocationInfo); - doReturn(null).when(newBlockLocationInfo.getPipeline()); + doReturn(null).when(newBlockLocationInfo).getPipeline(); testRefreshesPipelineOnReadFailure(ex, blockLocationInfo, id -> newBlockLocationInfo); } @@ -359,7 +359,7 @@ private static ChunkInputStream throwingChunkInputStream(IOException ex, if (succeedOnRetry) { stubbing.thenReturn(len); } - doReturn((long) len).when(stream.getRemaining()); + doReturn((long) len).when(stream).getRemaining(); return stream; } @@ -415,13 +415,13 @@ public void testRefreshOnReadFailureAfterUnbuffer(IOException ex) XceiverClientFactory clientFactory = mock(XceiverClientFactory.class); XceiverClientSpi client = mock(XceiverClientSpi.class); BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class); - doReturn(client).when(clientFactory.acquireClientForReadData(pipeline)); + doReturn(client).when(clientFactory).acquireClientForReadData(pipeline); final int len = 200; final ChunkInputStream stream = throwingChunkInputStream(ex, len, true); - doReturn(blockLocationInfo).when(refreshFunction.apply(blockID)); - doReturn(newPipeline).when(blockLocationInfo.getPipeline()); + doReturn(blockLocationInfo).when(refreshFunction).apply(blockID); + doReturn(newPipeline).when(blockLocationInfo).getPipeline(); OzoneClientConfig clientConfig = conf.getObject(OzoneClientConfig.class); clientConfig.setChecksumVerify(false); diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java index a8ef3d36b249..43628a95ab53 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockOutputStreamCorrectness.java @@ -157,7 +157,7 @@ private BlockOutputStream createBlockOutputStream(BufferPool bufferPool) final Pipeline pipeline = MockPipeline.createRatisPipeline(); final XceiverClientManager xcm = mock(XceiverClientManager.class); - doReturn(new MockXceiverClientSpi(pipeline)).when(xcm.acquireClient(any())); + doReturn(new MockXceiverClientSpi(pipeline)).when(xcm).acquireClient(any()); OzoneClientConfig config = new OzoneClientConfig(); config.setStreamBufferSize(4 * 1024 * 1024); @@ -185,7 +185,7 @@ private BlockOutputStream createBlockOutputStream(BufferPool bufferPool) private ECBlockOutputStream createECBlockOutputStream(OzoneClientConfig clientConfig, ECReplicationConfig repConfig, BlockID blockID, Pipeline pipeline) throws IOException { final XceiverClientManager xcm = mock(XceiverClientManager.class); - doReturn(new MockXceiverClientSpi(pipeline)).when(xcm.acquireClient(any())); + doReturn(new MockXceiverClientSpi(pipeline)).when(xcm).acquireClient(any()); ContainerClientMetrics clientMetrics = ContainerClientMetrics.acquire(); StreamBufferArgs streamBufferArgs = diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java index d229056e6b65..2afc88e3bc25 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java @@ -245,16 +245,16 @@ public void connectsToNewPipeline() throws Exception { Pipeline newPipeline = MockPipeline.createSingleNodePipeline(); Token token = mock(Token.class); - doReturn("oldToken").when(token.encodeToUrlString()); + doReturn("oldToken").when(token).encodeToUrlString(); Token newToken = mock(Token.class); - doReturn("newToken").when(newToken.encodeToUrlString()); + doReturn("newToken").when(newToken).encodeToUrlString(); AtomicReference pipelineRef = new AtomicReference<>(pipeline); AtomicReference> tokenRef = new AtomicReference<>(token); XceiverClientFactory clientFactory = mock(XceiverClientFactory.class); XceiverClientSpi client = mock(XceiverClientSpi.class); - doReturn(client).when(clientFactory.acquireClientForReadData(any())); + doReturn(client).when(clientFactory).acquireClientForReadData(any()); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(ContainerCommandRequestProto.class); when(client.getPipeline()) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java index cd4ae2757f6d..afc789292574 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java @@ -60,7 +60,7 @@ public void testNonECGivesBlockInputStream() throws IOException { 1024 * 1024 * 10); Pipeline pipeline = Mockito.spy(blockInfo.getPipeline()); blockInfo.setPipeline(pipeline); - doReturn(1).when(pipeline.getReplicaIndex(any(DatanodeDetails.class))); + doReturn(1).when(pipeline).getReplicaIndex(any(DatanodeDetails.class)); OzoneClientConfig clientConfig = conf.getObject(OzoneClientConfig.class); clientConfig.setChecksumVerify(true); BlockExtendedInputStream stream = From 593f389e3a2355a515089218086de8dfb4a45629 Mon Sep 17 00:00:00 2001 From: Chia-Chuan Yu Date: Sun, 9 Mar 2025 11:08:27 +0800 Subject: [PATCH 4/7] Fixed findingbugs --- .../hdds/scm/storage/DummyBlockInputStreamWithRetry.java | 1 + .../apache/hadoop/hdds/scm/storage/TestBlockInputStream.java | 4 +++- .../ozone/client/io/TestBlockInputStreamFactoryImpl.java | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java index 5beeefdd655e..0262ecb6c61a 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java @@ -40,6 +40,7 @@ * A dummy BlockInputStream with pipeline refresh function to mock read * block call to DN. */ +@SuppressWarnings("java:S1854") final class DummyBlockInputStreamWithRetry extends DummyBlockInputStream { diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java index 8940b6feba9e..b7db2970f553 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java @@ -293,14 +293,15 @@ public void testRefreshPipelineFunction() throws Exception { @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") + @SuppressWarnings("java:S1854") void refreshesPipelineOnReadFailure(IOException ex) throws Exception { // GIVEN Pipeline pipeline = MockPipeline.createSingleNodePipeline(); BlockLocationInfo blockLocationInfo = mock(BlockLocationInfo.class); - doReturn(pipeline).when(blockLocationInfo).getPipeline(); Pipeline newPipeline = MockPipeline.createSingleNodePipeline(); BlockLocationInfo newBlockLocationInfo = mock(BlockLocationInfo.class); + doReturn(pipeline).when(blockLocationInfo).getPipeline(); testRefreshesPipelineOnReadFailure(ex, blockLocationInfo, id -> newBlockLocationInfo); @@ -406,6 +407,7 @@ public void testReadNotRetriedOnOtherException(IOException ex) @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") + @SuppressWarnings("java:S1854") public void testRefreshOnReadFailureAfterUnbuffer(IOException ex) throws Exception { // GIVEN diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java index afc789292574..11063cb66502 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java @@ -51,6 +51,7 @@ public class TestBlockInputStreamFactoryImpl { private OzoneConfiguration conf = new OzoneConfiguration(); @Test + @SuppressWarnings("java:S1854") public void testNonECGivesBlockInputStream() throws IOException { BlockInputStreamFactory factory = new BlockInputStreamFactoryImpl(); ReplicationConfig repConfig = From fae4b19446d4719cbaf7e79420b4f154bcd75e23 Mon Sep 17 00:00:00 2001 From: Chia-Chuan Yu Date: Sun, 9 Mar 2025 11:29:40 +0800 Subject: [PATCH 5/7] fixed findingBugs --- .../hdds/scm/storage/DummyBlockInputStreamWithRetry.java | 2 +- .../apache/hadoop/hdds/scm/storage/TestBlockInputStream.java | 4 ++-- .../ozone/client/io/TestBlockInputStreamFactoryImpl.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java index 0262ecb6c61a..f7dd3503214b 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java @@ -40,7 +40,7 @@ * A dummy BlockInputStream with pipeline refresh function to mock read * block call to DN. */ -@SuppressWarnings("java:S1854") +@SuppressWarnings("ResultOfMethodCallIgnored") final class DummyBlockInputStreamWithRetry extends DummyBlockInputStream { diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java index b7db2970f553..d9c870a6f6b3 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java @@ -293,7 +293,7 @@ public void testRefreshPipelineFunction() throws Exception { @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") - @SuppressWarnings("java:S1854") + @SuppressWarnings("ResultOfMethodCallIgnored") void refreshesPipelineOnReadFailure(IOException ex) throws Exception { // GIVEN Pipeline pipeline = MockPipeline.createSingleNodePipeline(); @@ -407,7 +407,7 @@ public void testReadNotRetriedOnOtherException(IOException ex) @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") - @SuppressWarnings("java:S1854") + @SuppressWarnings("ResultOfMethodCallIgnored") public void testRefreshOnReadFailureAfterUnbuffer(IOException ex) throws Exception { // GIVEN diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java index 11063cb66502..82409a2e17c6 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java @@ -51,7 +51,7 @@ public class TestBlockInputStreamFactoryImpl { private OzoneConfiguration conf = new OzoneConfiguration(); @Test - @SuppressWarnings("java:S1854") + @SuppressWarnings("ResultOfMethodCallIgnored") public void testNonECGivesBlockInputStream() throws IOException { BlockInputStreamFactory factory = new BlockInputStreamFactoryImpl(); ReplicationConfig repConfig = From 9083eab2fe9350467b8e8ae149b4b19f44a12124 Mon Sep 17 00:00:00 2001 From: Chia-Chuan Yu Date: Sun, 9 Mar 2025 12:13:29 +0800 Subject: [PATCH 6/7] fixed findingBugs --- .../hdds/scm/storage/DummyBlockInputStreamWithRetry.java | 2 +- .../apache/hadoop/hdds/scm/storage/TestBlockInputStream.java | 4 ++-- .../ozone/client/io/TestBlockInputStreamFactoryImpl.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java index f7dd3503214b..080bfbf8ea26 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java @@ -40,7 +40,7 @@ * A dummy BlockInputStream with pipeline refresh function to mock read * block call to DN. */ -@SuppressWarnings("ResultOfMethodCallIgnored") +@SuppressWarnings("java:S2201") final class DummyBlockInputStreamWithRetry extends DummyBlockInputStream { diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java index d9c870a6f6b3..1364eb8804c3 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java @@ -293,7 +293,7 @@ public void testRefreshPipelineFunction() throws Exception { @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") - @SuppressWarnings("ResultOfMethodCallIgnored") + @SuppressWarnings("java:S2201") void refreshesPipelineOnReadFailure(IOException ex) throws Exception { // GIVEN Pipeline pipeline = MockPipeline.createSingleNodePipeline(); @@ -407,7 +407,7 @@ public void testReadNotRetriedOnOtherException(IOException ex) @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") - @SuppressWarnings("ResultOfMethodCallIgnored") + @SuppressWarnings("java:S2201") public void testRefreshOnReadFailureAfterUnbuffer(IOException ex) throws Exception { // GIVEN diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java index 82409a2e17c6..4162bf3dc056 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java @@ -51,7 +51,7 @@ public class TestBlockInputStreamFactoryImpl { private OzoneConfiguration conf = new OzoneConfiguration(); @Test - @SuppressWarnings("ResultOfMethodCallIgnored") + @SuppressWarnings("java:S2201") public void testNonECGivesBlockInputStream() throws IOException { BlockInputStreamFactory factory = new BlockInputStreamFactoryImpl(); ReplicationConfig repConfig = From 7d1f370cb9ddfc7af0b92638c18281afb54c8c53 Mon Sep 17 00:00:00 2001 From: Chia-Chuan Yu Date: Sun, 9 Mar 2025 14:23:03 +0800 Subject: [PATCH 7/7] Fixed findingBugs --- .../client/dev-support/findbugsExcludeFile.xml | 12 ++++++++++++ .../scm/storage/DummyBlockInputStreamWithRetry.java | 1 - .../hdds/scm/storage/TestBlockInputStream.java | 2 -- .../client/io/TestBlockInputStreamFactoryImpl.java | 1 - 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hadoop-hdds/client/dev-support/findbugsExcludeFile.xml b/hadoop-hdds/client/dev-support/findbugsExcludeFile.xml index 2951138b2f87..9c56d33c8bee 100644 --- a/hadoop-hdds/client/dev-support/findbugsExcludeFile.xml +++ b/hadoop-hdds/client/dev-support/findbugsExcludeFile.xml @@ -19,4 +19,16 @@ + + + + + + + + + + + + diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java index 080bfbf8ea26..5beeefdd655e 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/DummyBlockInputStreamWithRetry.java @@ -40,7 +40,6 @@ * A dummy BlockInputStream with pipeline refresh function to mock read * block call to DN. */ -@SuppressWarnings("java:S2201") final class DummyBlockInputStreamWithRetry extends DummyBlockInputStream { diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java index 1364eb8804c3..cb8323686969 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestBlockInputStream.java @@ -293,7 +293,6 @@ public void testRefreshPipelineFunction() throws Exception { @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") - @SuppressWarnings("java:S2201") void refreshesPipelineOnReadFailure(IOException ex) throws Exception { // GIVEN Pipeline pipeline = MockPipeline.createSingleNodePipeline(); @@ -407,7 +406,6 @@ public void testReadNotRetriedOnOtherException(IOException ex) @ParameterizedTest @MethodSource("exceptionsTriggersRefresh") - @SuppressWarnings("java:S2201") public void testRefreshOnReadFailureAfterUnbuffer(IOException ex) throws Exception { // GIVEN diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java index 4162bf3dc056..afc789292574 100644 --- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java +++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java @@ -51,7 +51,6 @@ public class TestBlockInputStreamFactoryImpl { private OzoneConfiguration conf = new OzoneConfiguration(); @Test - @SuppressWarnings("java:S2201") public void testNonECGivesBlockInputStream() throws IOException { BlockInputStreamFactory factory = new BlockInputStreamFactoryImpl(); ReplicationConfig repConfig =