Skip to content

Commit a98d158

Browse files
authored
MAPREDUCE-7419. Upgrade Junit 4 to 5 in hadoop-mapreduce-client-common (#5028). Contributed by Ashutosh Gupta.
Signed-off-by: Ayush Saxena <[email protected]>
1 parent 3b65b5d commit a98d158

File tree

13 files changed

+508
-449
lines changed

13 files changed

+508
-449
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@
5151
<artifactId>assertj-core</artifactId>
5252
<scope>test</scope>
5353
</dependency>
54+
<dependency>
55+
<groupId>org.junit.jupiter</groupId>
56+
<artifactId>junit-jupiter-api</artifactId>
57+
<scope>test</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.junit.jupiter</groupId>
61+
<artifactId>junit-jupiter-engine</artifactId>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.junit.platform</groupId>
66+
<artifactId>junit-platform-launcher</artifactId>
67+
<scope>test</scope>
68+
</dependency>
5469
</dependencies>
5570

5671
<build>

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@
2222
import java.util.Collection;
2323

2424
import org.apache.hadoop.conf.Configuration;
25+
2526
import org.apache.hadoop.fs.FileSystem;
2627
import org.apache.hadoop.fs.FileUtil;
2728
import org.apache.hadoop.fs.Path;
2829
import org.apache.hadoop.mapred.ClusterStatus.BlackListInfo;
2930
import org.apache.hadoop.mapreduce.MRConfig;
3031
import org.apache.hadoop.mapreduce.server.jobtracker.JTConfig;
31-
import org.junit.After;
32-
import org.junit.Assert;
33-
import org.junit.Test;
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.Timeout;
35+
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertFalse;
38+
import static org.junit.jupiter.api.Assertions.assertTrue;
3439

3540
public class TestJobClient {
3641

3742
final static String TEST_DIR = new File("target",
3843
TestJobClient.class.getSimpleName()).getAbsolutePath();
3944

40-
@After
45+
@AfterEach
4146
public void tearDown() {
4247
FileUtil.fullyDelete(new File(TEST_DIR));
4348
}
@@ -51,47 +56,48 @@ public void testGetClusterStatusWithLocalJobRunner() throws Exception {
5156
ClusterStatus clusterStatus = client.getClusterStatus(true);
5257
Collection<String> activeTrackerNames = clusterStatus
5358
.getActiveTrackerNames();
54-
Assert.assertEquals(0, activeTrackerNames.size());
59+
assertEquals(0, activeTrackerNames.size());
5560
int blacklistedTrackers = clusterStatus.getBlacklistedTrackers();
56-
Assert.assertEquals(0, blacklistedTrackers);
61+
assertEquals(0, blacklistedTrackers);
5762
Collection<BlackListInfo> blackListedTrackersInfo = clusterStatus
5863
.getBlackListedTrackersInfo();
59-
Assert.assertEquals(0, blackListedTrackersInfo.size());
64+
assertEquals(0, blackListedTrackersInfo.size());
6065
}
6166

62-
@Test(timeout = 10000)
67+
@Test
68+
@Timeout(10000)
6369
public void testIsJobDirValid() throws IOException {
6470
Configuration conf = new Configuration();
6571
FileSystem fs = FileSystem.getLocal(conf);
6672
Path testDir = new Path(TEST_DIR);
6773
fs.mkdirs(testDir);
68-
Assert.assertFalse(JobClient.isJobDirValid(testDir, fs));
74+
assertFalse(JobClient.isJobDirValid(testDir, fs));
6975

7076
Path jobconf = new Path(testDir, "job.xml");
7177
Path jobsplit = new Path(testDir, "job.split");
7278
fs.create(jobconf);
7379
fs.create(jobsplit);
74-
Assert.assertTrue(JobClient.isJobDirValid(testDir, fs));
75-
80+
assertTrue(JobClient.isJobDirValid(testDir, fs));
81+
7682
fs.delete(jobconf, true);
7783
fs.delete(jobsplit, true);
7884
}
79-
80-
@Test(timeout = 10000)
85+
86+
@Test
87+
@Timeout(10000)
8188
public void testGetStagingAreaDir() throws IOException, InterruptedException {
8289
Configuration conf = new Configuration();
8390
JobClient client = new JobClient(conf);
8491

85-
Assert.assertTrue(
86-
"Mismatch in paths",
87-
client.getClusterHandle().getStagingAreaDir().toString()
88-
.equals(client.getStagingAreaDir().toString()));
92+
assertEquals(client.getClusterHandle().getStagingAreaDir().toString(),
93+
client.getStagingAreaDir().toString());
8994
}
9095

9196
/**
9297
* Asks the compiler to check if JobClient is AutoClosable.
9398
*/
94-
@Test(timeout = 10000)
99+
@Test
100+
@Timeout(10000)
95101
public void testAutoClosable() throws IOException {
96102
Configuration conf = new Configuration();
97103
try (JobClient jobClient = new JobClient(conf)) {

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClientGetJob.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
package org.apache.hadoop.mapred;
2020

21-
import static org.junit.Assert.assertNotNull;
22-
2321
import java.io.IOException;
2422

23+
import org.junit.jupiter.api.Test;
24+
2525
import org.apache.hadoop.conf.Configuration;
2626
import org.apache.hadoop.fs.FSDataOutputStream;
2727
import org.apache.hadoop.fs.FileSystem;
2828
import org.apache.hadoop.fs.Path;
29-
import org.junit.Test;
29+
30+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3031

3132
public class TestJobClientGetJob {
3233

@@ -42,7 +43,7 @@ private Path createTempFile(String filename, String contents)
4243
os.close();
4344
return path;
4445
}
45-
46+
4647
@SuppressWarnings("deprecation")
4748
@Test
4849
public void testGetRunningJobFromJobClient() throws Exception {
@@ -54,10 +55,10 @@ public void testGetRunningJobFromJobClient() throws Exception {
5455
FileOutputFormat.setOutputPath(conf, outputDir);
5556
JobClient jc = new JobClient(conf);
5657
RunningJob runningJob = jc.submitJob(conf);
57-
assertNotNull("Running job", runningJob);
58+
assertNotNull(runningJob, "Running job");
5859
// Check that the running job can be retrieved by ID
5960
RunningJob newRunningJob = jc.getJob(runningJob.getID());
60-
assertNotNull("New running job", newRunningJob);
61+
assertNotNull(newRunningJob, "New running job");
6162
}
6263

6364
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestLocalDistributedCacheManager.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
package org.apache.hadoop.mapred;
2020

21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323
import static org.mockito.ArgumentMatchers.any;
2424
import static org.mockito.Mockito.mock;
2525
import static org.mockito.Mockito.when;
@@ -55,9 +55,9 @@
5555
import org.apache.hadoop.mapreduce.MRConfig;
5656
import org.apache.hadoop.mapreduce.MRJobConfig;
5757
import org.apache.hadoop.util.functional.CallableRaisingIOE;
58-
import org.junit.After;
59-
import org.junit.Before;
60-
import org.junit.Test;
58+
import org.junit.jupiter.api.AfterEach;
59+
import org.junit.jupiter.api.BeforeEach;
60+
import org.junit.jupiter.api.Test;
6161
import org.mockito.invocation.InvocationOnMock;
6262
import org.mockito.stubbing.Answer;
6363

@@ -109,7 +109,7 @@ private static void delete(File file) throws IOException {
109109
}
110110
}
111111

112-
@Before
112+
@BeforeEach
113113
public void setup() throws Exception {
114114
mockfs = mock(FileSystem.class);
115115
localDir = new File(System.getProperty("test.build.dir", "target/test-dir"),
@@ -118,7 +118,7 @@ public void setup() throws Exception {
118118
localDir.mkdirs();
119119
}
120120

121-
@After
121+
@AfterEach
122122
public void cleanup() throws Exception {
123123
delete(localDir);
124124
}
@@ -163,8 +163,8 @@ public void testDownload() throws Exception {
163163
when(mockfs.getFileStatus(any(Path.class))).thenAnswer(new Answer<FileStatus>() {
164164
@Override
165165
public FileStatus answer(InvocationOnMock args) throws Throwable {
166-
Path p = (Path)args.getArguments()[0];
167-
if("file.txt".equals(p.getName())) {
166+
Path p = (Path) args.getArguments()[0];
167+
if ("file.txt".equals(p.getName())) {
168168
return createMockTestFileStatus(filePath);
169169
} else {
170170
throw notMocked(p);
@@ -180,7 +180,7 @@ public FileStatus answer(InvocationOnMock args) throws Throwable {
180180
// anything else: FNFE
181181
when(mockfs.openFile(any(Path.class))).thenAnswer(
182182
(Answer<FutureDataInputStreamBuilder>) args -> {
183-
Path src = (Path)args.getArguments()[0];
183+
Path src = (Path) args.getArguments()[0];
184184
if ("file.txt".equals(src.getName())) {
185185
return new MockOpenFileBuilder(mockfs, src,
186186
() -> CompletableFuture.completedFuture(in));
@@ -228,15 +228,15 @@ public void testEmptyDownload() throws Exception {
228228

229229
when(mockfs.getFileStatus(any(Path.class))).thenAnswer(
230230
(Answer<FileStatus>) args -> {
231-
Path p = (Path)args.getArguments()[0];
231+
Path p = (Path) args.getArguments()[0];
232232
throw notMocked(p);
233233
});
234234

235235
when(mockfs.getConf()).thenReturn(conf);
236236
when(mockfs.openFile(any(Path.class))).thenAnswer(
237237
(Answer<FutureDataInputStreamBuilder>) args -> {
238-
Path src = (Path)args.getArguments()[0];
239-
throw notMocked(src);
238+
Path src = (Path) args.getArguments()[0];
239+
throw notMocked(src);
240240
});
241241
conf.set(MRJobConfig.CACHE_FILES, "");
242242
conf.set(MRConfig.LOCAL_DIR, localDir.getAbsolutePath());
@@ -272,8 +272,8 @@ public void testDuplicateDownload() throws Exception {
272272
when(mockfs.getFileStatus(any(Path.class))).thenAnswer(new Answer<FileStatus>() {
273273
@Override
274274
public FileStatus answer(InvocationOnMock args) throws Throwable {
275-
Path p = (Path)args.getArguments()[0];
276-
if("file.txt".equals(p.getName())) {
275+
Path p = (Path) args.getArguments()[0];
276+
if ("file.txt".equals(p.getName())) {
277277
return createMockTestFileStatus(filePath);
278278
} else {
279279
throw notMocked(p);
@@ -286,7 +286,7 @@ public FileStatus answer(InvocationOnMock args) throws Throwable {
286286
new FSDataInputStream(new MockInputStream(TEST_DATA));
287287
when(mockfs.openFile(any(Path.class))).thenAnswer(
288288
(Answer<FutureDataInputStreamBuilder>) args -> {
289-
Path src = (Path)args.getArguments()[0];
289+
Path src = (Path) args.getArguments()[0];
290290
if ("file.txt".equals(src.getName())) {
291291
return new MockOpenFileBuilder(mockfs, src,
292292
() -> CompletableFuture.completedFuture(in));

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestLocalModeWithNewApis.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
*/
1818
package org.apache.hadoop.mapred;
1919

20-
import static org.junit.Assert.*;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2122

2223
import java.io.BufferedReader;
2324
import java.io.DataOutputStream;
@@ -38,9 +39,9 @@
3839
import org.apache.hadoop.mapreduce.Reducer;
3940
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
4041
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
41-
import org.junit.After;
42-
import org.junit.Before;
43-
import org.junit.Test;
42+
import org.junit.jupiter.api.AfterEach;
43+
import org.junit.jupiter.api.BeforeEach;
44+
import org.junit.jupiter.api.Test;
4445
import org.slf4j.Logger;
4546
import org.slf4j.LoggerFactory;
4647

@@ -51,13 +52,13 @@ public class TestLocalModeWithNewApis {
5152

5253
Configuration conf;
5354

54-
@Before
55+
@BeforeEach
5556
public void setUp() throws Exception {
5657
conf = new Configuration();
5758
conf.set(MRConfig.FRAMEWORK_NAME, MRConfig.LOCAL_FRAMEWORK_NAME);
5859
}
5960

60-
@After
61+
@AfterEach
6162
public void tearDown() throws Exception {
6263
}
6364

@@ -93,8 +94,8 @@ public void testNewApis() throws Exception {
9394

9495
String output = readOutput(outDir, conf);
9596
assertEquals("The\t1\nbrown\t1\nfox\t2\nhas\t1\nmany\t1\n" +
96-
"quick\t1\nred\t1\nsilly\t1\nsox\t1\n", output);
97-
97+
"quick\t1\nred\t1\nsilly\t1\nsox\t1\n", output);
98+
9899
outFs.delete(tmpBaseDir, true);
99100
}
100101

0 commit comments

Comments
 (0)