|
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.security;
|
|
|
|
|
|
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
@@ -41,6 +42,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods;
|
|
@@ -153,7 +155,27 @@ public class TestDelegationToken {
|
|
|
// PASS
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDelegationTokenMetrics() throws Exception {
|
|
|
+ FSNamesystem namesystem = cluster.getNamesystem();
|
|
|
+ // should start with no token
|
|
|
+ assertEquals(0, namesystem.getCurrentTokensCount());
|
|
|
+
|
|
|
+ // get token
|
|
|
+ Token<DelegationTokenIdentifier> token = generateDelegationToken(
|
|
|
+ "SomeUser", "JobTracker");
|
|
|
+ assertEquals(1, namesystem.getCurrentTokensCount());
|
|
|
+
|
|
|
+ // Renew token shouldn't change the count of tokens
|
|
|
+ dtSecretManager.renewToken(token, "JobTracker");
|
|
|
+ assertEquals(1, namesystem.getCurrentTokensCount());
|
|
|
+
|
|
|
+ // Cancel token should remove the token from memory
|
|
|
+ dtSecretManager.cancelToken(token, "JobTracker");
|
|
|
+ assertEquals(0, namesystem.getCurrentTokensCount());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAddDelegationTokensDFSApi() throws Exception {
|
|
|
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("JobTracker");
|