You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sl...@apache.org on 2026/10/08 06:11:19 UTC
(hadoop) branch trunk updated: HADOOP-20009. Ensure token manager cleanup in testNodesLoadedAfterRestart. (#8797) Contributed by Shilun Fan
This is an automated email from the ASF dual-hosted git repository.
slfan1989 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 1c50c01f689 HADOOP-20009. Ensure token manager cleanup in testNodesLoadedAfterRestart. (#8797) Contributed by Shilun Fan
1c50c01f689 is described below
commit 1c50c01f68924eeb4a81d9b97fb17cda47100d63
Author: slfan1989 <55...@users.noreply.github.com>
AuthorDate: Thu Oct 8 14:11:12 2026 +0800
HADOOP-20009. Ensure token manager cleanup in testNodesLoadedAfterRestart. (#8797) Contributed by Shilun Fan
* HADOOP-20009. Ensure token manager cleanup in testNodesLoadedAfterRestart.
Destroy both the original and restarted DelegationTokenManager in finally blocks, including when initialization or assertions fail.
This prevents leftover ExpiredTokenRemover threads from accessing ZooKeeper after teardown and terminating the Surefire JVM with exit code 255, including in the inherited HDFS-RBF test.
Reviewed-by: Hualong Zhang <zh...@apache.org>
Signed-off-by: Shilun Fan <sl...@apache.org>
Preserve the existing cache-load and token-expiration assertions.
---
.../TestZKDelegationTokenSecretManager.java | 130 +++++++++++----------
1 file changed, 69 insertions(+), 61 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
index 58c3f541018..556ba48bd37 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
@@ -473,69 +473,77 @@ public void testNodesLoadedAfterRestart() throws Exception {
DelegationTokenManager tm =
new DelegationTokenManager(conf, new Text("bla"));
- tm.init();
- Token<DelegationTokenIdentifier> token =
- (Token<DelegationTokenIdentifier>) tm
- .createToken(UserGroupInformation.getCurrentUser(), "good");
- assertNotNull(token);
- Token<DelegationTokenIdentifier> cancelled =
- (Token<DelegationTokenIdentifier>) tm
- .createToken(UserGroupInformation.getCurrentUser(), "cancelled");
- assertNotNull(cancelled);
- tm.verifyToken(token);
- tm.verifyToken(cancelled);
-
- // Cancel one token, verify it's gone
- tm.cancelToken(cancelled, "cancelled");
- final AbstractDelegationTokenSecretManager sm =
- tm.getDelegationTokenSecretManager();
- final ZKDelegationTokenSecretManager zksm =
- (ZKDelegationTokenSecretManager) sm;
- final AbstractDelegationTokenIdentifier idCancelled =
- sm.decodeTokenIdentifier(cancelled);
- LOG.info("Waiting for the cancelled token to be removed");
-
- GenericTestUtils.waitFor(new Supplier<Boolean>() {
- @Override
- public Boolean get() {
- AbstractDelegationTokenSecretManager.DelegationTokenInformation dtinfo =
- zksm.getTokenInfo(idCancelled);
- return dtinfo == null;
- }
- }, 100, 5000);
+ final Token<DelegationTokenIdentifier> token;
+ final Token<DelegationTokenIdentifier> cancelled;
+ try {
+ tm.init();
+ token = (Token<DelegationTokenIdentifier>) tm
+ .createToken(UserGroupInformation.getCurrentUser(), "good");
+ assertNotNull(token);
+ cancelled = (Token<DelegationTokenIdentifier>) tm
+ .createToken(UserGroupInformation.getCurrentUser(), "cancelled");
+ assertNotNull(cancelled);
+ tm.verifyToken(token);
+ tm.verifyToken(cancelled);
+
+ // Cancel one token, verify it's gone
+ tm.cancelToken(cancelled, "cancelled");
+ final AbstractDelegationTokenSecretManager sm =
+ tm.getDelegationTokenSecretManager();
+ final ZKDelegationTokenSecretManager zksm =
+ (ZKDelegationTokenSecretManager) sm;
+ final AbstractDelegationTokenIdentifier idCancelled =
+ sm.decodeTokenIdentifier(cancelled);
+ LOG.info("Waiting for the cancelled token to be removed");
+
+ GenericTestUtils.waitFor(new Supplier<Boolean>() {
+ @Override
+ public Boolean get() {
+ AbstractDelegationTokenSecretManager.DelegationTokenInformation dtinfo =
+ zksm.getTokenInfo(idCancelled);
+ return dtinfo == null;
+ }
+ }, 100, 5000);
+ } finally {
+ tm.destroy();
+ }
// Fake a restart which launches a new tm
- tm.destroy();
- tm = new DelegationTokenManager(conf, new Text("bla"));
- tm.init();
- final AbstractDelegationTokenSecretManager smNew =
- tm.getDelegationTokenSecretManager();
- final ZKDelegationTokenSecretManager zksmNew =
- (ZKDelegationTokenSecretManager) smNew;
-
- // The cancelled token should be gone, and not loaded.
- AbstractDelegationTokenIdentifier id =
- smNew.decodeTokenIdentifier(cancelled);
- AbstractDelegationTokenSecretManager.DelegationTokenInformation dtinfo =
- zksmNew.getTokenInfo(id);
- assertNull(dtinfo, "canceled dt should be gone!");
-
- // The good token should be loaded on startup, and removed after expiry.
- id = smNew.decodeTokenIdentifier(token);
- dtinfo = zksmNew.getTokenInfoFromMemory(id);
- assertNotNull(dtinfo, "good dt should be in memory!");
-
- // Wait for the good token to expire.
- Thread.sleep(5000);
- final ZKDelegationTokenSecretManager zksm1 = zksmNew;
- final AbstractDelegationTokenIdentifier id1 = id;
- GenericTestUtils.waitFor(new Supplier<Boolean>() {
- @Override
- public Boolean get() {
- LOG.info("Waiting for the expired token to be removed...");
- return zksm1.getTokenInfo(id1) == null;
- }
- }, 1000, 5000);
+ DelegationTokenManager restartedManager =
+ new DelegationTokenManager(conf, new Text("bla"));
+ try {
+ restartedManager.init();
+ final AbstractDelegationTokenSecretManager smNew =
+ restartedManager.getDelegationTokenSecretManager();
+ final ZKDelegationTokenSecretManager zksmNew =
+ (ZKDelegationTokenSecretManager) smNew;
+
+ // The cancelled token should be gone, and not loaded.
+ AbstractDelegationTokenIdentifier id =
+ smNew.decodeTokenIdentifier(cancelled);
+ AbstractDelegationTokenSecretManager.DelegationTokenInformation dtinfo =
+ zksmNew.getTokenInfo(id);
+ assertNull(dtinfo, "canceled dt should be gone!");
+
+ // The good token should be loaded on startup, and removed after expiry.
+ id = smNew.decodeTokenIdentifier(token);
+ dtinfo = zksmNew.getTokenInfoFromMemory(id);
+ assertNotNull(dtinfo, "good dt should be in memory!");
+
+ // Wait for the good token to expire.
+ Thread.sleep(5000);
+ final ZKDelegationTokenSecretManager zksm1 = zksmNew;
+ final AbstractDelegationTokenIdentifier id1 = id;
+ GenericTestUtils.waitFor(new Supplier<Boolean>() {
+ @Override
+ public Boolean get() {
+ LOG.info("Waiting for the expired token to be removed...");
+ return zksm1.getTokenInfo(id1) == null;
+ }
+ }, 1000, 5000);
+ } finally {
+ restartedManager.destroy();
+ }
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org