HDFS-13629. Some tests in TestDiskBalancerCommand fail on Windows due to MiniDFSCluster path conflict and improper path usage. Contributed by Anbang Hu.

(cherry picked from commit 47c31ff16b)
This commit is contained in:
Inigo Goiri 2018-05-30 10:22:04 -07:00
parent 6dc40bab4e
commit 5c09dadd73
2 changed files with 11 additions and 9 deletions

View File

@ -38,6 +38,7 @@ import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerCluster;
import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerDataNode; import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerDataNode;
import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume; import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume;
import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolumeSet; import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolumeSet;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -46,6 +47,7 @@ import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
@ -307,7 +309,8 @@ public class DiskBalancerTestUtil {
"need to specify capacities for two storages."); "need to specify capacities for two storages.");
// Write a file and restart the cluster // Write a file and restart the cluster
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) File basedir = new File(GenericTestUtils.getRandomizedTempPath());
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, basedir)
.numDataNodes(numDatanodes) .numDataNodes(numDatanodes)
.storageCapacities(storageCapacities) .storageCapacities(storageCapacities)
.storageTypes(new StorageType[]{StorageType.DISK, StorageType.DISK}) .storageTypes(new StorageType[]{StorageType.DISK, StorageType.DISK})

View File

@ -615,15 +615,15 @@ public class TestDiskBalancerCommand {
assertThat( assertThat(
outputs.get(3), outputs.get(3),
is(allOf(containsString("DISK"), is(allOf(containsString("DISK"),
containsString(cluster.getInstanceStorageDir(0, 0) containsString(new Path(cluster.getInstanceStorageDir(0, 0)
.getAbsolutePath()), .getAbsolutePath()).toString()),
containsString("0.00"), containsString("0.00"),
containsString("1.00")))); containsString("1.00"))));
assertThat( assertThat(
outputs.get(4), outputs.get(4),
is(allOf(containsString("DISK"), is(allOf(containsString("DISK"),
containsString(cluster.getInstanceStorageDir(0, 1) containsString(new Path(cluster.getInstanceStorageDir(0, 1)
.getAbsolutePath()), .getAbsolutePath()).toString()),
containsString("0.00"), containsString("0.00"),
containsString("1.00")))); containsString("1.00"))));
} }
@ -719,9 +719,7 @@ public class TestDiskBalancerCommand {
@Test @Test
public void testPrintFullPathOfPlan() public void testPrintFullPathOfPlan()
throws Exception { throws Exception {
final Path parent = new Path( String parent = GenericTestUtils.getRandomizedTempPath();
PathUtils.getTestPath(getClass()),
GenericTestUtils.getMethodName());
MiniDFSCluster miniCluster = null; MiniDFSCluster miniCluster = null;
try { try {
@ -815,7 +813,8 @@ public class TestDiskBalancerCommand {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.setBoolean(DFSConfigKeys.DFS_DISK_BALANCER_ENABLED, true); conf.setBoolean(DFSConfigKeys.DFS_DISK_BALANCER_ENABLED, true);
final int numDatanodes = 2; final int numDatanodes = 2;
MiniDFSCluster miniDFSCluster = new MiniDFSCluster.Builder(conf) File basedir = new File(GenericTestUtils.getRandomizedTempPath());
MiniDFSCluster miniDFSCluster = new MiniDFSCluster.Builder(conf, basedir)
.numDataNodes(numDatanodes).build(); .numDataNodes(numDatanodes).build();
try { try {
miniDFSCluster.waitActive(); miniDFSCluster.waitActive();