TokenCache { static void obtainTokensForNamenodesInternal(Credentials credentials, Path[] ps, Configuration conf) throws IOException { Set<FileSystem> fsSet = new HashSet<FileSystem>(); for(Path p: ps) { fsSet.add(p.getFileSystem(conf)); } String masterPrincipal = Master.getMasterPrincipal(conf); for (FileSystem fs : fsSet) { obtainTokensForNamenodesInternal(fs, credentials, conf, masterPrincipal); } }  static byte[] getSecretKey(Credentials credentials, Text alias); static void obtainTokensForNamenodes(Credentials credentials,
      Path[] ps, Configuration conf); static void cleanUpTokenReferral(Configuration conf); @InterfaceAudience.Private @Deprecated static Credentials loadTokens(String jobTokenFile, JobConf conf); @InterfaceAudience.Private @Deprecated static Credentials loadTokens(String jobTokenFile, Configuration conf); @InterfaceAudience.Private static void setJobToken(Token<? extends TokenIdentifier> t, 
      Credentials credentials); @SuppressWarnings("unchecked") @InterfaceAudience.Private static Token<JobTokenIdentifier> getJobToken(Credentials credentials); @InterfaceAudience.Private static void setShuffleSecretKey(byte[] key, Credentials credentials); @InterfaceAudience.Private static byte[] getShuffleSecretKey(Credentials credentials); @InterfaceAudience.Private static void setEncryptedSpillKey(byte[] key, Credentials credentials); @InterfaceAudience.Private static byte[] getEncryptedSpillKey(Credentials credentials); @InterfaceAudience.Private @Deprecated static Token<?> getDelegationToken(
          Credentials credentials, String namenode); @InterfaceAudience.Private
  static final String JOB_TOKEN_HDFS_FILE; @InterfaceAudience.Private
  static final String JOB_TOKENS_FILENAME; }
@Test public void testObtainTokens() throws Exception { Credentials credentials = new Credentials(); FileSystem fs = mock(FileSystem.class); TokenCache.obtainTokensForNamenodesInternal(fs, credentials, conf, renewer); verify(fs).addDelegationTokens(eq(renewer), eq(credentials)); }
@Test public void testSingleTokenFetch() throws Exception { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_PRINCIPAL, "mapred/host@REALM"); String renewer = Master.getMasterPrincipal(conf); Credentials credentials = new Credentials(); final MockFileSystem fs = new MockFileSystem(); final MockFileSystem mockFs = (MockFileSystem) fs.getRawFileSystem(); when(mockFs.getCanonicalServiceName()).thenReturn("host:0"); when(mockFs.getUri()).thenReturn(new URI("mockfs: Path mockPath = mock(Path.class); when(mockPath.getFileSystem(conf)).thenReturn(mockFs); Path[] paths = new Path[]{ mockPath, mockPath }; when(mockFs.addDelegationTokens("me", credentials)).thenReturn(null); TokenCache.obtainTokensForNamenodesInternal(credentials, paths, conf); verify(mockFs, times(1)).addDelegationTokens(renewer, credentials); }