From 8c2846510ebd4be5e437e2b20e9ee8caf9375206 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Wed, 12 Dec 2012 00:10:37 +0000 Subject: [PATCH] HADOOP-9113. o.a.h.fs.TestDelegationTokenRenewer is failing intermittently. Contributed by Karthik Kambatla git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1420490 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../java/org/apache/hadoop/fs/DelegationTokenRenewer.java | 8 ++++++++ .../org/apache/hadoop/fs/TestDelegationTokenRenewer.java | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 08c289aa084..84222ad0d40 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -482,6 +482,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-9126. FormatZK and ZKFC startup can fail due to zkclient connection establishment delay. (Rakesh R and todd via todd) + HADOOP-9113. o.a.h.fs.TestDelegationTokenRenewer is failing intermittently. + (Karthik Kambatla via eli) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java index b60507afa34..6e45a1ea6ae 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java @@ -18,6 +18,8 @@ package org.apache.hadoop.fs; +import com.google.common.annotations.VisibleForTesting; + import java.io.IOException; import java.lang.ref.WeakReference; import java.util.concurrent.DelayQueue; @@ -147,6 +149,12 @@ public class DelegationTokenRenewer /** Queue to maintain the RenewActions to be processed by the {@link #run()} */ private volatile DelayQueue> queue = new DelayQueue>(); + /** For testing purposes */ + @VisibleForTesting + protected int getRenewQueueLength() { + return queue.size(); + } + /** * Create the singleton instance. However, the thread can be started lazily in * {@link #addRenewAction(FileSystem)} diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java index 86a580c5258..3f1d34e99b7 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java @@ -4,6 +4,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -133,6 +134,8 @@ public class TestDelegationTokenRenewer { InterruptedException { TestFileSystem tfs = new TestFileSystem(); renewer.addRenewAction(tfs); + assertEquals("FileSystem not added to DelegationTokenRenewer", 1, + renewer.getRenewQueueLength()); for (int i = 0; i < 60; i++) { Thread.sleep(RENEW_CYCLE); @@ -144,7 +147,8 @@ public class TestDelegationTokenRenewer { assertTrue("Token not renewed even after 1 minute", (tfs.testToken.renewCount > 0)); - assertTrue("Token not removed", (tfs.testToken.renewCount < MAX_RENEWALS)); + assertEquals("FileSystem not removed from DelegationTokenRenewer", 0, + renewer.getRenewQueueLength()); assertTrue("Token not cancelled", tfs.testToken.cancelled); } }