|
@@ -33,8 +33,8 @@ import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
|
|
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
|
|
import org.apache.hadoop.hdfs.tools.ECAdmin;
|
|
import org.apache.hadoop.hdfs.tools.ECAdmin;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
-import org.apache.hadoop.test.GenericTestUtils;
|
|
|
|
import org.apache.hadoop.tools.CopyListingFileStatus;
|
|
import org.apache.hadoop.tools.CopyListingFileStatus;
|
|
|
|
+import org.apache.hadoop.tools.DistCpConstants;
|
|
import org.apache.hadoop.tools.DistCpOptionSwitch;
|
|
import org.apache.hadoop.tools.DistCpOptionSwitch;
|
|
import org.apache.hadoop.tools.DistCpOptions.FileAttribute;
|
|
import org.apache.hadoop.tools.DistCpOptions.FileAttribute;
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
@@ -63,6 +63,7 @@ import static org.apache.hadoop.fs.permission.FsAction.READ;
|
|
import static org.apache.hadoop.fs.permission.FsAction.READ_EXECUTE;
|
|
import static org.apache.hadoop.fs.permission.FsAction.READ_EXECUTE;
|
|
import static org.apache.hadoop.fs.permission.FsAction.READ_WRITE;
|
|
import static org.apache.hadoop.fs.permission.FsAction.READ_WRITE;
|
|
import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.aclEntry;
|
|
import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.aclEntry;
|
|
|
|
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertTrue;
|
|
@@ -1208,7 +1209,7 @@ public class TestDistCpUtils {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testCompareFileLengthsAndChecksums() throws IOException {
|
|
|
|
|
|
+ public void testCompareFileLengthsAndChecksums() throws Throwable {
|
|
|
|
|
|
String base = "/tmp/verify-checksum/";
|
|
String base = "/tmp/verify-checksum/";
|
|
long srcSeed = System.currentTimeMillis();
|
|
long srcSeed = System.currentTimeMillis();
|
|
@@ -1224,22 +1225,18 @@ public class TestDistCpUtils {
|
|
Path dstWithLen0 = new Path(base + "dstLen0");
|
|
Path dstWithLen0 = new Path(base + "dstLen0");
|
|
fs.create(srcWithLen0).close();
|
|
fs.create(srcWithLen0).close();
|
|
fs.create(dstWithLen0).close();
|
|
fs.create(dstWithLen0).close();
|
|
- DistCpUtils.compareFileLengthsAndChecksums(fs, srcWithLen0,
|
|
|
|
- null, fs, dstWithLen0, false);
|
|
|
|
|
|
+ DistCpUtils.compareFileLengthsAndChecksums(0, fs, srcWithLen0,
|
|
|
|
+ null, fs, dstWithLen0, false, 0);
|
|
|
|
|
|
// different lengths comparison
|
|
// different lengths comparison
|
|
Path srcWithLen1 = new Path(base + "srcLen1");
|
|
Path srcWithLen1 = new Path(base + "srcLen1");
|
|
Path dstWithLen2 = new Path(base + "dstLen2");
|
|
Path dstWithLen2 = new Path(base + "dstLen2");
|
|
DFSTestUtil.createFile(fs, srcWithLen1, 1, replFactor, srcSeed);
|
|
DFSTestUtil.createFile(fs, srcWithLen1, 1, replFactor, srcSeed);
|
|
DFSTestUtil.createFile(fs, dstWithLen2, 2, replFactor, srcSeed);
|
|
DFSTestUtil.createFile(fs, dstWithLen2, 2, replFactor, srcSeed);
|
|
- try {
|
|
|
|
- DistCpUtils.compareFileLengthsAndChecksums(fs, srcWithLen1,
|
|
|
|
- null, fs, dstWithLen2, false);
|
|
|
|
- Assert.fail("Expected different lengths comparison to fail!");
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- GenericTestUtils.assertExceptionContains(
|
|
|
|
- "Mismatch in length", e);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ intercept(IOException.class, DistCpConstants.LENGTH_MISMATCH_ERROR_MSG,
|
|
|
|
+ () -> DistCpUtils.compareFileLengthsAndChecksums(1, fs,
|
|
|
|
+ srcWithLen1, null, fs, dstWithLen2, false, 2));
|
|
|
|
|
|
// checksums matched
|
|
// checksums matched
|
|
Path srcWithChecksum1 = new Path(base + "srcChecksum1");
|
|
Path srcWithChecksum1 = new Path(base + "srcChecksum1");
|
|
@@ -1248,28 +1245,24 @@ public class TestDistCpUtils {
|
|
replFactor, srcSeed);
|
|
replFactor, srcSeed);
|
|
DFSTestUtil.createFile(fs, dstWithChecksum1, 1024,
|
|
DFSTestUtil.createFile(fs, dstWithChecksum1, 1024,
|
|
replFactor, srcSeed);
|
|
replFactor, srcSeed);
|
|
- DistCpUtils.compareFileLengthsAndChecksums(fs, srcWithChecksum1,
|
|
|
|
- null, fs, dstWithChecksum1, false);
|
|
|
|
- DistCpUtils.compareFileLengthsAndChecksums(fs, srcWithChecksum1,
|
|
|
|
|
|
+ DistCpUtils.compareFileLengthsAndChecksums(1024, fs, srcWithChecksum1,
|
|
|
|
+ null, fs, dstWithChecksum1, false, 1024);
|
|
|
|
+ DistCpUtils.compareFileLengthsAndChecksums(1024, fs, srcWithChecksum1,
|
|
fs.getFileChecksum(srcWithChecksum1), fs, dstWithChecksum1,
|
|
fs.getFileChecksum(srcWithChecksum1), fs, dstWithChecksum1,
|
|
- false);
|
|
|
|
|
|
+ false, 1024);
|
|
|
|
|
|
// checksums mismatched
|
|
// checksums mismatched
|
|
Path dstWithChecksum2 = new Path(base + "dstChecksum2");
|
|
Path dstWithChecksum2 = new Path(base + "dstChecksum2");
|
|
DFSTestUtil.createFile(fs, dstWithChecksum2, 1024,
|
|
DFSTestUtil.createFile(fs, dstWithChecksum2, 1024,
|
|
replFactor, dstSeed);
|
|
replFactor, dstSeed);
|
|
- try {
|
|
|
|
- DistCpUtils.compareFileLengthsAndChecksums(fs, srcWithChecksum1,
|
|
|
|
- null, fs, dstWithChecksum2, false);
|
|
|
|
- Assert.fail("Expected different checksums comparison to fail!");
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- GenericTestUtils.assertExceptionContains(
|
|
|
|
- "Checksum mismatch", e);
|
|
|
|
- }
|
|
|
|
|
|
+ intercept(IOException.class, DistCpConstants.CHECKSUM_MISMATCH_ERROR_MSG,
|
|
|
|
+ () -> DistCpUtils.compareFileLengthsAndChecksums(1024, fs,
|
|
|
|
+ srcWithChecksum1, null, fs, dstWithChecksum2,
|
|
|
|
+ false, 1024));
|
|
|
|
|
|
// checksums mismatched but skipped
|
|
// checksums mismatched but skipped
|
|
- DistCpUtils.compareFileLengthsAndChecksums(fs, srcWithChecksum1,
|
|
|
|
- null, fs, dstWithChecksum2, true);
|
|
|
|
|
|
+ DistCpUtils.compareFileLengthsAndChecksums(1024, fs, srcWithChecksum1,
|
|
|
|
+ null, fs, dstWithChecksum2, true, 1024);
|
|
}
|
|
}
|
|
|
|
|
|
private static Random rand = new Random();
|
|
private static Random rand = new Random();
|