|
@@ -67,6 +67,7 @@ public class TestRMDelegationTokens {
|
|
conf.set(YarnConfiguration.RM_SCHEDULER, FairScheduler.class.getName());
|
|
conf.set(YarnConfiguration.RM_SCHEDULER, FairScheduler.class.getName());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Test the DT mast key in the state-store when the mast key is being rolled.
|
|
@Test(timeout = 15000)
|
|
@Test(timeout = 15000)
|
|
public void testRMDTMasterKeyStateOnRollingMasterKey() throws Exception {
|
|
public void testRMDTMasterKeyStateOnRollingMasterKey() throws Exception {
|
|
MemoryRMStateStore memStore = new MemoryRMStateStore();
|
|
MemoryRMStateStore memStore = new MemoryRMStateStore();
|
|
@@ -92,9 +93,6 @@ public class TestRMDelegationTokens {
|
|
Set<DelegationKey> expiringKeys = new HashSet<DelegationKey>();
|
|
Set<DelegationKey> expiringKeys = new HashSet<DelegationKey>();
|
|
expiringKeys.addAll(dtSecretManager.getAllMasterKeys());
|
|
expiringKeys.addAll(dtSecretManager.getAllMasterKeys());
|
|
|
|
|
|
- // record the current key
|
|
|
|
- DelegationKey oldCurrentKey =
|
|
|
|
- ((TestRMDelegationTokenSecretManager) dtSecretManager).getCurrentKey();
|
|
|
|
|
|
|
|
// request to generate a RMDelegationToken
|
|
// request to generate a RMDelegationToken
|
|
GetDelegationTokenRequest request = mock(GetDelegationTokenRequest.class);
|
|
GetDelegationTokenRequest request = mock(GetDelegationTokenRequest.class);
|
|
@@ -107,29 +105,26 @@ public class TestRMDelegationTokens {
|
|
ConverterUtils.convertFromYarn(delegationToken, (Text) null);
|
|
ConverterUtils.convertFromYarn(delegationToken, (Text) null);
|
|
RMDelegationTokenIdentifier dtId1 = token1.decodeIdentifier();
|
|
RMDelegationTokenIdentifier dtId1 = token1.decodeIdentifier();
|
|
|
|
|
|
- // wait for the first rollMasterKey
|
|
|
|
|
|
+ // For all keys that still remain in memory, we should have them stored
|
|
|
|
+ // in state-store also.
|
|
while (((TestRMDelegationTokenSecretManager) dtSecretManager).numUpdatedKeys
|
|
while (((TestRMDelegationTokenSecretManager) dtSecretManager).numUpdatedKeys
|
|
- .get() < 1){
|
|
|
|
- Thread.sleep(200);
|
|
|
|
|
|
+ .get() < 3) {
|
|
|
|
+ ((TestRMDelegationTokenSecretManager) dtSecretManager)
|
|
|
|
+ .checkCurrentKeyInStateStore(rmDTMasterKeyState);
|
|
|
|
+ Thread.sleep(100);
|
|
}
|
|
}
|
|
|
|
|
|
- // assert old-current-key and new-current-key exist
|
|
|
|
- Assert.assertTrue(rmDTMasterKeyState.contains(oldCurrentKey));
|
|
|
|
- DelegationKey newCurrentKey =
|
|
|
|
- ((TestRMDelegationTokenSecretManager) dtSecretManager).getCurrentKey();
|
|
|
|
- Assert.assertTrue(rmDTMasterKeyState.contains(newCurrentKey));
|
|
|
|
-
|
|
|
|
- // wait for token to expire
|
|
|
|
|
|
+ // wait for token to expire and remove from state-store
|
|
// rollMasterKey is called every 1 second.
|
|
// rollMasterKey is called every 1 second.
|
|
- while (((TestRMDelegationTokenSecretManager) dtSecretManager).numUpdatedKeys
|
|
|
|
- .get() < 6) {
|
|
|
|
- Thread.sleep(200);
|
|
|
|
|
|
+ int count = 0;
|
|
|
|
+ while (rmDTState.containsKey(dtId1) && count < 100) {
|
|
|
|
+ Thread.sleep(100);
|
|
|
|
+ count++;
|
|
}
|
|
}
|
|
-
|
|
|
|
- Assert.assertFalse(rmDTState.containsKey(dtId1));
|
|
|
|
rm1.stop();
|
|
rm1.stop();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Test all expired keys are removed from state-store.
|
|
@Test(timeout = 15000)
|
|
@Test(timeout = 15000)
|
|
public void testRemoveExpiredMasterKeyInRMStateStore() throws Exception {
|
|
public void testRemoveExpiredMasterKeyInRMStateStore() throws Exception {
|
|
MemoryRMStateStore memStore = new MemoryRMStateStore();
|
|
MemoryRMStateStore memStore = new MemoryRMStateStore();
|
|
@@ -205,10 +200,13 @@ public class TestRMDelegationTokens {
|
|
numUpdatedKeys.incrementAndGet();
|
|
numUpdatedKeys.incrementAndGet();
|
|
}
|
|
}
|
|
|
|
|
|
- public DelegationKey getCurrentKey() {
|
|
|
|
|
|
+ public synchronized DelegationKey checkCurrentKeyInStateStore(
|
|
|
|
+ Set<DelegationKey> rmDTMasterKeyState) {
|
|
for (int keyId : allKeys.keySet()) {
|
|
for (int keyId : allKeys.keySet()) {
|
|
if (keyId == currentId) {
|
|
if (keyId == currentId) {
|
|
- return allKeys.get(keyId);
|
|
|
|
|
|
+ DelegationKey currentKey = allKeys.get(keyId);
|
|
|
|
+ Assert.assertTrue(rmDTMasterKeyState.contains(currentKey));
|
|
|
|
+ return currentKey;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|