|
@@ -18,13 +18,9 @@
|
|
|
|
|
|
package org.apache.hadoop.tools;
|
|
package org.apache.hadoop.tools;
|
|
|
|
|
|
-import static org.junit.Assert.*;
|
|
|
|
-
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
-import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
-import java.util.Map.Entry;
|
|
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
@@ -37,8 +33,8 @@ import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
|
+import org.apache.hadoop.tools.util.DistCpTestUtils;
|
|
import org.apache.hadoop.util.Progressable;
|
|
import org.apache.hadoop.util.Progressable;
|
|
-import org.apache.hadoop.util.ToolRunner;
|
|
|
|
|
|
|
|
import org.junit.AfterClass;
|
|
import org.junit.AfterClass;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.BeforeClass;
|
|
@@ -79,6 +75,7 @@ public class TestDistCpWithXAttrs {
|
|
private static final Path dstFile2 = new Path(dstDir2, "file2");
|
|
private static final Path dstFile2 = new Path(dstDir2, "file2");
|
|
private static final Path dstFile3 = new Path(dstDir2, "file3");
|
|
private static final Path dstFile3 = new Path(dstDir2, "file3");
|
|
private static final Path dstFile4 = new Path(dstDir2, "file4");
|
|
private static final Path dstFile4 = new Path(dstDir2, "file4");
|
|
|
|
+ private static final String rootedSrcName = "/src";
|
|
|
|
|
|
@BeforeClass
|
|
@BeforeClass
|
|
public static void init() throws Exception {
|
|
public static void init() throws Exception {
|
|
@@ -125,55 +122,56 @@ public class TestDistCpWithXAttrs {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testPreserveXAttrs() throws Exception {
|
|
public void testPreserveXAttrs() throws Exception {
|
|
- assertRunDistCp(DistCpConstants.SUCCESS, "/dstPreserveXAttrs");
|
|
|
|
|
|
+ DistCpTestUtils.assertRunDistCp(DistCpConstants.SUCCESS, rootedSrcName,
|
|
|
|
+ "/dstPreserveXAttrs", "-px", conf);
|
|
|
|
|
|
// dstDir1
|
|
// dstDir1
|
|
Map<String, byte[]> xAttrs = Maps.newHashMap();
|
|
Map<String, byte[]> xAttrs = Maps.newHashMap();
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name2, value2);
|
|
xAttrs.put(name2, value2);
|
|
- assertXAttrs(dstDir1, xAttrs);
|
|
|
|
|
|
+ DistCpTestUtils.assertXAttrs(dstDir1, fs, xAttrs);
|
|
|
|
|
|
// dstSubDir1
|
|
// dstSubDir1
|
|
xAttrs.clear();
|
|
xAttrs.clear();
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name3, new byte[0]);
|
|
xAttrs.put(name3, new byte[0]);
|
|
- assertXAttrs(dstSubDir1, xAttrs);
|
|
|
|
|
|
+ DistCpTestUtils.assertXAttrs(dstSubDir1, fs, xAttrs);
|
|
|
|
|
|
// dstFile1
|
|
// dstFile1
|
|
xAttrs.clear();
|
|
xAttrs.clear();
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name2, value2);
|
|
xAttrs.put(name2, value2);
|
|
xAttrs.put(name3, new byte[0]);
|
|
xAttrs.put(name3, new byte[0]);
|
|
- assertXAttrs(dstFile1, xAttrs);
|
|
|
|
|
|
+ DistCpTestUtils.assertXAttrs(dstFile1, fs, xAttrs);
|
|
|
|
|
|
// dstDir2
|
|
// dstDir2
|
|
xAttrs.clear();
|
|
xAttrs.clear();
|
|
xAttrs.put(name2, value2);
|
|
xAttrs.put(name2, value2);
|
|
- assertXAttrs(dstDir2, xAttrs);
|
|
|
|
|
|
+ DistCpTestUtils.assertXAttrs(dstDir2, fs, xAttrs);
|
|
|
|
|
|
// dstFile2
|
|
// dstFile2
|
|
xAttrs.clear();
|
|
xAttrs.clear();
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name1, value1);
|
|
xAttrs.put(name4, new byte[0]);
|
|
xAttrs.put(name4, new byte[0]);
|
|
- assertXAttrs(dstFile2, xAttrs);
|
|
|
|
|
|
+ DistCpTestUtils.assertXAttrs(dstFile2, fs, xAttrs);
|
|
|
|
|
|
// dstFile3
|
|
// dstFile3
|
|
xAttrs.clear();
|
|
xAttrs.clear();
|
|
xAttrs.put(name3, new byte[0]);
|
|
xAttrs.put(name3, new byte[0]);
|
|
xAttrs.put(name4, new byte[0]);
|
|
xAttrs.put(name4, new byte[0]);
|
|
- assertXAttrs(dstFile3, xAttrs);
|
|
|
|
|
|
+ DistCpTestUtils.assertXAttrs(dstFile3, fs, xAttrs);
|
|
|
|
|
|
// dstFile4
|
|
// dstFile4
|
|
xAttrs.clear();
|
|
xAttrs.clear();
|
|
- assertXAttrs(dstFile4, xAttrs);
|
|
|
|
|
|
+ DistCpTestUtils.assertXAttrs(dstFile4, fs, xAttrs);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testXAttrsNotEnabled() throws Exception {
|
|
public void testXAttrsNotEnabled() throws Exception {
|
|
try {
|
|
try {
|
|
restart(false);
|
|
restart(false);
|
|
- assertRunDistCp(DistCpConstants.XATTRS_NOT_SUPPORTED,
|
|
|
|
- "/dstXAttrsNotEnabled");
|
|
|
|
|
|
+ DistCpTestUtils.assertRunDistCp(DistCpConstants.XATTRS_NOT_SUPPORTED,
|
|
|
|
+ rootedSrcName, "/dstXAttrsNotEnabled", "-px", conf);
|
|
} finally {
|
|
} finally {
|
|
restart(true);
|
|
restart(true);
|
|
}
|
|
}
|
|
@@ -181,8 +179,8 @@ public class TestDistCpWithXAttrs {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testXAttrsNotImplemented() throws Exception {
|
|
public void testXAttrsNotImplemented() throws Exception {
|
|
- assertRunDistCp(DistCpConstants.XATTRS_NOT_SUPPORTED,
|
|
|
|
- "stubfs://dstXAttrsNotImplemented");
|
|
|
|
|
|
+ DistCpTestUtils.assertRunDistCp(DistCpConstants.XATTRS_NOT_SUPPORTED,
|
|
|
|
+ rootedSrcName, "stubfs://dstXAttrsNotImplemented", "-px", conf);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -251,45 +249,6 @@ public class TestDistCpWithXAttrs {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Asserts the XAttrs returned by getXAttrs for a specific path.
|
|
|
|
- *
|
|
|
|
- * @param path String path to check
|
|
|
|
- * @param xAttrs XAttr[] expected xAttrs
|
|
|
|
- * @throws Exception if there is any error
|
|
|
|
- */
|
|
|
|
- private static void assertXAttrs(Path path, Map<String, byte[]> expectedXAttrs)
|
|
|
|
- throws Exception {
|
|
|
|
- Map<String, byte[]> xAttrs = fs.getXAttrs(path);
|
|
|
|
- assertEquals(expectedXAttrs.size(), xAttrs.size());
|
|
|
|
- Iterator<Entry<String, byte[]>> i = expectedXAttrs.entrySet().iterator();
|
|
|
|
- while (i.hasNext()) {
|
|
|
|
- Entry<String, byte[]> e = i.next();
|
|
|
|
- String name = e.getKey();
|
|
|
|
- byte[] value = e.getValue();
|
|
|
|
- if (value == null) {
|
|
|
|
- assertTrue(xAttrs.containsKey(name) && xAttrs.get(name) == null);
|
|
|
|
- } else {
|
|
|
|
- assertArrayEquals(value, xAttrs.get(name));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Runs distcp from /src to specified destination, preserving XAttrs. Asserts
|
|
|
|
- * expected exit code.
|
|
|
|
- *
|
|
|
|
- * @param int exitCode expected exit code
|
|
|
|
- * @param dst String distcp destination
|
|
|
|
- * @throws Exception if there is any error
|
|
|
|
- */
|
|
|
|
- private static void assertRunDistCp(int exitCode, String dst)
|
|
|
|
- throws Exception {
|
|
|
|
- DistCp distCp = new DistCp(conf, null);
|
|
|
|
- assertEquals(exitCode,
|
|
|
|
- ToolRunner.run(conf, distCp, new String[] { "-px", "/src", dst }));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Initialize the cluster, wait for it to become active, and get FileSystem.
|
|
* Initialize the cluster, wait for it to become active, and get FileSystem.
|
|
*
|
|
*
|