@Test public void testRenewal() throws IOException, InterruptedException {
    DelegationTokenStore tokenStore = new MemoryTokenStore();
    // Have a long renewal to ensure that Thread.sleep does not overshoot the initial validity
    TokenStoreDelegationTokenSecretManager mgr = createTokenMgr(tokenStore, 3600, MetastoreConf.getTimeVar(
            conf, MetastoreConf.ConfVars.DELEGATION_TOKEN_GC_INTERVAL, TimeUnit.SECONDS), MetastoreConf.getTimeVar(conf,
            MetastoreConf.ConfVars.DELEGATION_TOKEN_MAX_LIFETIME, TimeUnit.SECONDS));
    try {
      mgr.startThreads();
      String tokenStr =
          mgr.getDelegationToken(UserGroupInformation.getCurrentUser().getShortUserName(),
              UserGroupInformation.getCurrentUser().getShortUserName());
      Assert.assertNotNull(mgr.verifyDelegationToken(tokenStr));
      DelegationTokenIdentifier id = getID(tokenStr);
      long initialExpiry = tokenStore.getToken(id).getRenewDate();
      Thread.sleep(100);
      Assert.assertTrue(System.currentTimeMillis() > id.getIssueDate());
      // No change in renewal date without renewal
      Assert.assertEquals(tokenStore.getToken(id).getRenewDate(), initialExpiry);
      mgr.renewDelegationToken(tokenStr);
      // Verify the token is valid
      Assert.assertNotNull(mgr.verifyDelegationToken(tokenStr));
      // Renewal date has increased after renewal
      Assert.assertTrue(tokenStore.getToken(id).getRenewDate() > initialExpiry);
    } finally {
      mgr.stopThreads();
    }
  }
Test the renewal of Delegation tokens obtained from the Metastore.
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/security/TestTokenStoreDelegationTokenSecretManager.java