From eaef8446f69965d6e6ffccd15b7c893e2dcd34e4 Mon Sep 17 00:00:00 2001 From: John Zhuge Date: Thu, 14 Sep 2017 11:29:34 -0700 Subject: [PATCH] HADOOP-14864. FSDataInputStream#unbuffer UOE should include stream class name. Contributed by Bharat Viswanadham. (cherry picked from commit 7ee02d1065268511ec10a8b8852d0d6327419b9c) --- .../apache/hadoop/fs/FSDataInputStream.java | 4 ++-- .../org/apache/hadoop/fs/TestUnbuffer.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSDataInputStream.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSDataInputStream.java index 640db592fb1..a80279db525 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSDataInputStream.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSDataInputStream.java @@ -230,8 +230,8 @@ public class FSDataInputStream extends DataInputStream try { ((CanUnbuffer)in).unbuffer(); } catch (ClassCastException e) { - throw new UnsupportedOperationException("this stream does not " + - "support unbuffering."); + throw new UnsupportedOperationException("this stream " + + in.getClass().getName() + " does not " + "support unbuffering."); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUnbuffer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUnbuffer.java index e25a7548852..b112e306c82 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUnbuffer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestUnbuffer.java @@ -27,12 +27,18 @@ import org.apache.hadoop.hdfs.PeerCache; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; import org.apache.hadoop.io.IOUtils; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; public class TestUnbuffer { private static final Log LOG = LogFactory.getLog(TestUnbuffer.class.getName()); + @Rule + public ExpectedException exception = ExpectedException.none(); + /** * Test that calling Unbuffer closes sockets. */ @@ -123,4 +129,19 @@ public class TestUnbuffer { } } } + + /** + * Test unbuffer method which throws an Exception with class name included. + */ + @Test + public void testUnbufferException() { + FSInputStream in = Mockito.mock(FSInputStream.class); + FSDataInputStream fs = new FSDataInputStream(in); + + exception.expect(UnsupportedOperationException.class); + exception.expectMessage("this stream " + in.getClass().getName() + + " does not support unbuffering"); + + fs.unbuffer(); + } }