Skip to content

Commit 966b0a7

Browse files
author
slfan1989
committed
YARN-11158. Fix CheckStyle.
1 parent 09dcc8c commit 966b0a7

File tree

2 files changed

+95
-9
lines changed

2 files changed

+95
-9
lines changed

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

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,20 @@ public void getRMNodeLabelsFailed() {
519519
metrics.incrGetRMNodeLabelsFailedRetrieved();
520520
}
521521

522-
public void getCheckUserAccessToQueueRetrieved() {
523-
LOG.info("Mocked: failed checkUserAccessToQueueRetrieved call");
522+
public void getCheckUserAccessToQueueFailed() {
523+
LOG.info("Mocked: failed checkUserAccessToQueue call");
524524
metrics.incrCheckUserAccessToQueueFailedRetrieved();
525525
}
526+
527+
public void getDelegationTokenFailed() {
528+
LOG.info("Mocked: failed getDelegationToken call");
529+
metrics.incrGetDelegationTokenFailedRetrieved();
530+
}
531+
532+
public void getRenewDelegationTokenFailed() {
533+
LOG.info("Mocked: failed renewDelegationToken call");
534+
metrics.incrRenewDelegationTokenFailedRetrieved();
535+
}
526536
}
527537

528538
// Records successes for all calls
@@ -743,6 +753,16 @@ public void getCheckUserAccessToQueueRetrieved(long duration) {
743753
LOG.info("Mocked: successful CheckUserAccessToQueue call with duration {}", duration);
744754
metrics.succeededCheckUserAccessToQueueRetrieved(duration);
745755
}
756+
757+
public void getGetDelegationTokenRetrieved(long duration) {
758+
LOG.info("Mocked: successful GetDelegationToken call with duration {}", duration);
759+
metrics.succeededGetDelegationTokenRetrieved(duration);
760+
}
761+
762+
public void getRenewDelegationTokenRetrieved(long duration) {
763+
LOG.info("Mocked: successful RenewDelegationToken call with duration {}", duration);
764+
metrics.succeededRenewDelegationTokenRetrieved(duration);
765+
}
746766
}
747767

748768
@Test
@@ -1510,7 +1530,7 @@ public void testGetRMNodeLabelsRetrievedFailed() {
15101530
}
15111531

