HDFS-14374. Expose total number of delegation tokens in AbstractDelegationTokenSecretManager. Contributed by CR Hota.

This commit is contained in:
Inigo Goiri 2019-04-22 13:31:20 -07:00
parent 174b7d3126
commit fb1c549139
2 changed files with 31 additions and 1 deletions

View File

@ -146,6 +146,13 @@ public synchronized void reset() {
currentTokens.clear();
}
/**
* Total count of active delegation tokens.
*/
public long getCurrentTokensSize() {
return currentTokens.size();
}
/**
* Add a previously used master key to cache (when NN restarts),
* should be called before activate().

View File

@ -259,6 +259,29 @@ public void testGetUserWithOwnerAndReal() {
ugi.getRealUser().getAuthenticationMethod());
}
@Test
public void testDelegationTokenCount() throws Exception {
final TestDelegationTokenSecretManager dtSecretManager =
new TestDelegationTokenSecretManager(24*60*60*1000,
3*1000, 1*1000, 3600000);
try {
dtSecretManager.startThreads();
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 0);
final Token<TestDelegationTokenIdentifier> token1 =
generateDelegationToken(dtSecretManager, "SomeUser", "JobTracker");
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 1);
final Token<TestDelegationTokenIdentifier> token2 =
generateDelegationToken(dtSecretManager, "SomeUser", "JobTracker");
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 2);
dtSecretManager.cancelToken(token1, "JobTracker");
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 1);
dtSecretManager.cancelToken(token2, "JobTracker");
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 0);
} finally {
dtSecretManager.stopThreads();
}
}
@Test
public void testDelegationTokenSecretManager() throws Exception {
final TestDelegationTokenSecretManager dtSecretManager =