26
26
import org .apache .hadoop .fs .aliyun .oss .statistics .BlockOutputStreamStatistics ;
27
27
import org .apache .hadoop .fs .contract .ContractTestUtils ;
28
28
import 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 ;
34
33
35
34
import java .io .File ;
36
35
import java .io .IOException ;
48
47
import static org .apache .hadoop .fs .aliyun .oss .Constants .MULTIPART_UPLOAD_PART_SIZE_DEFAULT ;
49
48
import static org .apache .hadoop .fs .aliyun .oss .Constants .MULTIPART_UPLOAD_PART_SIZE_KEY ;
50
49
import 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 ;
56
55
57
56
/**
58
57
* Tests regular and multi-part upload functionality for
59
58
* AliyunOSSBlockOutputStream.
60
59
*/
60
+ @ Timeout (30 * 60 )
61
61
public class TestAliyunOSSBlockOutputStream {
62
62
private FileSystem fs ;
63
63
private static final int PART_SIZE = 1024 * 1024 ;
64
64
private static String testRootPath =
65
65
AliyunOSSTestUtils .generateUniqueTestPath ();
66
66
private static final long MEMORY_LIMIT = 10 * 1024 * 1024 ;
67
67
68
- @ Rule
69
- public Timeout testTimeout = new Timeout (30 * 60 * 1000 );
70
-
71
- @ Before
68
+ @ BeforeEach
72
69
public void setUp () throws Exception {
73
70
Configuration conf = new Configuration ();
74
71
conf .setInt (MULTIPART_UPLOAD_PART_SIZE_KEY , PART_SIZE );
@@ -79,7 +76,7 @@ public void setUp() throws Exception {
79
76
fs = AliyunOSSTestUtils .createTestFileSystem (conf );
80
77
}
81
78
82
- @ After
79
+ @ AfterEach
83
80
public void tearDown () throws Exception {
84
81
if (fs != null ) {
85
82
fs .delete (new Path (testRootPath ), true );
@@ -237,8 +234,8 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
237
234
OSSDataBlocks .ByteBufferBlockFactory
238
235
blockFactory = (OSSDataBlocks .ByteBufferBlockFactory )
239
236
((AliyunOSSFileSystem )fs ).getBlockFactory ();
240
- assertEquals ("outstanding buffers in " + blockFactory ,
241
- 0 , blockFactory . getOutstandingBufferCount () );
237
+ assertEquals (0 , blockFactory . getOutstandingBufferCount () ,
238
+ "outstanding buffers in " + blockFactory );
242
239
}
243
240
}
244
241
BlockOutputStreamStatistics statistics =
@@ -258,7 +255,7 @@ private void bufferShouldReleased(boolean zeroSizeFile) throws IOException {
258
255
public void testDirectoryAllocator () throws Throwable {
259
256
Configuration conf = fs .getConf ();
260
257
File tmp = AliyunOSSUtils .createTmpFileForWrite ("out-" , 1024 , conf );
261
- assertTrue ("not found: " + tmp , tmp . exists () );
258
+ assertTrue (tmp . exists (), "not found: " + tmp );
262
259
tmp .delete ();
263
260
264
261
// tmp should not in DeleteOnExitHook
@@ -268,9 +265,9 @@ public void testDirectoryAllocator() throws Throwable {
268
265
field .setAccessible (true );
269
266
String name = field .getName ();
270
267
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" );
274
271
} catch (Exception e ) {
275
272
e .printStackTrace ();
276
273
}
@@ -290,8 +287,8 @@ public void testDirectoryAllocatorRR() throws Throwable {
290
287
tmp1 .delete ();
291
288
File tmp2 = AliyunOSSUtils .createTmpFileForWrite ("out-" , 1024 , conf );
292
289
tmp2 .delete ();
293
- assertNotEquals ("round robin not working" ,
294
- tmp1 . getParent (), tmp2 . getParent () );
290
+ assertNotEquals (tmp1 . getParent (), tmp2 . getParent () ,
291
+ "round robin not working" );
295
292
}
296
293
297
294
@ Test
@@ -301,37 +298,36 @@ public void testByteBufferIO() throws IOException {
301
298
int limit = 128 ;
302
299
OSSDataBlocks .ByteBufferBlockFactory .ByteBufferBlock block
303
300
= 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 );
306
303
307
304
byte [] buffer = ContractTestUtils .toAsciiByteArray ("test data" );
308
305
int bufferLen = buffer .length ;
309
306
block .write (buffer , 0 , bufferLen );
310
307
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 );
316
312
317
313
// now start the write
318
314
OSSDataBlocks .BlockUploadData blockUploadData = block .startUpload ();
319
315
ByteBufferBlockFactory .ByteBufferBlock .ByteBufferInputStream
320
316
stream =
321
317
(ByteBufferBlockFactory .ByteBufferBlock .ByteBufferInputStream )
322
318
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 );
325
321
326
322
int expected = bufferLen ;
327
- assertEquals ("wrong available() in " + stream ,
328
- expected , stream . available ());
323
+ assertEquals (expected , stream . available (),
324
+ "wrong available() in " + stream );
329
325
330
326
assertEquals ('t' , stream .read ());
331
327
stream .mark (limit );
332
328
expected --;
333
- assertEquals ("wrong available() in " + stream ,
334
- expected , stream . available ());
329
+ assertEquals (expected , stream . available (),
330
+ "wrong available() in " + stream );
335
331
336
332
// read into a byte array with an offset
337
333
int offset = 5 ;
@@ -340,8 +336,8 @@ public void testByteBufferIO() throws IOException {
340
336
assertEquals ('e' , in [offset ]);
341
337
assertEquals ('s' , in [offset + 1 ]);
342
338
expected -= 2 ;
343
- assertEquals ("wrong available() in " + stream ,
344
- expected , stream . available ());
339
+ assertEquals (expected , stream . available (),
340
+ "wrong available() in " + stream );
345
341
346
342
// read to end
347
343
byte [] remainder = new byte [limit ];
@@ -353,24 +349,23 @@ public void testByteBufferIO() throws IOException {
353
349
assertEquals (expected , index );
354
350
assertEquals ('a' , remainder [--index ]);
355
351
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 );
359
354
360
355
// go the mark point
361
356
stream .reset ();
362
357
assertEquals ('e' , stream .read ());
363
358
364
359
// when the stream is closed, the data should be returned
365
360
stream .close ();
366
- assertEquals ("outstanding buffers in " + factory ,
367
- 1 , factory . getOutstandingBufferCount () );
361
+ assertEquals (1 , factory . getOutstandingBufferCount () ,
362
+ "outstanding buffers in " + factory );
368
363
block .close ();
369
- assertEquals ("outstanding buffers in " + factory ,
370
- 0 , factory . getOutstandingBufferCount () );
364
+ assertEquals (0 , factory . getOutstandingBufferCount () ,
365
+ "outstanding buffers in " + factory );
371
366
stream .close ();
372
- assertEquals ("outstanding buffers in " + factory ,
373
- 0 , factory . getOutstandingBufferCount () );
367
+ assertEquals (0 , factory . getOutstandingBufferCount () ,
368
+ "outstanding buffers in " + factory );
374
369
}
375
370
}
376
371
0 commit comments