1818package org .apache .hadoop .hdfs ;
1919
2020import static org .apache .hadoop .hdfs .client .HdfsClientConfigKeys .DFS_CLIENT_MAX_BLOCK_ACQUIRE_FAILURES_KEY ;
21- import static org .junit .Assert .assertEquals ;
22- import static org .junit .Assert .assertTrue ;
23- import static org .junit .Assert .fail ;
21+ import static org .junit .jupiter . api . Assertions .assertEquals ;
22+ import static org .junit .jupiter . api . Assertions .assertTrue ;
23+ import static org .junit .jupiter . api . Assertions .fail ;
2424
2525import java .io .EOFException ;
2626import java .io .IOException ;
5353import org .apache .hadoop .hdfs .server .datanode .SimulatedFSDataset ;
5454import org .apache .hadoop .io .IOUtils ;
5555import org .apache .hadoop .test .GenericTestUtils ;
56- import org .junit .Assert ;
57- import org .junit .Before ;
58- import org .junit .BeforeClass ;
59- import org .junit .Test ;
56+ import org .junit .jupiter .api .Assertions ;
57+ import org .junit .jupiter .api .BeforeEach ;
58+ import org .junit .jupiter .api .BeforeAll ;
59+ import org .junit .jupiter .api .Test ;
60+ import org .junit .jupiter .api .Timeout ;
6061import org .mockito .Mockito ;
6162import org .mockito .invocation .InvocationOnMock ;
6263import org .mockito .stubbing .Answer ;
@@ -82,11 +83,13 @@ public class TestPread {
8283 LoggerFactory .getLogger (TestPread .class .getName ());
8384 private final GenericTestUtils .LogCapturer dfsClientLog =
8485 GenericTestUtils .LogCapturer .captureLogs (DFSClient .LOG );
85- @ BeforeClass
86+
87+ @ BeforeAll
8688 public static void setLogLevel () {
8789 GenericTestUtils .setLogLevel (DFSClient .LOG , org .apache .log4j .Level .WARN );
8890 }
89- @ Before
91+
92+ @ BeforeEach
9093 public void setup () {
9194 simulatedStorage = false ;
9295 isHedgedRead = false ;
@@ -107,10 +110,10 @@ private void writeFile(FileSystem fileSys, Path name) throws IOException {
107110 // should throw an exception
108111 res = e ;
109112 }
110- assertTrue ("Error reading beyond file boundary." , res != null );
113+ assertTrue (res != null , "Error reading beyond file boundary." );
111114 in .close ();
112115 if (!fileSys .delete (name , true ))
113- assertTrue ("Cannot delete file" , false );
116+ assertTrue (false , "Cannot delete file" );
114117
115118 // now create the real file
116119 DFSTestUtil .createFile (fileSys , name , fileSize , fileSize ,
@@ -119,9 +122,9 @@ private void writeFile(FileSystem fileSys, Path name) throws IOException {
119122
120123 private void checkAndEraseData (byte [] actual , int from , byte [] expected , String message ) {
121124 for (int idx = 0 ; idx < actual .length ; idx ++) {
122- assertEquals (message + " byte " +( from + idx )+ " differs. expected " +
123- expected [ from + idx ]+ " actual " + actual [ idx ],
124- actual [ idx ], expected [ from + idx ]);
125+ assertEquals (actual [ idx ], expected [ from + idx ],
126+ message + " byte " + ( from + idx )
127+ + " differs. expected " + expected [ from + idx ] + " actual " + actual [ idx ]);
125128 actual [idx ] = 0 ;
126129 }
127130 }
@@ -140,17 +143,17 @@ private void doPread(FSDataInputStream stm, long position, byte[] buffer,
140143 while (nread < length ) {
141144 int nbytes =
142145 stm .read (position + nread , buffer , offset + nread , length - nread );
143- assertTrue ("Error in pread" , nbytes > 0 );
146+ assertTrue (nbytes > 0 , "Error in pread" );
144147 nread += nbytes ;
145148 }
146149
147150 if (dfstm != null ) {
148151 if (isHedgedRead ) {
149- assertTrue ("Expected read statistic to be incremented" , length <= dfstm
150- . getReadStatistics (). getTotalBytesRead () - totalRead );
152+ assertTrue (length <= dfstm . getReadStatistics (). getTotalBytesRead () - totalRead ,
153+ "Expected read statistic to be incremented" );
151154 } else {
152- assertEquals ("Expected read statistic to be incremented" , length , dfstm
153- . getReadStatistics (). getTotalBytesRead () - totalRead );
155+ assertEquals (length , dfstm . getReadStatistics (). getTotalBytesRead () - totalRead ,
156+ "Expected read statistic to be incremented" );
154157 }
155158 }
156159 }
@@ -221,7 +224,7 @@ private void pReadFile(FileSystem fileSys, Path name) throws IOException {
221224 // should throw an exception
222225 res = e ;
223226 }
224- assertTrue ("Error reading beyond file boundary." , res != null );
227+ assertTrue (res != null , "Error reading beyond file boundary." );
225228
226229 stm .close ();
227230 }
@@ -553,9 +556,9 @@ public Void call() throws IOException {
553556 });
554557 try {
555558 future .get (4 , TimeUnit .SECONDS );
556- Assert .fail ();
559+ Assertions .fail ();
557560 } catch (ExecutionException ee ) {
558- assertTrue (ee .toString () , ee .getCause () instanceof EOFException );
561+ assertTrue (ee .getCause () instanceof EOFException , ee .toString () );
559562 } finally {
560563 future .cancel (true );
561564 executor .shutdown ();
@@ -570,7 +573,8 @@ public Void call() throws IOException {
570573 * retrying on a different datanode or by refreshing data nodes and retrying each data node one
571574 * more time.
572575 */
573- @ Test (timeout =120000 )
576+ @ Test
577+ @ Timeout (value = 120 )
574578 public void testGetFromOneDataNodeExceptionLogging () throws IOException {
575579 // With maxBlockAcquireFailures = 0, we would try on each datanode only once and if
576580 // we fail on all three datanodes, we fail the read request.
@@ -647,7 +651,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
647651 /**
648652 * Test the case where we always hit IOExceptions, causing the read request to fail.
649653 */
650- @ Test (timeout =60000 )
654+ @ Test
655+ @ Timeout (value = 60 )
651656 public void testFetchFromDataNodeExceptionLoggingFailedRequest ()
652657 throws IOException {
653658 testFetchFromDataNodeExceptionLoggingFailedRequest (0 );
@@ -723,7 +728,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
723728 }
724729 }
725730
726- @ Test (timeout =30000 )
731+ @ Test
732+ @ Timeout (value = 30 )
727733 public void testHedgedReadFromAllDNFailed () throws IOException {
728734 Configuration conf = new Configuration ();
729735 int numHedgedReadPoolThreads = 5 ;
@@ -768,7 +774,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
768774 byte [] buffer = new byte [64 * 1024 ];
769775 input = dfsClient .open (filename );
770776 input .read (0 , buffer , 0 , 1024 );
771- Assert .fail ("Reading the block should have thrown BlockMissingException" );
777+ Assertions .fail ("Reading the block should have thrown BlockMissingException" );
772778 } catch (BlockMissingException e ) {
773779 // The result of 9 is due to 2 blocks by 4 iterations plus one because
774780 // hedgedReadOpsLoopNumForTesting is incremented at start of the loop.
@@ -808,7 +814,8 @@ public void testPreadFailureWithChangedBlockLocations() throws Exception {
808814 * 7. Consider next calls to getBlockLocations() always returns DN3 as last
809815 * location.<br>
810816 */
811- @ Test (timeout = 60000 )
817+ @ Test
818+ @ Timeout (value = 60 )
812819 public void testPreadHedgedFailureWithChangedBlockLocations ()
813820 throws Exception {
814821 isHedgedRead = true ;
@@ -929,10 +936,10 @@ public Boolean get() {
929936 byte [] buf = new byte [1024 ];
930937 int n = din .read (0 , buf , 0 , data .length ());
931938 assertEquals (data .length (), n );
932- assertEquals ("Data should be read" , data , new String (buf , 0 , n ));
933- assertTrue ("Read should complete with maximum " + maxFailures
934- + " failures, but completed with " + din . failures ,
935- din . failures <= maxFailures );
939+ assertEquals (data , new String (buf , 0 , n ), "Data should be read" );
940+ assertTrue (din . failures <= maxFailures ,
941+ "Read should complete with maximum " + maxFailures
942+ + " failures, but completed with " + din . failures );
936943 DFSClient .LOG .info ("Read completed" );
937944 }
938945 }
0 commit comments