|
@@ -24,6 +24,7 @@ import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.fs.AbstractFileSystem;
|
|
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
|
|
|
import org.apache.hadoop.hdfs.*;
|
|
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
|
@@ -367,6 +368,37 @@ public class TestDelegationTokensWithHA {
|
|
|
token.cancel(conf);
|
|
|
}
|
|
|
|
|
|
+ @Test(timeout = 300000)
|
|
|
+ public void testCancelAndUpdateDelegationTokens() throws Exception {
|
|
|
+ // Create UGI with token1
|
|
|
+ String user = UserGroupInformation.getCurrentUser().getShortUserName();
|
|
|
+ UserGroupInformation ugi1 = UserGroupInformation.createRemoteUser(user);
|
|
|
+
|
|
|
+ ugi1.doAs(new PrivilegedExceptionAction<Void>() {
|
|
|
+ public Void run() throws Exception {
|
|
|
+ final Token<DelegationTokenIdentifier> token1 =
|
|
|
+ getDelegationToken(fs, "JobTracker");
|
|
|
+ UserGroupInformation.getCurrentUser()
|
|
|
+ .addToken(token1.getService(), token1);
|
|
|
+
|
|
|
+ FileSystem fs1 = HATestUtil.configureFailoverFs(cluster, conf);
|
|
|
+
|
|
|
+ // Cancel token1
|
|
|
+ doRenewOrCancel(token1, conf, TokenTestAction.CANCEL);
|
|
|
+
|
|
|
+ // Update UGI with token2
|
|
|
+ final Token<DelegationTokenIdentifier> token2 =
|
|
|
+ getDelegationToken(fs, "JobTracker");
|
|
|
+ UserGroupInformation.getCurrentUser()
|
|
|
+ .addToken(token2.getService(), token2);
|
|
|
+
|
|
|
+ // Check whether token2 works
|
|
|
+ fs1.listFiles(new Path("/"), false);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private Token<DelegationTokenIdentifier> getDelegationToken(FileSystem fs,
|
|
|
String renewer) throws IOException {
|