19
19
package org .apache .hadoop .fs ;
20
20
21
21
import static org .apache .hadoop .fs .FileContextTestHelper .createFile ;
22
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
22
23
23
24
import java .io .IOException ;
24
25
import java .net .URI ;
34
35
35
36
import org .apache .hadoop .fs .FileSystem .Statistics ;
36
37
import org .apache .hadoop .test .GenericTestUtils ;
37
- import org .junit .Assert ;
38
- import org .junit .Test ;
38
+ import org .junit .jupiter . api . Test ;
39
+ import org .junit .jupiter . api . Timeout ;
39
40
40
41
import java .util .function .Supplier ;
41
42
import org .apache .hadoop .thirdparty .com .google .common .util .concurrent .Uninterruptibles ;
@@ -59,17 +60,18 @@ public abstract class FCStatisticsBaseTest {
59
60
//fc should be set appropriately by the deriving test.
60
61
protected static FileContext fc = null ;
61
62
62
- @ Test (timeout =60000 )
63
+ @ Test
64
+ @ Timeout (value = 60 )
63
65
public void testStatisticsOperations () throws Exception {
64
66
final Statistics stats = new Statistics ("file" );
65
- Assert . assertEquals (0L , stats .getBytesRead ());
66
- Assert . assertEquals (0L , stats .getBytesWritten ());
67
- Assert . assertEquals (0 , stats .getWriteOps ());
67
+ assertEquals (0L , stats .getBytesRead ());
68
+ assertEquals (0L , stats .getBytesWritten ());
69
+ assertEquals (0 , stats .getWriteOps ());
68
70
stats .incrementBytesWritten (1000 );
69
- Assert . assertEquals (1000L , stats .getBytesWritten ());
70
- Assert . assertEquals (0 , stats .getWriteOps ());
71
+ assertEquals (1000L , stats .getBytesWritten ());
72
+ assertEquals (0 , stats .getWriteOps ());
71
73
stats .incrementWriteOps (123 );
72
- Assert . assertEquals (123 , stats .getWriteOps ());
74
+ assertEquals (123 , stats .getWriteOps ());
73
75
74
76
Thread thread = new Thread () {
75
77
@ Override
@@ -79,33 +81,33 @@ public void run() {
79
81
};
80
82
thread .start ();
81
83
Uninterruptibles .joinUninterruptibly (thread );
82
- Assert . assertEquals (124 , stats .getWriteOps ());
84
+ assertEquals (124 , stats .getWriteOps ());
83
85
// Test copy constructor and reset function
84
86
Statistics stats2 = new Statistics (stats );
85
87
stats .reset ();
86
- Assert . assertEquals (0 , stats .getWriteOps ());
87
- Assert . assertEquals (0L , stats .getBytesWritten ());
88
- Assert . assertEquals (0L , stats .getBytesRead ());
89
- Assert . assertEquals (124 , stats2 .getWriteOps ());
90
- Assert . assertEquals (1000L , stats2 .getBytesWritten ());
91
- Assert . assertEquals (0L , stats2 .getBytesRead ());
88
+ assertEquals (0 , stats .getWriteOps ());
89
+ assertEquals (0L , stats .getBytesWritten ());
90
+ assertEquals (0L , stats .getBytesRead ());
91
+ assertEquals (124 , stats2 .getWriteOps ());
92
+ assertEquals (1000L , stats2 .getBytesWritten ());
93
+ assertEquals (0L , stats2 .getBytesRead ());
92
94
}
93
95
94
96
@ Test
95
97
public void testStatistics () throws IOException , URISyntaxException {
96
98
URI fsUri = getFsUri ();
97
99
Statistics stats = FileContext .getStatistics (fsUri );
98
- Assert . assertEquals (0 , stats .getBytesRead ());
100
+ assertEquals (0 , stats .getBytesRead ());
99
101
Path filePath = fileContextTestHelper .getTestRootPath (fc , "file1" );
100
102
createFile (fc , filePath , numBlocks , blockSize );
101
103
102
- Assert . assertEquals (0 , stats .getBytesRead ());
104
+ assertEquals (0 , stats .getBytesRead ());
103
105
verifyWrittenBytes (stats );
104
106
FSDataInputStream fstr = fc .open (filePath );
105
107
byte [] buf = new byte [blockSize ];
106
108
int bytesRead = fstr .read (buf , 0 , blockSize );
107
109
fstr .read (0 , buf , 0 , blockSize );
108
- Assert . assertEquals (blockSize , bytesRead );
110
+ assertEquals (blockSize , bytesRead );
109
111
verifyReadBytes (stats );
110
112
verifyWrittenBytes (stats );
111
113
verifyReadBytes (FileContext .getStatistics (getFsUri ()));
@@ -115,7 +117,8 @@ public void testStatistics() throws IOException, URISyntaxException {
115
117
fc .delete (filePath , true );
116
118
}
117
119
118
- @ Test (timeout =70000 )
120
+ @ Test
121
+ @ Timeout (value = 70 )
119
122
public void testStatisticsThreadLocalDataCleanUp () throws Exception {
120
123
final Statistics stats = new Statistics ("test" );
121
124
// create a small thread pool to test the statistics
@@ -136,8 +139,8 @@ public Boolean call() {
136
139
// assert that the data size is exactly the number of threads
137
140
final AtomicInteger allDataSize = new AtomicInteger (0 );
138
141
allDataSize .set (stats .getAllThreadLocalDataSize ());
139
- Assert . assertEquals (size , allDataSize .get ());
140
- Assert . assertEquals (size , stats .getReadOps ());
142
+ assertEquals (size , allDataSize .get ());
143
+ assertEquals (size , stats .getReadOps ());
141
144
// force the GC to collect the threads by shutting down the thread pool
142
145
es .shutdownNow ();
143
146
es .awaitTermination (1 , TimeUnit .MINUTES );
@@ -160,8 +163,8 @@ public Boolean get() {
160
163
return false ;
161
164
}
162
165
}, 500 , 60 *1000 );
163
- Assert . assertEquals (0 , allDataSize .get ());
164
- Assert . assertEquals (size , stats .getReadOps ());
166
+ assertEquals (0 , allDataSize .get ());
167
+ assertEquals (size , stats .getReadOps ());
165
168
}
166
169
167
170
/**
0 commit comments