HDFS-11718. DFSStripedOutputStream hsync/hflush should not throw UnsupportedOperationException. (Manoj Govindassamy via lei)

Change-Id: I4cc226b80c64a0d900a3b1ce71e51f051cd29c22
This commit is contained in:
Lei Xu 2017-04-28 17:06:14 -07:00
parent 2e52789edf
commit 19a7e94ee4
2 changed files with 30 additions and 3 deletions

View File

@ -783,12 +783,12 @@ public class DFSStripedOutputStream extends DFSOutputStream {
@Override
public void hflush() {
throw new UnsupportedOperationException();
// not supported yet
}
@Override
public void hsync() {
throw new UnsupportedOperationException();
// not supported yet
}
@Override

View File

@ -17,15 +17,21 @@
*/
package org.apache.hadoop.hdfs;
import static org.apache.hadoop.fs.contract.ContractTestUtils.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.erasurecode.CodecUtil;
import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
import org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawErasureCoderFactory;
@ -170,7 +176,6 @@ public class TestDFSStripedOutputStream {
blockSize * dataBlocks + cellSize+ 123);
}
@Test
public void testFileMoreThanABlockGroup3() throws Exception {
testOneFile("/MoreThanABlockGroup3",
@ -178,6 +183,28 @@ public class TestDFSStripedOutputStream {
+ cellSize + 123);
}
/**
* {@link DFSStripedOutputStream} doesn't support hflush() or hsync() yet.
* This test is to make sure that DFSStripedOutputStream doesn't throw any
* {@link UnsupportedOperationException} on hflush() or hsync() so as to
* comply with output stream spec.
*
* @throws Exception
*/
@Test
public void testStreamFlush() throws Exception {
final byte[] bytes = StripedFileTestUtil.generateBytes(blockSize *
dataBlocks * 3 + cellSize * dataBlocks + cellSize + 123);
try (FSDataOutputStream os = fs.create(new Path("/ec-file-1"))) {
InputStream is = new ByteArrayInputStream(bytes);
IOUtils.copyBytes(is, os, bytes.length);
os.hflush();
os.hsync();
} catch (Exception e) {
fail("hflush()/hsync() on striped file output stream failed!", e);
}
}
private void testOneFile(String src, int writeBytes) throws Exception {
src += "_" + writeBytes;
Path testPath = new Path(src);