org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem#getDelegationToken ( )源码实例Demo

下面列出了org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem#getDelegationToken ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hadoop   文件: TestTokenCache.java
@SuppressWarnings("deprecation")
@Test
public void testGetTokensForNamenodes() throws IOException,
    URISyntaxException {
  Path TEST_ROOT_DIR =
      new Path(System.getProperty("test.build.data", "test/build/data"));
  // ick, but need fq path minus file:/
  String binaryTokenFile =
      FileSystem.getLocal(conf)
        .makeQualified(new Path(TEST_ROOT_DIR, "tokenFile")).toUri()
        .getPath();

  MockFileSystem fs1 = createFileSystemForServiceName("service1");
  Credentials creds = new Credentials();
  Token<?> token1 = fs1.getDelegationToken(renewer);
  creds.addToken(token1.getService(), token1);
  // wait to set, else the obtain tokens call above will fail with FNF
  conf.set(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY, binaryTokenFile);
  creds.writeTokenStorageFile(new Path(binaryTokenFile), conf);
  TokenCache.obtainTokensForNamenodesInternal(fs1, creds, conf);
  String fs_addr = fs1.getCanonicalServiceName();
  Token<?> nnt = TokenCache.getDelegationToken(creds, fs_addr);
  assertNotNull("Token for nn is null", nnt);
}
 
源代码2 项目: big-c   文件: TestTokenCache.java
@SuppressWarnings("deprecation")
@Test
public void testGetTokensForNamenodes() throws IOException,
    URISyntaxException {
  Path TEST_ROOT_DIR =
      new Path(System.getProperty("test.build.data", "test/build/data"));
  // ick, but need fq path minus file:/
  String binaryTokenFile =
      FileSystem.getLocal(conf)
        .makeQualified(new Path(TEST_ROOT_DIR, "tokenFile")).toUri()
        .getPath();

  MockFileSystem fs1 = createFileSystemForServiceName("service1");
  Credentials creds = new Credentials();
  Token<?> token1 = fs1.getDelegationToken(renewer);
  creds.addToken(token1.getService(), token1);
  // wait to set, else the obtain tokens call above will fail with FNF
  conf.set(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY, binaryTokenFile);
  creds.writeTokenStorageFile(new Path(binaryTokenFile), conf);
  TokenCache.obtainTokensForNamenodesInternal(fs1, creds, conf);
  String fs_addr = fs1.getCanonicalServiceName();
  Token<?> nnt = TokenCache.getDelegationToken(creds, fs_addr);
  assertNotNull("Token for nn is null", nnt);
}
 
源代码3 项目: incubator-tez   文件: TestTokenCache.java
@Test
@SuppressWarnings("deprecation")
public void testBinaryCredentials() throws Exception {
  String binaryTokenFile = null;
  try {
    Path TEST_ROOT_DIR = new Path("target");
    binaryTokenFile = FileSystem.getLocal(conf).makeQualified(
      new Path(TEST_ROOT_DIR, "tokenFile")).toUri().getPath();

    MockFileSystem fs1 = createFileSystemForServiceName("service1");
    MockFileSystem fs2 = createFileSystemForServiceName("service2");
    MockFileSystem fs3 = createFileSystemForServiceName("service3");

    // get the tokens for fs1 & fs2 and write out to binary creds file
    Credentials creds = new Credentials();
    Token<?> token1 = fs1.getDelegationToken(renewer);
    Token<?> token2 = fs2.getDelegationToken(renewer);
    creds.addToken(token1.getService(), token1);
    creds.addToken(token2.getService(), token2);
    creds.writeTokenStorageFile(new Path(binaryTokenFile), conf);


    Credentials newCreds = new Credentials();
    TokenCache.mergeBinaryTokens(newCreds, conf, binaryTokenFile);

    Assert.assertTrue(newCreds.getAllTokens().size() > 0);
    checkTokens(creds, newCreds);
  } finally {
    if (binaryTokenFile != null) {
      try {
        FileSystem.getLocal(conf).delete(new Path(binaryTokenFile));
      } catch (IOException e) {
        // Ignore
      }
    }
  }
}
 
源代码4 项目: tez   文件: TestTokenCache.java
@Test(timeout = 5000)
@SuppressWarnings("deprecation")
public void testBinaryCredentials() throws Exception {
  String binaryTokenFile = null;
  try {
    Path TEST_ROOT_DIR = new Path("target");
    binaryTokenFile = FileSystem.getLocal(conf).makeQualified(
      new Path(TEST_ROOT_DIR, "tokenFile")).toUri().getPath();

    MockFileSystem fs1 = createFileSystemForServiceName("service1");
    MockFileSystem fs2 = createFileSystemForServiceName("service2");

    // get the tokens for fs1 & fs2 and write out to binary creds file
    Credentials creds = new Credentials();
    Token<?> token1 = fs1.getDelegationToken(renewer);
    Token<?> token2 = fs2.getDelegationToken(renewer);
    creds.addToken(token1.getService(), token1);
    creds.addToken(token2.getService(), token2);
    creds.writeTokenStorageFile(new Path(binaryTokenFile), conf);


    Credentials newCreds = new Credentials();
    TokenCache.mergeBinaryTokens(newCreds, conf, binaryTokenFile);

    Assert.assertTrue(newCreds.getAllTokens().size() > 0);
    checkTokens(creds, newCreds);
  } finally {
    if (binaryTokenFile != null) {
      try {
        FileSystem.getLocal(conf).delete(new Path(binaryTokenFile));
      } catch (IOException e) {
        // Ignore
      }
    }
  }
}