DelegationTokenFetcher { @VisibleForTesting static void saveDelegationToken(Configuration conf, FileSystem fs, final String renewer, final Path tokenFile) throws IOException { Token<?> token = fs.getDelegationToken(renewer); if (null != token) { Credentials cred = new Credentials(); cred.addToken(token.getService(), token); cred.writeTokenStorageFile(tokenFile, conf); if (LOG.isDebugEnabled()) { LOG.debug("Fetched token " + fs.getUri() + " for " + token.getService() + " into " + tokenFile); } } else { System.err.println("ERROR: Failed to fetch token from " + fs.getUri()); } }  static void main(final String[] args);  }
@Test(expected = IOException.class) public void testTokenFetchFail() throws Exception { WebHdfsFileSystem fs = mock(WebHdfsFileSystem.class); doThrow(new IOException()).when(fs).getDelegationToken(anyString()); Path p = new Path(f.getRoot().getAbsolutePath(), tokenFile); DelegationTokenFetcher.saveDelegationToken(conf, fs, null, p); }