Skip to content

Commit 1cda2dc

Browse files
hotcodemachaAshutosh Gupta
andauthored
YARN-10793. Upgrade Junit from 4 to 5 in hadoop-yarn-server-applicationhistoryservice (#4603)
Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com> Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
1 parent 52c2d99 commit 1cda2dc

21 files changed

+1391
-1356
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<yarn.basedir>${project.parent.parent.basedir}</yarn.basedir>
3535
</properties>
3636

37+
38+
3739
<dependencies>
3840
<dependency>
3941
<groupId>javax.servlet</groupId>
@@ -194,6 +196,21 @@
194196
<artifactId>bcprov-jdk15on</artifactId>
195197
<scope>test</scope>
196198
</dependency>
199+
<dependency>
200+
<groupId>org.junit.jupiter</groupId>
201+
<artifactId>junit-jupiter-api</artifactId>
202+
<scope>test</scope>
203+
</dependency>
204+
<dependency>
205+
<groupId>org.junit.jupiter</groupId>
206+
<artifactId>junit-jupiter-engine</artifactId>
207+
<scope>test</scope>
208+
</dependency>
209+
<dependency>
210+
<groupId>org.junit.jupiter</groupId>
211+
<artifactId>junit-jupiter-params</artifactId>
212+
<scope>test</scope>
213+
</dependency>
197214
<dependency>
198215
<groupId>de.ruedigermoeller</groupId>
199216
<artifactId>fst</artifactId>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryClientService.java

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import java.io.IOException;
2222
import java.util.List;
2323

24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.Test;
26+
2427
import org.apache.hadoop.conf.Configuration;
2528
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
2629
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
@@ -49,17 +52,19 @@
4952
import org.apache.hadoop.yarn.server.timeline.TimelineDataManager;
5053
import org.apache.hadoop.yarn.server.timeline.TimelineStore;
5154
import org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager;
52-
import org.junit.Assert;
53-
import org.junit.BeforeClass;
54-
import org.junit.Test;
55+
56+
import static org.junit.jupiter.api.Assertions.assertEquals;
57+
import static org.junit.jupiter.api.Assertions.assertNotNull;
58+
import static org.junit.jupiter.api.Assertions.assertTrue;
59+
import static org.junit.jupiter.api.Assertions.fail;
5560

5661
public class TestApplicationHistoryClientService {
5762

5863
private static ApplicationHistoryClientService clientService;
5964
private static TimelineDataManager dataManager;
6065
private final static int MAX_APPS = 2;
6166

62-
@BeforeClass
67+
@BeforeAll
6368
public static void setup() throws Exception {
6469
Configuration conf = new YarnConfiguration();
6570
TimelineStore store =
@@ -78,7 +83,7 @@ public static void setup() throws Exception {
7883
}
7984

8085
@Test
81-
public void testApplicationNotFound() throws IOException, YarnException {
86+
void testApplicationNotFound() throws IOException, YarnException {
8287
ApplicationId appId = null;
8388
appId = ApplicationId.newInstance(0, MAX_APPS + 1);
8489
GetApplicationReportRequest request =
@@ -87,18 +92,18 @@ public void testApplicationNotFound() throws IOException, YarnException {
8792
@SuppressWarnings("unused")
8893
GetApplicationReportResponse response =
8994
clientService.getApplicationReport(request);
90-
Assert.fail("Exception should have been thrown before we reach here.");
95+
fail("Exception should have been thrown before we reach here.");
9196
} catch (ApplicationNotFoundException e) {
9297
//This exception is expected.
93-
Assert.assertTrue(e.getMessage().contains(
98+
assertTrue(e.getMessage().contains(
9499
"doesn't exist in the timeline store"));
95100
} catch (Exception e) {
96-
Assert.fail("Undesired exception caught");
101+
fail("Undesired exception caught");
97102
}
98103
}
99104

100105
@Test
101-
public void testApplicationAttemptNotFound() throws IOException, YarnException {
106+
void testApplicationAttemptNotFound() throws IOException, YarnException {
102107
ApplicationId appId = ApplicationId.newInstance(0, 1);
103108
ApplicationAttemptId appAttemptId =
104109
ApplicationAttemptId.newInstance(appId, MAX_APPS + 1);
@@ -108,95 +113,95 @@ public void testApplicationAttemptNotFound() throws IOException, YarnException {
108113
@SuppressWarnings("unused")
109114
GetApplicationAttemptReportResponse response =
110115
clientService.getApplicationAttemptReport(request);
111-
Assert.fail("Exception should have been thrown before we reach here.");
116+
fail("Exception should have been thrown before we reach here.");
112117
} catch (ApplicationAttemptNotFoundException e) {
113118
//This Exception is expected
114119
System.out.println(e.getMessage());
115-
Assert.assertTrue(e.getMessage().contains(
120+
assertTrue(e.getMessage().contains(
116121
"doesn't exist in the timeline store"));
117122
} catch (Exception e) {
118-
Assert.fail("Undesired exception caught");
123+
fail("Undesired exception caught");
119124
}
120125
}
121126

122127
@Test
123-
public void testContainerNotFound() throws IOException, YarnException {
124-
ApplicationId appId = ApplicationId.newInstance(0, 1);
125-
ApplicationAttemptId appAttemptId =
126-
ApplicationAttemptId.newInstance(appId, 1);
127-
ContainerId containerId = ContainerId.newContainerId(appAttemptId,
128-
MAX_APPS + 1);
129-
GetContainerReportRequest request =
130-
GetContainerReportRequest.newInstance(containerId);
131-
try {
132-
@SuppressWarnings("unused")
133-
GetContainerReportResponse response =
134-
clientService.getContainerReport(request);
135-
} catch (ContainerNotFoundException e) {
136-
//This exception is expected
137-
Assert.assertTrue(e.getMessage().contains(
138-
"doesn't exist in the timeline store"));
139-
} catch (Exception e) {
140-
Assert.fail("Undesired exception caught");
141-
}
142-
}
128+
void testContainerNotFound() throws IOException, YarnException {
129+
ApplicationId appId = ApplicationId.newInstance(0, 1);
130+
ApplicationAttemptId appAttemptId =
131+
ApplicationAttemptId.newInstance(appId, 1);
132+
ContainerId containerId = ContainerId.newContainerId(appAttemptId,
133+
MAX_APPS + 1);
134+
GetContainerReportRequest request =
135+
GetContainerReportRequest.newInstance(containerId);
136+
try {
137+
@SuppressWarnings("unused")
138+
GetContainerReportResponse response =
139+
clientService.getContainerReport(request);
140+
} catch (ContainerNotFoundException e) {
141+
//This exception is expected
142+
assertTrue(e.getMessage().contains(
143+
"doesn't exist in the timeline store"));
144+
} catch (Exception e) {
145+
fail("Undesired exception caught");
146+
}
147+
}
143148

144149
@Test
145-
public void testApplicationReport() throws IOException, YarnException {
150+
void testApplicationReport() throws IOException, YarnException {
146151
ApplicationId appId = null;
147152
appId = ApplicationId.newInstance(0, 1);
148153
GetApplicationReportRequest request =
149154
GetApplicationReportRequest.newInstance(appId);
150155
GetApplicationReportResponse response =
151156
clientService.getApplicationReport(request);
152157
ApplicationReport appReport = response.getApplicationReport();
153-
Assert.assertNotNull(appReport);
154-
Assert.assertEquals(123, appReport.getApplicationResourceUsageReport()
158+
assertNotNull(appReport);
159+
assertEquals(123, appReport.getApplicationResourceUsageReport()
155160
.getMemorySeconds());
156-
Assert.assertEquals(345, appReport.getApplicationResourceUsageReport()
161+
assertEquals(345, appReport.getApplicationResourceUsageReport()
157162
.getVcoreSeconds());
158-
Assert.assertEquals("application_0_0001", appReport.getApplicationId()
159-
.toString());
160-
Assert.assertEquals("test app type",
163+
assertEquals("application_0_0001", appReport.getApplicationId()
164+
.toString());
165+
assertEquals("test app type",
161166
appReport.getApplicationType().toString());
162-
Assert.assertEquals("test queue", appReport.getQueue().toString());
167+
assertEquals("test queue", appReport.getQueue().toString());
163168
}
164169

165170
@Test
166-
public void testApplications() throws IOException, YarnException {
171+
void testApplications() throws IOException, YarnException {
167172
ApplicationId appId = null;
168173
appId = ApplicationId.newInstance(0, 1);
169174
ApplicationId appId1 = ApplicationId.newInstance(0, 2);
170175
GetApplicationsRequest request = GetApplicationsRequest.newInstance();
171176
GetApplicationsResponse response =
172177
clientService.getApplications(request);
173178
List<ApplicationReport> appReport = response.getApplicationList();
174-
Assert.assertNotNull(appReport);
175-
Assert.assertEquals(appId, appReport.get(1).getApplicationId());
176-
Assert.assertEquals(appId1, appReport.get(0).getApplicationId());
179+
assertNotNull(appReport);
180+
assertEquals(appId, appReport.get(1).getApplicationId());
181+
assertEquals(appId1, appReport.get(0).getApplicationId());
177182

178183
// Create a historyManager, and set the max_apps can be loaded
179184
// as 1.
180185
Configuration conf = new YarnConfiguration();
181186
conf.setLong(YarnConfiguration.APPLICATION_HISTORY_MAX_APPS, 1);
182187
ApplicationHistoryManagerOnTimelineStore historyManager2 =
183188
new ApplicationHistoryManagerOnTimelineStore(dataManager,
184-
new ApplicationACLsManager(conf));
189+
new ApplicationACLsManager(conf));
185190
historyManager2.init(conf);
186191
historyManager2.start();
187192
@SuppressWarnings("resource")
188193
ApplicationHistoryClientService clientService2 =
189194
new ApplicationHistoryClientService(historyManager2);
190195
response = clientService2.getApplications(request);
191196
appReport = response.getApplicationList();
192-
Assert.assertNotNull(appReport);
193-
Assert.assertTrue(appReport.size() == 1);
197+
assertNotNull(appReport);
198+
assertTrue(appReport.size() == 1);
194199
// Expected to get the appReport for application with appId1
195-
Assert.assertEquals(appId1, appReport.get(0).getApplicationId());
200+
assertEquals(appId1, appReport.get(0).getApplicationId());
196201
}
197202

198203
@Test
199-
public void testApplicationAttemptReport() throws IOException, YarnException {
204+
void testApplicationAttemptReport() throws IOException, YarnException {
200205
ApplicationId appId = ApplicationId.newInstance(0, 1);
201206
ApplicationAttemptId appAttemptId =
202207
ApplicationAttemptId.newInstance(appId, 1);
@@ -206,13 +211,13 @@ public void testApplicationAttemptReport() throws IOException, YarnException {
206211
clientService.getApplicationAttemptReport(request);
207212
ApplicationAttemptReport attemptReport =
208213
response.getApplicationAttemptReport();
209-
Assert.assertNotNull(attemptReport);
210-
Assert.assertEquals("appattempt_0_0001_000001", attemptReport
211-
.getApplicationAttemptId().toString());
214+
assertNotNull(attemptReport);
215+
assertEquals("appattempt_0_0001_000001", attemptReport
216+
.getApplicationAttemptId().toString());
212217
}
213218

214219
@Test
215-
public void testApplicationAttempts() throws IOException, YarnException {
220+
void testApplicationAttempts() throws IOException, YarnException {
216221
ApplicationId appId = ApplicationId.newInstance(0, 1);
217222
ApplicationAttemptId appAttemptId =
218223
ApplicationAttemptId.newInstance(appId, 1);
@@ -224,15 +229,15 @@ public void testApplicationAttempts() throws IOException, YarnException {
224229
clientService.getApplicationAttempts(request);
225230
List<ApplicationAttemptReport> attemptReports =
226231
response.getApplicationAttemptList();
227-
Assert.assertNotNull(attemptReports);
228-
Assert.assertEquals(appAttemptId, attemptReports.get(0)
229-
.getApplicationAttemptId());
230-
Assert.assertEquals(appAttemptId1, attemptReports.get(1)
231-
.getApplicationAttemptId());
232+
assertNotNull(attemptReports);
233+
assertEquals(appAttemptId, attemptReports.get(0)
234+
.getApplicationAttemptId());
235+
assertEquals(appAttemptId1, attemptReports.get(1)
236+
.getApplicationAttemptId());
232237
}
233238

234239
@Test
235-
public void testContainerReport() throws IOException, YarnException {
240+
void testContainerReport() throws IOException, YarnException {
236241
ApplicationId appId = ApplicationId.newInstance(0, 1);
237242
ApplicationAttemptId appAttemptId =
238243
ApplicationAttemptId.newInstance(appId, 1);
@@ -242,15 +247,15 @@ public void testContainerReport() throws IOException, YarnException {
242247
GetContainerReportResponse response =
243248
clientService.getContainerReport(request);
244249
ContainerReport container = response.getContainerReport();
245-
Assert.assertNotNull(container);
246-
Assert.assertEquals(containerId, container.getContainerId());
247-
Assert.assertEquals("http://0.0.0.0:8188/applicationhistory/logs/" +
250+
assertNotNull(container);
251+
assertEquals(containerId, container.getContainerId());
252+
assertEquals("http://0.0.0.0:8188/applicationhistory/logs/" +
248253
"test host:100/container_0_0001_01_000001/" +
249254
"container_0_0001_01_000001/user1", container.getLogUrl());
250255
}
251256

252257
@Test
253-
public void testContainers() throws IOException, YarnException {
258+
void testContainers() throws IOException, YarnException {
254259
ApplicationId appId = ApplicationId.newInstance(0, 1);
255260
ApplicationAttemptId appAttemptId =
256261
ApplicationAttemptId.newInstance(appId, 1);
@@ -261,8 +266,8 @@ public void testContainers() throws IOException, YarnException {
261266
GetContainersResponse response =
262267
clientService.getContainers(request);
263268
List<ContainerReport> containers = response.getContainerList();
264-
Assert.assertNotNull(containers);
265-
Assert.assertEquals(containerId, containers.get(0).getContainerId());
266-
Assert.assertEquals(containerId1, containers.get(1).getContainerId());
269+
assertNotNull(containers);
270+
assertEquals(containerId, containers.get(0).getContainerId());
271+
assertEquals(containerId1, containers.get(1).getContainerId());
267272
}
268273
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerImpl.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,43 @@
2121
import java.io.IOException;
2222
import java.util.Map;
2323

24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
2428
import org.apache.hadoop.conf.Configuration;
2529
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
2630
import org.apache.hadoop.yarn.api.records.ApplicationId;
2731
import org.apache.hadoop.yarn.api.records.ApplicationReport;
2832
import org.apache.hadoop.yarn.conf.YarnConfiguration;
2933
import org.apache.hadoop.yarn.exceptions.YarnException;
30-
import org.junit.After;
31-
import org.junit.Assert;
32-
import org.junit.Before;
33-
import org.junit.Test;
34+
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertNotNull;
37+
import static org.junit.jupiter.api.Assertions.assertNull;
3438

3539
public class TestApplicationHistoryManagerImpl extends
3640
ApplicationHistoryStoreTestUtils {
37-
ApplicationHistoryManagerImpl applicationHistoryManagerImpl = null;
41+
private ApplicationHistoryManagerImpl applicationHistoryManagerImpl = null;
3842

39-
@Before
43+
@BeforeEach
4044
public void setup() throws Exception {
4145
Configuration config = new Configuration();
4246
config.setClass(YarnConfiguration.APPLICATION_HISTORY_STORE,
43-
MemoryApplicationHistoryStore.class, ApplicationHistoryStore.class);
47+
MemoryApplicationHistoryStore.class, ApplicationHistoryStore.class);
4448
applicationHistoryManagerImpl = new ApplicationHistoryManagerImpl();
4549
applicationHistoryManagerImpl.init(config);
4650
applicationHistoryManagerImpl.start();
4751
store = applicationHistoryManagerImpl.getHistoryStore();
4852
}
4953

50-
@After
54+
@AfterEach
5155
public void tearDown() throws Exception {
5256
applicationHistoryManagerImpl.stop();
5357
}
5458

5559
@Test
56-
public void testApplicationReport() throws IOException, YarnException {
60+
void testApplicationReport() throws IOException, YarnException {
5761
ApplicationId appId = null;
5862
appId = ApplicationId.newInstance(0, 1);
5963
writeApplicationStartData(appId);
@@ -64,17 +68,17 @@ public void testApplicationReport() throws IOException, YarnException {
6468
writeApplicationAttemptFinishData(appAttemptId);
6569
ApplicationReport appReport =
6670
applicationHistoryManagerImpl.getApplication(appId);
67-
Assert.assertNotNull(appReport);
68-
Assert.assertEquals(appId, appReport.getApplicationId());
69-
Assert.assertEquals(appAttemptId,
70-
appReport.getCurrentApplicationAttemptId());
71-
Assert.assertEquals(appAttemptId.toString(), appReport.getHost());
72-
Assert.assertEquals("test type", appReport.getApplicationType().toString());
73-
Assert.assertEquals("test queue", appReport.getQueue().toString());
71+
assertNotNull(appReport);
72+
assertEquals(appId, appReport.getApplicationId());
73+
assertEquals(appAttemptId,
74+
appReport.getCurrentApplicationAttemptId());
75+
assertEquals(appAttemptId.toString(), appReport.getHost());
76+
assertEquals("test type", appReport.getApplicationType().toString());
77+
assertEquals("test queue", appReport.getQueue().toString());
7478
}
7579

7680
@Test
77-
public void testApplications() throws IOException {
81+
void testApplications() throws IOException {
7882
ApplicationId appId1 = ApplicationId.newInstance(0, 1);
7983
ApplicationId appId2 = ApplicationId.newInstance(0, 2);
8084
ApplicationId appId3 = ApplicationId.newInstance(0, 3);
@@ -86,10 +90,10 @@ public void testApplications() throws IOException {
8690
writeApplicationFinishData(appId3);
8791
Map<ApplicationId, ApplicationReport> reports =
8892
applicationHistoryManagerImpl.getApplications(2, 2000L, 5000L);
89-
Assert.assertNotNull(reports);
90-
Assert.assertEquals(2, reports.size());
91-
Assert.assertNull(reports.get("1"));
92-
Assert.assertNull(reports.get("2"));
93-
Assert.assertNull(reports.get("3"));
93+
assertNotNull(reports);
94+
assertEquals(2, reports.size());
95+
assertNull(reports.get("1"));
96+
assertNull(reports.get("2"));
97+
assertNull(reports.get("3"));
9498
}
9599
}

0 commit comments

Comments
 (0)