From bd816a2739855073160b248b3f26b89c4eeafb7b Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Fri, 10 May 2013 19:54:27 +0000 Subject: [PATCH] HDFS-4751. TestLeaseRenewer#testThreadName flakes. Contributed by Andrew Wang. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1481166 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ .../src/main/java/org/apache/hadoop/hdfs/LeaseRenewer.java | 6 ++++++ .../test/java/org/apache/hadoop/hdfs/TestLeaseRenewer.java | 5 +---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index dc7339f4905..ddbf3809dfd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -244,6 +244,8 @@ Release 2.0.5-beta - UNRELEASED HDFS-4799. Corrupt replica can be prematurely removed from corruptReplicas map. (todd via kihwal) + HDFS-4751. TestLeaseRenewer#testThreadName flakes. (Andrew Wang via atm) + Release 2.0.4-alpha - 2013-04-25 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/LeaseRenewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/LeaseRenewer.java index 79ebd81de58..8f3b8fb0e32 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/LeaseRenewer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/LeaseRenewer.java @@ -35,6 +35,7 @@ import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.Daemon; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.Time; +import com.google.common.annotations.VisibleForTesting; /** *

@@ -323,6 +324,11 @@ class LeaseRenewer { } } + @VisibleForTesting + synchronized void setEmptyTime(long time) { + emptyTime = time; + } + /** Close a file. */ void closeFile(final String src, final DFSClient dfsc) { dfsc.removeFileBeingWritten(src); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRenewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRenewer.java index 361e5c304df..6fcb0ed7b86 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRenewer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRenewer.java @@ -182,8 +182,6 @@ public class TestLeaseRenewer { renewer.isRunning()); // Pretend to open a file - Mockito.doReturn(false) - .when(MOCK_DFSCLIENT).isFilesBeingWrittenEmpty(); renewer.put(filePath, mockStream, MOCK_DFSCLIENT); Assert.assertTrue("Renewer should have started running", @@ -194,9 +192,8 @@ public class TestLeaseRenewer { Assert.assertEquals("LeaseRenewer:myuser@hdfs://nn1/", threadName); // Pretend to close the file - Mockito.doReturn(true) - .when(MOCK_DFSCLIENT).isFilesBeingWrittenEmpty(); renewer.closeFile(filePath, MOCK_DFSCLIENT); + renewer.setEmptyTime(Time.now()); // Should stop the renewer running within a few seconds long failTime = Time.now() + 5000;