From 19a7e94ee47f81557f0db6fb76bdf6bc49944dd0 Mon Sep 17 00:00:00 2001 From: Lei Xu Date: Fri, 28 Apr 2017 17:06:14 -0700 Subject: [PATCH] HDFS-11718. DFSStripedOutputStream hsync/hflush should not throw UnsupportedOperationException. (Manoj Govindassamy via lei) Change-Id: I4cc226b80c64a0d900a3b1ce71e51f051cd29c22 --- .../hadoop/hdfs/DFSStripedOutputStream.java | 4 +-- .../hdfs/TestDFSStripedOutputStream.java | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedOutputStream.java index 22b30e9306..3dd07f72e0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedOutputStream.java @@ -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 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedOutputStream.java index 14825ca41b..70309c95fe 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedOutputStream.java @@ -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);