2929import static org .assertj .core .api .Assertions .assertThat ;
3030
3131import java .io .IOException ;
32+ import java .util .Arrays ;
3233import java .util .Collections ;
3334import java .util .HashMap ;
3435import java .util .Map ;
36+ import java .util .stream .Collectors ;
3537
3638import org .apache .hadoop .conf .Configuration ;
3739import org .apache .hadoop .fs .FileStatus ;
5254import org .apache .hadoop .tools .DistCpOptions ;
5355import org .apache .hadoop .tools .SimpleCopyListing ;
5456import org .apache .hadoop .tools .mapred .CopyMapper ;
55- import org .apache .hadoop .tools . util .DistCpTestUtils ;
57+ import org .apache .hadoop .util .ToolRunner ;
5658import org .apache .hadoop .util .functional .RemoteIterators ;
5759
60+ import org .assertj .core .api .Assertions ;
5861import org .junit .jupiter .api .AfterEach ;
5962import org .junit .jupiter .api .BeforeEach ;
6063import org .junit .jupiter .api .Test ;
@@ -534,8 +537,7 @@ public void testLargeFilesFromRemote() throws Exception {
534537 public void testSetJobId () throws Exception {
535538 describe ("check jobId is set in the conf" );
536539 remoteFS .create (new Path (remoteDir , "file1" )).close ();
537- DistCpTestUtils
538- .assertRunDistCp (DistCpConstants .SUCCESS , remoteDir .toString (),
540+ assertRunDistCp (DistCpConstants .SUCCESS , remoteDir .toString (),
539541 localDir .toString (), getDefaultCLIOptionsOrNull (), conf );
540542 assertThat (conf .get (CONF_LABEL_DISTCP_JOB_ID ))
541543 .withFailMessage ("DistCp job id isn't set" )
@@ -719,7 +721,7 @@ public void testDistCpWithIterator() throws Exception {
719721 GenericTestUtils .LogCapturer .captureLogs (SimpleCopyListing .LOG );
720722
721723 String options = "-useiterator -update -delete" + getDefaultCLIOptions ();
722- DistCpTestUtils . assertRunDistCp (DistCpConstants .SUCCESS , source .toString (),
724+ assertRunDistCp (DistCpConstants .SUCCESS , source .toString (),
723725 dest .toString (), options , conf );
724726
725727 // Check the target listing was also done using iterator.
@@ -864,7 +866,7 @@ public void testDistCpWithFile() throws Exception {
864866 verifyPathExists (remoteFS , "" , source );
865867 verifyPathExists (localFS , "" , localDir );
866868
867- DistCpTestUtils . assertRunDistCp (DistCpConstants .SUCCESS , source .toString (),
869+ assertRunDistCp (DistCpConstants .SUCCESS , source .toString (),
868870 dest .toString (), getDefaultCLIOptionsOrNull (), conf );
869871
870872 assertThat (RemoteIterators .toList (localFS .listFiles (dest , true )))
@@ -889,7 +891,7 @@ public void testDistCpWithUpdateExistFile() throws Exception {
889891
890892 verifyPathExists (remoteFS , "" , source );
891893 verifyPathExists (localFS , "" , dest );
892- DistCpTestUtils . assertRunDistCp (DistCpConstants .SUCCESS , source .toString (),
894+ assertRunDistCp (DistCpConstants .SUCCESS , source .toString (),
893895 dest .toString (), "-delete -update" + getDefaultCLIOptions (), conf );
894896
895897 assertThat (RemoteIterators .toList (localFS .listFiles (dest , true )))
@@ -1015,4 +1017,37 @@ private void verifySkipAndCopyCounter(Job job,
10151017 .withFailMessage ("Mismatch in SKIP counter value" )
10161018 .isEqualTo (skipExpectedValue );
10171019 }
1020+
1021+ /**
1022+ * Runs distcp from src to dst, preserving XAttrs. Asserts the
1023+ * expected exit code.
1024+ *
1025+ * @param exitCode expected exit code
1026+ * @param src distcp src path
1027+ * @param dst distcp destination
1028+ * @param options distcp command line options
1029+ * @param conf Configuration to use
1030+ * @throws Exception if there is any error
1031+ */
1032+ public static void assertRunDistCp (int exitCode , String src , String dst ,
1033+ String options , Configuration conf )
1034+ throws Exception {
1035+ assertRunDistCp (exitCode , src , dst ,
1036+ options == null ? new String [0 ] : options .trim ().split (" " ), conf );
1037+ }
1038+
1039+ private static void assertRunDistCp (int exitCode , String src , String dst ,
1040+ String [] options , Configuration conf )
1041+ throws Exception {
1042+ DistCp distCp = new DistCp (conf , null );
1043+ String [] optsArr = new String [options .length + 2 ];
1044+ System .arraycopy (options , 0 , optsArr , 0 , options .length );
1045+ optsArr [optsArr .length - 2 ] = src ;
1046+ optsArr [optsArr .length - 1 ] = dst ;
1047+
1048+ Assertions .assertThat (ToolRunner .run (conf , distCp , optsArr ))
1049+ .describedAs ("Exit code of distcp %s" ,
1050+ Arrays .stream (optsArr ).collect (Collectors .joining (" " )))
1051+ .isEqualTo (exitCode );
1052+ }
10181053}
0 commit comments