From 7bd700941d0a423d5232331fa19eab5fdab6a6fb Mon Sep 17 00:00:00 2001 From: Xiao Chen Date: Mon, 16 Oct 2017 09:54:37 -0700 Subject: [PATCH] HDFS-12637. Extend TestDistributedFileSystemWithECFile with a random EC policy. Contributed by Takanobu Asanuma. --- .../TestDistributedFileSystemWithECFile.java | 37 +++++++++----- ...ileSystemWithECFileWithRandomECPolicy.java | 49 +++++++++++++++++++ 2 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFileWithRandomECPolicy.java diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFile.java index d4e01b72d4..14a2ec494a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFile.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFile.java @@ -39,34 +39,45 @@ * FileSystem.listFiles for erasure coded files. */ public class TestDistributedFileSystemWithECFile { - private final ErasureCodingPolicy ecPolicy = - StripedFileTestUtil.getDefaultECPolicy(); - private final int cellSize = ecPolicy.getCellSize(); - private final short dataBlocks = (short) ecPolicy.getNumDataUnits(); - private final short parityBlocks = (short) ecPolicy.getNumParityUnits(); - private final int numDNs = dataBlocks + parityBlocks; - private final int stripesPerBlock = 4; - private final int blockSize = stripesPerBlock * cellSize; - private final int blockGroupSize = blockSize * dataBlocks; + private ErasureCodingPolicy ecPolicy; + private int cellSize; + private short dataBlocks; + private short parityBlocks; + private int numDNs; + private int stripesPerBlock; + private int blockSize; + private int blockGroupSize; private MiniDFSCluster cluster; private FileContext fileContext; private DistributedFileSystem fs; private Configuration conf = new HdfsConfiguration(); + public ErasureCodingPolicy getEcPolicy() { + return StripedFileTestUtil.getDefaultECPolicy(); + } + @Before public void setup() throws IOException { + ecPolicy = getEcPolicy(); + cellSize = ecPolicy.getCellSize(); + dataBlocks = (short) ecPolicy.getNumDataUnits(); + parityBlocks = (short) ecPolicy.getNumParityUnits(); + numDNs = dataBlocks + parityBlocks; + stripesPerBlock = 4; + blockSize = stripesPerBlock * cellSize; + blockGroupSize = blockSize * dataBlocks; + conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_REDUNDANCY_CONSIDERLOAD_KEY, false); cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDNs).build(); fileContext = FileContext.getFileContext(cluster.getURI(0), conf); fs = cluster.getFileSystem(); - fs.enableErasureCodingPolicy( - StripedFileTestUtil.getDefaultECPolicy().getName()); + fs.enableErasureCodingPolicy(ecPolicy.getName()); fs.mkdirs(new Path("/ec")); cluster.getFileSystem().getClient().setErasureCodingPolicy("/ec", - StripedFileTestUtil.getDefaultECPolicy().getName()); + ecPolicy.getName()); } @After @@ -121,7 +132,7 @@ private void assertSmallerThanOneCell(BlockLocation[] locations) @Test(timeout=60000) public void testListECFilesSmallerThanOneStripe() throws Exception { - int dataBlocksNum = 3; + int dataBlocksNum = dataBlocks; createFile("/ec/smallstripe", cellSize * dataBlocksNum); RemoteIterator iter = cluster.getFileSystem().listFiles(new Path("/ec"), true); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFileWithRandomECPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFileWithRandomECPolicy.java new file mode 100644 index 0000000000..afa7569b1d --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDistributedFileSystemWithECFileWithRandomECPolicy.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs; + +import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This test extends TestDistributedFileSystemWithECFile to use a random + * (non-default) EC policy. + */ +public class TestDistributedFileSystemWithECFileWithRandomECPolicy extends + TestDistributedFileSystemWithECFile { + private static final Logger LOG = LoggerFactory.getLogger( + TestDistributedFileSystemWithECFileWithRandomECPolicy.class); + + private ErasureCodingPolicy ecPolicy; + + public TestDistributedFileSystemWithECFileWithRandomECPolicy() { + // If you want to debug this test with a specific ec policy, please use + // SystemErasureCodingPolicies class. + // e.g. ecPolicy = SystemErasureCodingPolicies.getByID(RS_3_2_POLICY_ID); + ecPolicy = StripedFileTestUtil.getRandomNonDefaultECPolicy(); + LOG.info("run {} with {}.", + TestDistributedFileSystemWithECFileWithRandomECPolicy.class + .getSuperclass().getSimpleName(), ecPolicy.getName()); + } + + @Override + public ErasureCodingPolicy getEcPolicy() { + return ecPolicy; + } +}