HDFS-12637. Extend TestDistributedFileSystemWithECFile with a random EC policy. Contributed by Takanobu Asanuma.

This commit is contained in:
Xiao Chen 2017-10-16 09:54:37 -07:00
parent 035c6ee587
commit 7bd700941d
2 changed files with 73 additions and 13 deletions

View File

@ -39,34 +39,45 @@
* FileSystem.listFiles for erasure coded files. * FileSystem.listFiles for erasure coded files.
*/ */
public class TestDistributedFileSystemWithECFile { public class TestDistributedFileSystemWithECFile {
private final ErasureCodingPolicy ecPolicy = private ErasureCodingPolicy ecPolicy;
StripedFileTestUtil.getDefaultECPolicy(); private int cellSize;
private final int cellSize = ecPolicy.getCellSize(); private short dataBlocks;
private final short dataBlocks = (short) ecPolicy.getNumDataUnits(); private short parityBlocks;
private final short parityBlocks = (short) ecPolicy.getNumParityUnits(); private int numDNs;
private final int numDNs = dataBlocks + parityBlocks; private int stripesPerBlock;
private final int stripesPerBlock = 4; private int blockSize;
private final int blockSize = stripesPerBlock * cellSize; private int blockGroupSize;
private final int blockGroupSize = blockSize * dataBlocks;
private MiniDFSCluster cluster; private MiniDFSCluster cluster;
private FileContext fileContext; private FileContext fileContext;
private DistributedFileSystem fs; private DistributedFileSystem fs;
private Configuration conf = new HdfsConfiguration(); private Configuration conf = new HdfsConfiguration();
public ErasureCodingPolicy getEcPolicy() {
return StripedFileTestUtil.getDefaultECPolicy();
}
@Before @Before
public void setup() throws IOException { 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.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize);
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_REDUNDANCY_CONSIDERLOAD_KEY, conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_REDUNDANCY_CONSIDERLOAD_KEY,
false); false);
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDNs).build(); cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDNs).build();
fileContext = FileContext.getFileContext(cluster.getURI(0), conf); fileContext = FileContext.getFileContext(cluster.getURI(0), conf);
fs = cluster.getFileSystem(); fs = cluster.getFileSystem();
fs.enableErasureCodingPolicy( fs.enableErasureCodingPolicy(ecPolicy.getName());
StripedFileTestUtil.getDefaultECPolicy().getName());
fs.mkdirs(new Path("/ec")); fs.mkdirs(new Path("/ec"));
cluster.getFileSystem().getClient().setErasureCodingPolicy("/ec", cluster.getFileSystem().getClient().setErasureCodingPolicy("/ec",
StripedFileTestUtil.getDefaultECPolicy().getName()); ecPolicy.getName());
} }
@After @After
@ -121,7 +132,7 @@ private void assertSmallerThanOneCell(BlockLocation[] locations)
@Test(timeout=60000) @Test(timeout=60000)
public void testListECFilesSmallerThanOneStripe() throws Exception { public void testListECFilesSmallerThanOneStripe() throws Exception {
int dataBlocksNum = 3; int dataBlocksNum = dataBlocks;
createFile("/ec/smallstripe", cellSize * dataBlocksNum); createFile("/ec/smallstripe", cellSize * dataBlocksNum);
RemoteIterator<LocatedFileStatus> iter = RemoteIterator<LocatedFileStatus> iter =
cluster.getFileSystem().listFiles(new Path("/ec"), true); cluster.getFileSystem().listFiles(new Path("/ec"), true);

View File

@ -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;
}
}