HADOOP-14864. FSDataInputStream#unbuffer UOE should include stream class name. Contributed by Bharat Viswanadham.

This commit is contained in:
John Zhuge 2017-09-13 20:55:06 -07:00 committed by John Zhuge
parent 09b476e6da
commit 7ee02d1065
2 changed files with 23 additions and 2 deletions

View File

@ -230,8 +230,8 @@ public void unbuffer() {
try { try {
((CanUnbuffer)in).unbuffer(); ((CanUnbuffer)in).unbuffer();
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new UnsupportedOperationException("this stream does not " + throw new UnsupportedOperationException("this stream " +
"support unbuffering."); in.getClass().getName() + " does not " + "support unbuffering.");
} }
} }

View File

@ -27,12 +27,18 @@
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
public class TestUnbuffer { public class TestUnbuffer {
private static final Log LOG = private static final Log LOG =
LogFactory.getLog(TestUnbuffer.class.getName()); LogFactory.getLog(TestUnbuffer.class.getName());
@Rule
public ExpectedException exception = ExpectedException.none();
/** /**
* Test that calling Unbuffer closes sockets. * Test that calling Unbuffer closes sockets.
*/ */
@ -123,4 +129,19 @@ public void testOpenManyFilesViaTcp() throws Exception {
} }
} }
} }
/**
* 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();
}
} }