@Test
public void testRenewTokenUsingTokenConfProvidedByApp() throws Exception{

  conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
      "kerberos");
  UserGroupInformation.setConfiguration(conf);
  MockRM rm = new TestSecurityMockRM(conf, null);
  rm.start();
  final MockNM nm1 =
      new MockNM("127.0.0.1:1234", 15120, rm.getResourceTrackerService());
  nm1.registerNode();
  // create a token
  Text userText1 = new Text("user1");
  DelegationTokenIdentifier dtId1 =
      new DelegationTokenIdentifier(userText1, new Text("renewer1"),
          userText1);
  final Token<DelegationTokenIdentifier> token1 =
      new Token<DelegationTokenIdentifier>(dtId1.getBytes(),
          "password1".getBytes(), dtId1.getKind(), new Text("service1"));
  Credentials credentials = new Credentials();
  credentials.addToken(userText1, token1);
  // create token conf for renewal
  Configuration appConf = new Configuration(false);
  appConf.set("dfs.nameservices", "mycluster1,mycluster2");
  appConf.set("dfs.namenode.rpc-address.mycluster2.nn1", "123.0.0.1");
  appConf.set("dfs.namenode.rpc-address.mycluster2.nn2", "123.0.0.2");
  appConf.set("dfs.ha.namenodes.mycluster2", "nn1,nn2");
  appConf.set("dfs.client.failover.proxy.provider.mycluster2", "provider");
  DataOutputBuffer dob = new DataOutputBuffer();
  appConf.write(dob);
  ByteBuffer tokenConf = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
  final int confSize = appConf.size();
  // submit app
  RMApp app = submitApp(rm, credentials, tokenConf);
  GenericTestUtils.waitFor(new Supplier<Boolean>() {
    public Boolean get() {
      DelegationTokenToRenew toRenew =
          rm.getRMContext().getDelegationTokenRenewer().getAllTokens()
              .get(token1);
      // check app conf size equals to original size and it does contain
      // the specific config we added.
      return toRenew != null && toRenew.conf != null
          && toRenew.conf.size() == confSize && toRenew.conf
          .get("dfs.namenode.rpc-address.mycluster2.nn1").equals("123.0.0.1");
    }
  }, 200, 10000);
}