@Test public void testTokenRenewalAndRemoval() throws IOException, InterruptedException {
    DelegationTokenStore tokenStore = new MemoryTokenStore();
    TokenStoreDelegationTokenSecretManager mgr = createTokenMgr(tokenStore, 2, 1, 8);
    try {
      mgr.startThreads();
      String tokenStr =
          mgr.getDelegationToken(UserGroupInformation.getCurrentUser().getShortUserName(),
              UserGroupInformation.getCurrentUser().getShortUserName());
      DelegationTokenIdentifier id = getID(tokenStr);
      Assert.assertNotNull(mgr.verifyDelegationToken(tokenStr));

      long initialExpiry = tokenStore.getToken(id).getRenewDate();
      Thread.sleep(5000);
      // Token should automatically get renewed by the Thread as the current time is > renew time.
      Assert.assertTrue(tokenStore.getToken(id).getRenewDate() > initialExpiry);

      Thread.sleep(5000);
      //Expiry thread will remove the token as it has crossed the maxLifeTime.
      Assert.assertEquals(tokenStore.getAllDelegationTokenIdentifiers().size(), 0);
    } 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