15121532
@Test
1513-
public void testCheckUserAccessToQueueRetrievedRetrieved() {
1533+
public void testCheckUserAccessToQueueRetrieved() {
15141534
long totalGoodBefore = metrics.getNumSucceededCheckUserAccessToQueueRetrieved();
15151535
goodSubCluster.getCheckUserAccessToQueueRetrieved(150);
15161536
Assert.assertEquals(totalGoodBefore + 1,
@@ -1527,8 +1547,54 @@ public void testCheckUserAccessToQueueRetrievedRetrieved() {
15271547
@Test
15281548
public void testCheckUserAccessToQueueRetrievedFailed() {
15291549
long totalBadBefore = metrics.getCheckUserAccessToQueueFailedRetrieved();
1530-
badSubCluster.getCheckUserAccessToQueueRetrieved();
1550+
badSubCluster.getCheckUserAccessToQueueFailed();
15311551
Assert.assertEquals(totalBadBefore + 1,
15321552
metrics.getCheckUserAccessToQueueFailedRetrieved());
15331553
}
1554+
1555+
@Test
1556+
public void testGetDelegationTokenRetrieved() {
1557+
long totalGoodBefore = metrics.getNumSucceededGetDelegationTokenRetrieved();
1558+
goodSubCluster.getGetDelegationTokenRetrieved(150);
1559+
Assert.assertEquals(totalGoodBefore + 1,
1560+
metrics.getNumSucceededGetDelegationTokenRetrieved());
1561+
Assert.assertEquals(150,
1562+
metrics.getLatencySucceededGetDelegationTokenRetrieved(), ASSERT_DOUBLE_DELTA);
1563+
goodSubCluster.getGetDelegationTokenRetrieved(300);
1564+
Assert.assertEquals(totalGoodBefore + 2,
1565+
metrics.getNumSucceededGetDelegationTokenRetrieved());
1566+
Assert.assertEquals(225,
1567+
metrics.getLatencySucceededGetDelegationTokenRetrieved(), ASSERT_DOUBLE_DELTA);
1568+
}
1569+
1570+
@Test
1571+
public void testGetDelegationTokenRetrievedFailed() {
1572+
long totalBadBefore = metrics.getDelegationTokenFailedRetrieved();
1573+
badSubCluster.getDelegationTokenFailed();
1574+
Assert.assertEquals(totalBadBefore + 1,
1575+
metrics.getDelegationTokenFailedRetrieved());
1576+
}
1577+
1578+
@Test
1579+
public void testRenewDelegationTokenRetrieved() {
1580+
long totalGoodBefore = metrics.getNumSucceededRenewDelegationTokenRetrieved();
1581+
goodSubCluster.getRenewDelegationTokenRetrieved(150);
1582+
Assert.assertEquals(totalGoodBefore + 1,
1583+
metrics.getNumSucceededRenewDelegationTokenRetrieved());
1584+
Assert.assertEquals(150,
1585+
metrics.getLatencySucceededRenewDelegationTokenRetrieved(), ASSERT_DOUBLE_DELTA);
1586+
goodSubCluster.getRenewDelegationTokenRetrieved(300);
1587+
Assert.assertEquals(totalGoodBefore + 2,
1588+
metrics.getNumSucceededRenewDelegationTokenRetrieved());
1589+
Assert.assertEquals(225,
1590+
metrics.getLatencySucceededRenewDelegationTokenRetrieved(), ASSERT_DOUBLE_DELTA);
1591+
}
1592+
1593+
@Test
1594+
public void testRenewDelegationTokenRetrievedFailed() {
1595+
long totalBadBefore = metrics.getRenewDelegationTokenFailedRetrieved();
1596+
badSubCluster.getRenewDelegationTokenFailed();
1597+
Assert.assertEquals(totalBadBefore + 1,
1598+
metrics.getRenewDelegationTokenFailedRetrieved());
1599+
}
15341600
}

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,8 +1584,9 @@ public void testGetDelegationToken() throws IOException, YarnException {
15841584
// RM_DELEGATION_TOKEN
15851585
//
15861586
// 2. We maintain the compatibility with RMDelegationTokenIdentifier,
1587-
// we can serialize the token into RMDelegationTokenIdentifier,
1588-
// we can get the issueDate, and compare the data in the StateStore,
1587+
// we can serialize the token into RMDelegationTokenIdentifier.
1588+
//
1589+
// 3. We can get the issueDate, and compare the data in the StateStore,
15891590
// the data should be consistent.
15901591

15911592
// Step1. We apply for DelegationToken for renewer1
@@ -1616,7 +1617,12 @@ public void testGetDelegationToken() throws IOException, YarnException {
16161617
Assert.assertEquals((issueDate + tokenMaxLifetime), maxDate);
16171618

16181619
RouterRMDTSecretManagerState managerState = stateStore.getRouterRMSecretManagerState();
1620+
Assert.assertNotNull(managerState);
1621+
16191622
Map<RMDelegationTokenIdentifier, Long> delegationTokenState = managerState.getTokenState();
1623+
Assert.assertNotNull(delegationTokenState);
1624+
Assert.assertTrue(delegationTokenState.containsKey(rMDelegationTokenIdentifier));
1625+
16201626
long tokenRenewInterval = this.getConf().getLong(
16211627
YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_KEY,
16221628
YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT);
@@ -1626,35 +1632,49 @@ public void testGetDelegationToken() throws IOException, YarnException {
16261632

16271633
@Test
16281634
public void testRenewDelegationToken() throws IOException, YarnException {
1629-
16301635
// We design such a unit test to check
16311636
// that the execution of the GetDelegationToken method is as expected
16321637
// 1. Call GetDelegationToken to apply for delegationToken.
16331638
// 2. Call renewDelegationToken to refresh delegationToken.
16341639
// By looking at the code of AbstractDelegationTokenSecretManager#renewToken,
16351640
// we know that renewTime is calculated as Math.min(id.getMaxDate(), now + tokenRenewInterval)
1636-
// so renewTime will be less than or equal to maxDate
1641+
// so renewTime will be less than or equal to maxDate.
1642+
// 3. We will compare whether the expirationTime returned to the
1643+
// client is consistent with the renewDate in the stateStore.
16371644

1645+
// Step1. Call GetDelegationToken to apply for delegationToken.
16381646
GetDelegationTokenRequest request = mock(GetDelegationTokenRequest.class);
16391647
when(request.getRenewer()).thenReturn("renewer2");
16401648
GetDelegationTokenResponse response = interceptor.getDelegationToken(request);
16411649
Assert.assertNotNull(response);
16421650
Token delegationToken = response.getRMDelegationToken();
16431651

1644-
// Step2. Serialize the returned Token as RMDelegationTokenIdentifier.
16451652
org.apache.hadoop.security.token.Token<RMDelegationTokenIdentifier> token =
16461653
ConverterUtils.convertFromYarn(delegationToken, (Text) null);
16471654
RMDelegationTokenIdentifier rMDelegationTokenIdentifier = token.decodeIdentifier();
16481655
String renewer = rMDelegationTokenIdentifier.getRenewer().toString();
16491656
long maxDate = rMDelegationTokenIdentifier.getMaxDate();
16501657
Assert.assertEquals("renewer2", renewer);
16511658

1659+
// Step2. Call renewDelegationToken to refresh delegationToken.
16521660
RenewDelegationTokenRequest renewRequest = Records.newRecord(RenewDelegationTokenRequest.class);
16531661
renewRequest.setDelegationToken(delegationToken);
16541662
RenewDelegationTokenResponse renewResponse = interceptor.renewDelegationToken(renewRequest);
16551663
Assert.assertNotNull(renewResponse);
16561664

16571665
long expDate = renewResponse.getNextExpirationTime();
16581666
Assert.assertTrue(expDate <= maxDate);
1667+
1668+
// Step3. Compare whether the expirationTime returned to
1669+
// the client is consistent with the renewDate in the stateStore
1670+
RouterRMDTSecretManagerState managerState = stateStore.getRouterRMSecretManagerState();
1671+
Map<RMDelegationTokenIdentifier, Long> delegationTokenState = managerState.getTokenState();
1672+
Assert.assertNotNull(delegationTokenState);
1673+
Assert.assertTrue(delegationTokenState.containsKey(rMDelegationTokenIdentifier));
1674+
long renewDate = delegationTokenState.get(rMDelegationTokenIdentifier);
1675+
Assert.assertEquals(expDate, renewDate);
16591676
}
1677+
1678+
1679+
16601680
}

0 commit comments

Comments
 (0)