2626import  org .apache .hadoop .fs .aliyun .oss .statistics .BlockOutputStreamStatistics ;
2727import  org .apache .hadoop .fs .contract .ContractTestUtils ;
2828import  org .apache .hadoop .test .GenericTestUtils ;
29- import  org .junit .After ;
30- import  org .junit .Before ;
31- import  org .junit .Rule ;
32- import  org .junit .Test ;
33- import  org .junit .rules .Timeout ;
29+ import  org .junit .jupiter .api .AfterEach ;
30+ import  org .junit .jupiter .api .BeforeEach ;
31+ import  org .junit .jupiter .api .Test ;
32+ import  org .junit .jupiter .api .Timeout ;
3433
3534import  java .io .File ;
3635import  java .io .IOException ;
4847import  static  org .apache .hadoop .fs .aliyun .oss .Constants .MULTIPART_UPLOAD_PART_SIZE_DEFAULT ;
4948import  static  org .apache .hadoop .fs .aliyun .oss .Constants .MULTIPART_UPLOAD_PART_SIZE_KEY ;
5049import  static  org .apache .hadoop .fs .contract .ContractTestUtils .IO_CHUNK_BUFFER_SIZE ;
51- import  static  org .junit .Assert .assertEquals ;
52- import  static  org .junit .Assert .assertFalse ;
53- import  static  org .junit .Assert .assertNotEquals ;
54- import  static  org .junit .Assert .assertNotNull ;
55- import  static  org .junit .Assert .assertTrue ;
50+ import  static  org .junit .jupiter . api . Assertions .assertEquals ;
51+ import  static  org .junit .jupiter . api . Assertions .assertFalse ;
52+ import  static  org .junit .jupiter . api . Assertions .assertNotEquals ;
53+ import  static  org .junit .jupiter . api . Assertions .assertNotNull ;
54+ import  static  org .junit .jupiter . api . Assertions .assertTrue ;
5655
5756/** 
5857 * Tests regular and multi-part upload functionality for 
5958 * AliyunOSSBlockOutputStream. 
6059 */ 
60+ @ Timeout (30  * 60 )
6161public  class  TestAliyunOSSBlockOutputStream  {
6262  private  FileSystem  fs ;
6363  private  static  final  int  PART_SIZE  = 1024  * 1024 ;
6464  private  static  String  testRootPath  =
6565      AliyunOSSTestUtils .generateUniqueTestPath ();
6666  private  static  final  long  MEMORY_LIMIT  = 10  * 1024  * 1024 ;
6767
68-   @ Rule 
69-   public  Timeout  testTimeout  = new  Timeout (30  * 60  * 1000 );
70- 
71-   @ Before 
68+   @ BeforeEach 
7269  public  void  setUp () throws  Exception  {
7370    Configuration  conf  = new  Configuration ();
7471    conf .setInt (MULTIPART_UPLOAD_PART_SIZE_KEY , PART_SIZE );
@@ -79,7 +76,7 @@ public void setUp() throws Exception {
7976    fs  = AliyunOSSTestUtils .createTestFileSystem (conf );
8077  }
8178
82-   @ After 
79+   @ AfterEach 
8380  public  void  tearDown () throws  Exception  {
8481    if  (fs  != null ) {
8582      fs .delete (new  Path (testRootPath ), true );
@@ -237,8 +234,8 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
237234        OSSDataBlocks .ByteBufferBlockFactory 
238235            blockFactory  = (OSSDataBlocks .ByteBufferBlockFactory )
239236                ((AliyunOSSFileSystem )fs ).getBlockFactory ();
240-         assertEquals ("outstanding buffers in "  +  blockFactory ,
241-             0 ,  blockFactory . getOutstandingBufferCount () );
237+         assertEquals (0 ,  blockFactory . getOutstandingBufferCount () ,
238+             "outstanding buffers in "  +  blockFactory );
242239      }
243240    }
244241    BlockOutputStreamStatistics  statistics  =
@@ -258,7 +255,7 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
258255  public  void  testDirectoryAllocator () throws  Throwable  {
259256    Configuration  conf  = fs .getConf ();
260257    File  tmp  = AliyunOSSUtils .createTmpFileForWrite ("out-" , 1024 , conf );
261-     assertTrue ("not found: "  + tmp ,  tmp . exists () );
258+     assertTrue (tmp . exists (),  "not found: "  + tmp );
262259    tmp .delete ();
263260
264261    // tmp should not in DeleteOnExitHook 
@@ -268,9 +265,9 @@ public void testDirectoryAllocator() throws Throwable {
268265      field .setAccessible (true );
269266      String  name  = field .getName ();
270267      LinkedHashSet <String > files  = (LinkedHashSet <String >)field .get (name );
271-       assertTrue ("in DeleteOnExitHook" ,  files .isEmpty ());
272-       assertFalse ("in DeleteOnExitHook" , 
273-           (new  ArrayList <>(files )).contains (tmp .getPath ()));
268+       assertTrue (files .isEmpty (),  "in DeleteOnExitHook" );
269+       assertFalse (
270+           (new  ArrayList <>(files )).contains (tmp .getPath ()),  "in DeleteOnExitHook" );
274271    } catch  (Exception  e ) {
275272      e .printStackTrace ();
276273    }
@@ -290,8 +287,8 @@ public void testDirectoryAllocatorRR() throws Throwable {
290287    tmp1 .delete ();
291288    File  tmp2  = AliyunOSSUtils .createTmpFileForWrite ("out-" , 1024 , conf );
292289    tmp2 .delete ();
293-     assertNotEquals ("round robin not working" ,
294-         tmp1 . getParent (),  tmp2 . getParent () );
290+     assertNotEquals (tmp1 . getParent (),  tmp2 . getParent () ,
291+         "round robin not working" );
295292  }
296293
297294  @ Test 
@@ -301,37 +298,36 @@ public void testByteBufferIO() throws IOException {
301298      int  limit  = 128 ;
302299      OSSDataBlocks .ByteBufferBlockFactory .ByteBufferBlock  block 
303300          = factory .create (1 , limit , null );
304-       assertEquals ("outstanding buffers in "  +  factory ,
305-           1 ,  factory . getOutstandingBufferCount () );
301+       assertEquals (1 ,  factory . getOutstandingBufferCount () ,
302+           "outstanding buffers in "  +  factory );
306303
307304      byte [] buffer  = ContractTestUtils .toAsciiByteArray ("test data" );
308305      int  bufferLen  = buffer .length ;
309306      block .write (buffer , 0 , bufferLen );
310307      assertEquals (bufferLen , block .dataSize ());
311-       assertEquals ("capacity in "  + block ,
312-           limit  - bufferLen , block .remainingCapacity ());
313-       assertTrue ("hasCapacity(64) in "  + block , block .hasCapacity (64 ));
314-       assertTrue ("No capacity in "  + block ,
315-           block .hasCapacity (limit  - bufferLen ));
308+       assertEquals (limit  - bufferLen , block .remainingCapacity (),
309+           "capacity in "  + block );
310+       assertTrue (block .hasCapacity (64 ), "hasCapacity(64) in "  + block );
311+       assertTrue (block .hasCapacity (limit  - bufferLen ), "No capacity in "  + block );
316312
317313      // now start the write 
318314      OSSDataBlocks .BlockUploadData  blockUploadData  = block .startUpload ();
319315      ByteBufferBlockFactory .ByteBufferBlock .ByteBufferInputStream 
320316          stream  =
321317          (ByteBufferBlockFactory .ByteBufferBlock .ByteBufferInputStream )
322318              blockUploadData .getUploadStream ();
323-       assertTrue ("Mark not supported in "  + stream ,  stream . markSupported () );
324-       assertTrue ("!hasRemaining() in "  + stream ,  stream . hasRemaining () );
319+       assertTrue (stream . markSupported (),  "Mark not supported in "  + stream );
320+       assertTrue (stream . hasRemaining (),  "!hasRemaining() in "  + stream );
325321
326322      int  expected  = bufferLen ;
327-       assertEquals ("wrong  available() in "  +  stream ,
328-           expected ,  stream . available ());
323+       assertEquals (expected ,  stream . available (),
324+           "wrong  available() in "  +  stream );
329325
330326      assertEquals ('t' , stream .read ());
331327      stream .mark (limit );
332328      expected --;
333-       assertEquals ("wrong  available() in "  +  stream ,
334-           expected ,  stream . available ());
329+       assertEquals (expected ,  stream . available (),
330+           "wrong  available() in "  +  stream );
335331
336332      // read into a byte array with an offset 
337333      int  offset  = 5 ;
@@ -340,8 +336,8 @@ public void testByteBufferIO() throws IOException {
340336      assertEquals ('e' , in [offset ]);
341337      assertEquals ('s' , in [offset  + 1 ]);
342338      expected  -= 2 ;
343-       assertEquals ("wrong  available() in "  +  stream ,
344-           expected ,  stream . available ());
339+       assertEquals (expected ,  stream . available (),
340+           "wrong  available() in "  +  stream );
345341
346342      // read to end 
347343      byte [] remainder  = new  byte [limit ];
@@ -353,24 +349,23 @@ public void testByteBufferIO() throws IOException {
353349      assertEquals (expected , index );
354350      assertEquals ('a' , remainder [--index ]);
355351
356-       assertEquals ("wrong available() in "  + stream ,
357-           0 , stream .available ());
358-       assertTrue ("hasRemaining() in "  + stream , !stream .hasRemaining ());
352+       assertEquals (0 , stream .available (), "wrong available() in "  + stream );
353+       assertTrue (!stream .hasRemaining (), "hasRemaining() in "  + stream );
359354
360355      // go the mark point 
361356      stream .reset ();
362357      assertEquals ('e' , stream .read ());
363358
364359      // when the stream is closed, the data should be returned 
365360      stream .close ();
366-       assertEquals ("outstanding buffers in "  +  factory ,
367-           1 ,  factory . getOutstandingBufferCount () );
361+       assertEquals (1 ,  factory . getOutstandingBufferCount () ,
362+           "outstanding buffers in "  +  factory );
368363      block .close ();
369-       assertEquals ("outstanding buffers in "  +  factory ,
370-           0 ,  factory . getOutstandingBufferCount () );
364+       assertEquals (0 ,  factory . getOutstandingBufferCount () ,
365+           "outstanding buffers in "  +  factory );
371366      stream .close ();
372-       assertEquals ("outstanding buffers in "  +  factory ,
373-           0 ,  factory . getOutstandingBufferCount () );
367+       assertEquals (0 ,  factory . getOutstandingBufferCount () ,
368+           "outstanding buffers in "  +  factory );
374369    }
375370  }
376371
0 commit comments