Skip to content

Commit 590fe7c

Browse files
slfan1989zhtttylz
andauthored
YARN-11267. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-router. (#7546)
* YARN-11267. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-router. Co-authored-by: Hualong Zhang <hualong.z@hotmail.com> Reviewed-by: Hualong Zhang <hualong.z@hotmail.com> Signed-off-by: Shilun Fan <slfan1989@apache.org>
1 parent f099f08 commit 590fe7c

File tree

38 files changed

+1740
-1523
lines changed

38 files changed

+1740
-1523
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@
200200
<artifactId>junit-vintage-engine</artifactId>
201201
<scope>test</scope>
202202
</dependency>
203+
<dependency>
204+
<groupId>org.glassfish.jersey.media</groupId>
205+
<artifactId>jersey-media-json-jettison</artifactId>
206+
</dependency>
203207
</dependencies>
204208

205209
<build>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/policies/dao/WeightedPolicyInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.HashMap;
2323
import java.util.Map;
2424

25+
import com.fasterxml.jackson.annotation.JsonProperty;
2526
import com.fasterxml.jackson.core.JsonProcessingException;
2627
import com.fasterxml.jackson.databind.ObjectMapper;
2728
import javax.xml.bind.annotation.XmlAccessType;
@@ -52,8 +53,11 @@ public class WeightedPolicyInfo {
5253
private static final Logger LOG =
5354
LoggerFactory.getLogger(WeightedPolicyInfo.class);
5455
private static ObjectMapper mapper = new ObjectMapper();
56+
@JsonProperty("routerPolicyWeights")
5557
private Map<SubClusterIdInfo, Float> routerPolicyWeights = new HashMap<>();
58+
@JsonProperty("amrmPolicyWeights")
5659
private Map<SubClusterIdInfo, Float> amrmPolicyWeights = new HashMap<>();
60+
@JsonProperty("headroomAlpha")
5761
private float headroomAlpha;
5862

5963
public WeightedPolicyInfo() {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/SubClusterIdInfo.java

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

1919
package org.apache.hadoop.yarn.server.federation.store.records;
2020

21+
import com.fasterxml.jackson.annotation.JsonProperty;
2122
import org.apache.commons.lang3.builder.EqualsBuilder;
2223
import org.apache.commons.lang3.builder.HashCodeBuilder;
2324
import org.apache.hadoop.classification.InterfaceAudience;
@@ -55,6 +56,7 @@ public SubClusterIdInfo(SubClusterId subClusterId) {
5556
* Get the sub-cluster identifier as {@link SubClusterId}.
5657
* @return the sub-cluster id.
5758
*/
59+
@JsonProperty("id")
5860
public SubClusterId toId() {
5961
return SubClusterId.newInstance(id);
6062
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/DefaultRMAdminRequestInterceptor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.apache.hadoop.conf.Configuration;
2525
import org.apache.hadoop.ipc.StandbyException;
26-
import org.apache.hadoop.security.UserGroupInformation;
2726
import org.apache.hadoop.yarn.client.ClientRMProxy;
2827
import org.apache.hadoop.yarn.exceptions.YarnException;
2928
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
@@ -86,7 +85,6 @@ public class DefaultRMAdminRequestInterceptor
8685
private static final Logger LOG =
8786
LoggerFactory.getLogger(DefaultRMAdminRequestInterceptor.class);
8887
private ResourceManagerAdministrationProtocol rmAdminProxy;
89-
private UserGroupInformation user = null;
9088

9189
@Override
9290
public void init(String userName) {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
141141
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
142142
import org.apache.hadoop.yarn.util.LRUCacheHashMap;
143+
import org.apache.hadoop.yarn.webapp.ForbiddenException;
143144
import org.apache.hadoop.yarn.webapp.dao.ConfInfo;
144145
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;
145146
import org.apache.hadoop.yarn.util.Clock;
@@ -1001,8 +1002,8 @@ private SubClusterInfo getNodeSubcluster(String nodeId) throws NotFoundException
10011002
NodeInfo nodeInfo = null;
10021003
for (Entry<SubClusterInfo, NodeInfo> entry : results.entrySet()) {
10031004
NodeInfo nodeResponse = entry.getValue();
1004-
if (nodeInfo == null || nodeInfo.getLastHealthUpdate() <
1005-
nodeResponse.getLastHealthUpdate()) {
1005+
if (nodeInfo == null || (nodeResponse != null &&
1006+
nodeInfo.getLastHealthUpdate() < nodeResponse.getLastHealthUpdate())) {
10061007
subcluster = entry.getKey();
10071008
nodeInfo = nodeResponse;
10081009
}
@@ -1137,6 +1138,7 @@ public AppState getAppState(HttpServletRequest hsr, String appId)
11371138
}
11381139
} catch (YarnException | IllegalArgumentException e) {
11391140
LOG.error("getHomeSubClusterInfoByAppId error, applicationId = {}.", appId, e);
1141+
return null;
11401142
}
11411143
return new AppState();
11421144
}
@@ -1385,8 +1387,8 @@ public ActivitiesInfo getActivities(HttpServletRequest hsr, String nodeId,
13851387
String groupBy) {
13861388
try {
13871389
// Check the parameters to ensure that the parameters are not empty
1388-
// Validate.checkNotNullAndNotEmpty(nodeId, "nodeId");
1389-
// Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");
1390+
Validate.checkNotNullAndNotEmpty(nodeId, "nodeId");
1391+
Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");
13901392

13911393
// Query SubClusterInfo according to id,
13921394
// if the nodeId cannot get SubClusterInfo, an exception will be thrown directly.
@@ -3356,11 +3358,22 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
33563358
} catch (Exception e) {
33573359
LOG.error("SubCluster {} failed to call {} method.",
33583360
info.getSubClusterId(), request.getMethodName(), e);
3361+
Throwable cause = e.getCause();
3362+
if (cause instanceof YarnException) {
3363+
return new SubClusterResult<>(info, null, (YarnException) cause);
3364+
}
3365+
if (cause instanceof IllegalArgumentException) {
3366+
return new SubClusterResult<>(info, null, (IllegalArgumentException) cause);
3367+
}
3368+
if(cause instanceof ForbiddenException) {
3369+
return new SubClusterResult<>(info, null, (ForbiddenException) cause);
3370+
}
33593371
return new SubClusterResult<>(info, null, e);
33603372
}
33613373
});
33623374
}
33633375

3376+
Exception lastException = null;
33643377
for (int i = 0; i < clusterIds.size(); i++) {
33653378
SubClusterInfo subClusterInfo = null;
33663379
try {
@@ -3375,6 +3388,7 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
33753388

33763389
Exception exception = result.getException();
33773390
if (exception != null) {
3391+
lastException = exception;
33783392
throw exception;
33793393
}
33803394
} catch (Throwable e) {
@@ -3390,6 +3404,13 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
33903404
}
33913405
}
33923406

3407+
if (results.isEmpty() && lastException != null) {
3408+
Throwable cause = lastException.getCause();
3409+
if (cause != null) {
3410+
throw new YarnRuntimeException(cause.getMessage());
3411+
}
3412+
throw new YarnRuntimeException(lastException.getMessage());
3413+
}
33933414
return results;
33943415
}
33953416

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/TestRouter.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818
package org.apache.hadoop.yarn.server.router;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
22-
import static org.junit.Assert.fail;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.fail;
23+
import static org.mockito.Mockito.mock;
24+
import static org.mockito.Mockito.when;
2325

2426
import org.apache.hadoop.conf.Configuration;
2527
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
@@ -34,9 +36,7 @@
3436
import org.eclipse.jetty.servlet.FilterHolder;
3537
import org.eclipse.jetty.servlet.ServletHandler;
3638
import org.eclipse.jetty.webapp.WebAppContext;
37-
import org.junit.Assert;
38-
import org.junit.Test;
39-
import org.mockito.Mockito;
39+
import org.junit.jupiter.api.Test;
4040

4141
import javax.servlet.FilterChain;
4242
import javax.servlet.ServletException;
@@ -107,7 +107,7 @@ private void verifyServiceACLsRefresh(ServiceAuthorizationManager manager,
107107
for (Class<?> protocolClass : manager.getProtocolsWithAcls()) {
108108
AccessControlList accessList = manager.getProtocolsAcls(protocolClass);
109109
if (protocolClass == protocol) {
110-
Assert.assertEquals(accessList.getAclString(), aclString);
110+
assertEquals(accessList.getAclString(), aclString);
111111
}
112112
}
113113
}
@@ -149,42 +149,42 @@ public void testRouterSupportCrossOrigin() throws ServletException, IOException
149149
CrossOriginFilter filter = (CrossOriginFilter) holder.getFilter();
150150

151151
// 1. Simulate [example.com] for access
152-
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
153-
Mockito.when(mockReq.getHeader("Origin")).thenReturn("example.com");
154-
Mockito.when(mockReq.getHeader("Access-Control-Request-Method")).thenReturn("GET");
155-
Mockito.when(mockReq.getHeader("Access-Control-Request-Headers"))
152+
HttpServletRequest mockReq = mock(HttpServletRequest.class);
153+
when(mockReq.getHeader("Origin")).thenReturn("example.com");
154+
when(mockReq.getHeader("Access-Control-Request-Method")).thenReturn("GET");
155+
when(mockReq.getHeader("Access-Control-Request-Headers"))
156156
.thenReturn("X-Requested-With");
157157

158158
// Objects to verify interactions based on request
159159
HttpServletResponseForRouterTest mockRes = new HttpServletResponseForRouterTest();
160-
FilterChain mockChain = Mockito.mock(FilterChain.class);
160+
FilterChain mockChain = mock(FilterChain.class);
161161

162162
// Object under test
163163
filter.doFilter(mockReq, mockRes, mockChain);
164164

165165
// Why is 5, because when Filter passes,
166166
// CrossOriginFilter will set 5 values to Map
167-
Assert.assertEquals(5, mockRes.getHeaders().size());
167+
assertEquals(5, mockRes.getHeaders().size());
168168
String allowResult = mockRes.getHeader("Access-Control-Allow-Credentials");
169-
Assert.assertEquals("true", allowResult);
169+
assertEquals("true", allowResult);
170170

171171
// 2. Simulate [example.org] for access
172-
HttpServletRequest mockReq2 = Mockito.mock(HttpServletRequest.class);
173-
Mockito.when(mockReq2.getHeader("Origin")).thenReturn("example.org");
174-
Mockito.when(mockReq2.getHeader("Access-Control-Request-Method")).thenReturn("GET");
175-
Mockito.when(mockReq2.getHeader("Access-Control-Request-Headers"))
172+
HttpServletRequest mockReq2 = mock(HttpServletRequest.class);
173+
when(mockReq2.getHeader("Origin")).thenReturn("example.org");
174+
when(mockReq2.getHeader("Access-Control-Request-Method")).thenReturn("GET");
175+
when(mockReq2.getHeader("Access-Control-Request-Headers"))
176176
.thenReturn("X-Requested-With");
177177

178178
// Objects to verify interactions based on request
179179
HttpServletResponseForRouterTest mockRes2 = new HttpServletResponseForRouterTest();
180-
FilterChain mockChain2 = Mockito.mock(FilterChain.class);
180+
FilterChain mockChain2 = mock(FilterChain.class);
181181

182182
// Object under test
183183
filter.doFilter(mockReq2, mockRes2, mockChain2);
184184

185185
// Why is 0, because when the Filter fails,
186186
// CrossOriginFilter will not set any value
187-
Assert.assertEquals(0, mockRes2.getHeaders().size());
187+
assertEquals(0, mockRes2.getHeaders().size());
188188

189189
router.stop();
190190
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/TestRouterAuditLogger.java

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

1919
package org.apache.hadoop.yarn.server.router;
2020

21-
import static org.junit.Assert.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2223
import static org.mockito.Mockito.mock;
2324
import static org.mockito.Mockito.when;
2425

@@ -37,9 +38,8 @@
3738
import org.apache.hadoop.thirdparty.protobuf.ServiceException;
3839
import org.apache.hadoop.yarn.api.records.ApplicationId;
3940
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
40-
import org.junit.Assert;
41-
import org.junit.Before;
42-
import org.junit.Test;
41+
import org.junit.jupiter.api.BeforeEach;
42+
import org.junit.jupiter.api.Test;
4343

4444
import java.net.InetAddress;
4545
import java.net.InetSocketAddress;
@@ -56,7 +56,8 @@ public class TestRouterAuditLogger {
5656
private static final ApplicationId APPID = mock(ApplicationId.class);
5757
private static final SubClusterId SUBCLUSTERID = mock(SubClusterId.class);
5858

59-
@Before public void setUp() throws Exception {
59+
@BeforeEach
60+
public void setUp() throws Exception {
6061
when(APPID.toString()).thenReturn("app_1");
6162
when(SUBCLUSTERID.toString()).thenReturn("sc0");
6263
}
@@ -202,8 +203,8 @@ public TestProtos.EmptyResponseProto ping(
202203
throws ServiceException {
203204
// Ensure clientId is received
204205
byte[] clientId = Server.getClientId();
205-
Assert.assertNotNull(clientId);
206-
Assert.assertEquals(ClientId.BYTE_LENGTH, clientId.length);
206+
assertNotNull(clientId);
207+
assertEquals(ClientId.BYTE_LENGTH, clientId.length);
207208
// test with ip set
208209
testSuccessLogFormat(true);
209210
testFailureLogFormat(true);

0 commit comments

Comments
 (0)