Skip to content

Commit

Permalink
YARN-8900. Fix CheckStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Dec 28, 2022
1 parent d431c46 commit fbd1c91
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Expand Up @@ -2341,9 +2341,9 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
throw exception;
}
} catch (Throwable e) {
String msg = String.format("SubCluster %s failed to %s report.", subClusterInfo,
request.getMethodName());
LOG.error(msg, e);
String subClusterId = subClusterInfo != null ?
subClusterInfo.getSubClusterId().getId() : "UNKNOWN";
LOG.error("SubCluster {} failed to {} report.", subClusterId, request.getMethodName(), e);
throw new YarnRuntimeException(e.getCause().getMessage(), e);
}
}
Expand Down Expand Up @@ -2417,4 +2417,17 @@ public Map<SubClusterId, DefaultRequestInterceptorREST> getInterceptors() {
public void setAllowPartialResult(boolean allowPartialResult) {
this.allowPartialResult = allowPartialResult;
}

@VisibleForTesting
public Map<SubClusterInfo, NodesInfo> invokeConcurrentGetNodeLabel()
throws IOException, YarnException {
NodesInfo nodes = new NodesInfo();
Map<SubClusterId, SubClusterInfo> subClustersActive = getActiveSubclusters();
Class[] argsClasses = new Class[]{String.class};
Object[] args = new Object[]{null};
ClientMethod remoteMethod = new ClientMethod("getNodes", argsClasses, args);
Map<SubClusterInfo, NodesInfo> nodesMap =
invokeConcurrent(subClustersActive.values(), remoteMethod, NodesInfo.class);
return nodesMap;
}
}
Expand Up @@ -1485,4 +1485,32 @@ public void testCheckFederationInterceptorRESTClient() {
Assert.assertNotNull(interceptorREST.getClient());
Assert.assertEquals(webAppAddress, interceptorREST.getWebAppAddress());
}

@Test
public void testInvokeConcurrent() throws IOException, YarnException {

// We design such a test case, we call the interceptor's getNodes interface,
// this interface will generate the following test data
// subCluster0 Node 0
// subCluster1 Node 1
// subCluster2 Node 2
// subCluster3 Node 3
// We use the returned data to verify whether the subClusterId
// of the multi-thread call can match the node data
Map<SubClusterInfo, NodesInfo> subClusterInfoNodesInfoMap =
interceptor.invokeConcurrentGetNodeLabel();
Assert.assertNotNull(subClusterInfoNodesInfoMap);
Assert.assertEquals(4, subClusterInfoNodesInfoMap.size());

subClusterInfoNodesInfoMap.forEach((subClusterInfo, nodesInfo) -> {
String subClusterId = subClusterInfo.getSubClusterId().getId();
List<NodeInfo> nodeInfos = nodesInfo.getNodes();
Assert.assertNotNull(nodeInfos);
Assert.assertEquals(1, nodeInfos.size());

String expectNodeId = "Node " + subClusterId;
String nodeId = nodeInfos.get(0).getNodeId();
Assert.assertEquals(expectNodeId, nodeId);
});
}
}

0 comments on commit fbd1c91

Please sign in to comment.