Skip to content

Commit 8249dc6

Browse files
author
slfan1989
committed
YARN-11218. Add Junit Test.
1 parent 8d7f600 commit 8249dc6

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestsInfo;
136136
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateResponseInfo;
137137
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDeleteResponseInfo;
138+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ActivitiesInfo;
139+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts;
140+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeAllocationInfo;
138141
import org.apache.hadoop.yarn.server.router.RouterServerUtil;
139142
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.PartitionInfo;
140143
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.RMQueueAclInfo;
@@ -1206,4 +1209,28 @@ public RMQueueAclInfo checkUserAccessToQueue(
12061209
return new RMQueueAclInfo(true, user.getUserName(), "");
12071210
}
12081211
}
1212+
1213+
@Override
1214+
public ActivitiesInfo getActivities(HttpServletRequest hsr, String nodeId, String groupBy) {
1215+
if (!EnumUtils.isValidEnum(RMWSConsts.ActivitiesGroupBy.class, groupBy.toUpperCase())) {
1216+
String errMesasge = "Got invalid groupBy: " + groupBy + ", valid groupBy types: "
1217+
+ Arrays.asList(RMWSConsts.ActivitiesGroupBy.values());
1218+
throw new IllegalArgumentException(errMesasge);
1219+
}
1220+
1221+
SubClusterId subClusterId = getSubClusterId();
1222+
ActivitiesInfo activitiesInfo = mock(ActivitiesInfo.class);
1223+
Mockito.when(activitiesInfo.getNodeId()).thenReturn(nodeId);
1224+
Mockito.when(activitiesInfo.getTimestamp()).thenReturn(1673081972L);
1225+
Mockito.when(activitiesInfo.getDiagnostic()).thenReturn("Diagnostic:" + subClusterId.getId());
1226+
1227+
List<NodeAllocationInfo> allocationInfos = new ArrayList<>();
1228+
NodeAllocationInfo nodeAllocationInfo = mock(NodeAllocationInfo.class);
1229+
Mockito.when(nodeAllocationInfo.getPartition()).thenReturn("p" + subClusterId.getId());
1230+
Mockito.when(nodeAllocationInfo.getFinalAllocationState()).thenReturn("ALLOCATED");
1231+
1232+
allocationInfos.add(nodeAllocationInfo);
1233+
Mockito.when(activitiesInfo.getAllocations()).thenReturn(allocationInfos);
1234+
return activitiesInfo;
1235+
}
12091236
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javax.ws.rs.core.Response;
3434
import javax.ws.rs.core.Response.Status;
3535

36+
import org.apache.commons.lang3.StringUtils;
3637
import org.apache.hadoop.security.authorize.AuthorizationException;
3738
import org.apache.hadoop.test.LambdaTestUtils;
3839
import org.apache.hadoop.conf.Configuration;
@@ -108,6 +109,8 @@
108109
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NewReservation;
109110
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateRequestInfo;
110111
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDeleteRequestInfo;
112+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ActivitiesInfo;
113+
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeAllocationInfo;
111114
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
112115
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
113116
import org.apache.hadoop.yarn.server.router.webapp.dao.FederationRMQueueAclInfo;
@@ -1685,4 +1688,43 @@ public void testCancelDelegationToken() throws Exception {
16851688
Assert.assertNotNull(cancelResponse);
16861689
Assert.assertEquals(response.getStatus(), Status.OK.getStatusCode());
16871690
}
1691+
1692+
@Test
1693+
public void testGetActivitiesNormal() {
1694+
ActivitiesInfo activitiesInfo = interceptor.getActivities(null, "1", "DIAGNOSTIC");
1695+
Assert.assertNotNull(activitiesInfo);
1696+
1697+
String nodeId = activitiesInfo.getNodeId();
1698+
Assert.assertNotNull(nodeId);
1699+
Assert.assertEquals("1", nodeId);
1700+
1701+
String diagnostic = activitiesInfo.getDiagnostic();
1702+
Assert.assertNotNull(diagnostic);
1703+
Assert.assertTrue(StringUtils.contains(diagnostic, "Diagnostic"));
1704+
1705+
long timestamp = activitiesInfo.getTimestamp();
1706+
Assert.assertEquals(1673081972L, timestamp);
1707+
1708+
List<NodeAllocationInfo> allocationInfos = activitiesInfo.getAllocations();
1709+
Assert.assertNotNull(allocationInfos);
1710+
Assert.assertEquals(1, allocationInfos.size());
1711+
}
1712+
1713+
@Test
1714+
public void testGetActivitiesError() throws Exception {
1715+
// nodeId is empty
1716+
LambdaTestUtils.intercept(IllegalArgumentException.class,
1717+
"'nodeId' must not be empty.",
1718+
() -> interceptor.getActivities(null, "", "DIAGNOSTIC"));
1719+
1720+
// groupBy is empty
1721+
LambdaTestUtils.intercept(IllegalArgumentException.class,
1722+
"'groupBy' must not be empty.",
1723+
() -> interceptor.getActivities(null, "1", ""));
1724+
1725+
// groupBy value is wrong
1726+
LambdaTestUtils.intercept(IllegalArgumentException.class,
1727+
"Got invalid groupBy: TEST1, valid groupBy types: [DIAGNOSTIC]",
1728+
() -> interceptor.getActivities(null, "1", "TEST1"));
1729+
}
16881730
}

0 commit comments

Comments
 (0)