53
53
import java .util .*;
54
54
55
55
import static org .apache .hadoop .fs .contract .ContractTestUtils .*;
56
+ import static org .apache .hadoop .tools .DistCpConstants .CONF_LABEL_TARGET_FINAL_PATH ;
57
+ import static org .apache .hadoop .tools .DistCpConstants .CONF_LABEL_TARGET_WORK_PATH ;
56
58
import static org .apache .hadoop .tools .util .TestDistCpUtils .*;
57
59
58
60
public class TestCopyCommitter {
@@ -160,10 +162,10 @@ public void testPreserveStatus() throws IOException {
160
162
context .setTargetPathExists (false );
161
163
162
164
CopyListing listing = new GlobbedCopyListing (conf , CREDENTIALS );
163
- Path listingFile = new Path ("/tmp1/" + String . valueOf ( rand .nextLong () ));
165
+ Path listingFile = new Path ("/tmp1/" + rand .nextLong ());
164
166
listing .buildListing (listingFile , context );
165
167
166
- conf .set (DistCpConstants . CONF_LABEL_TARGET_WORK_PATH , targetBase );
168
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , targetBase );
167
169
168
170
committer .commitJob (jobContext );
169
171
checkDirectoryPermissions (fs , targetBase , sourcePerm );
@@ -179,6 +181,45 @@ public void testPreserveStatus() throws IOException {
179
181
180
182
}
181
183
184
+ @ Test
185
+ public void testPreserveStatusWithAtomicCommit () throws IOException {
186
+ TaskAttemptContext taskAttemptContext = getTaskAttemptContext (config );
187
+ JobContext jobContext = new JobContextImpl (
188
+ taskAttemptContext .getConfiguration (),
189
+ taskAttemptContext .getTaskAttemptID ().getJobID ());
190
+ Configuration conf = jobContext .getConfiguration ();
191
+ String sourceBase ;
192
+ String workBase ;
193
+ String targetBase ;
194
+ FileSystem fs = null ;
195
+ try {
196
+ OutputCommitter committer = new CopyCommitter (null , taskAttemptContext );
197
+ fs = FileSystem .get (conf );
198
+ FsPermission sourcePerm = new FsPermission ((short ) 511 );
199
+ FsPermission initialPerm = new FsPermission ((short ) 448 );
200
+ sourceBase = TestDistCpUtils .createTestSetup (fs , sourcePerm );
201
+ workBase = TestDistCpUtils .createTestSetup (fs , initialPerm );
202
+ targetBase = "/tmp1/" + rand .nextLong ();
203
+ final DistCpOptions options = new DistCpOptions .Builder (
204
+ Collections .singletonList (new Path (sourceBase )), new Path ("/out" ))
205
+ .preserve (FileAttribute .PERMISSION ).build ();
206
+ options .appendToConf (conf );
207
+ final DistCpContext context = new DistCpContext (options );
208
+ context .setTargetPathExists (false );
209
+ CopyListing listing = new GlobbedCopyListing (conf , CREDENTIALS );
210
+ Path listingFile = new Path ("/tmp1/" + rand .nextLong ());
211
+ listing .buildListing (listingFile , context );
212
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , targetBase );
213
+ conf .set (CONF_LABEL_TARGET_WORK_PATH , workBase );
214
+ conf .setBoolean (DistCpConstants .CONF_LABEL_ATOMIC_COPY , true );
215
+ committer .commitJob (jobContext );
216
+ checkDirectoryPermissions (fs , targetBase , sourcePerm );
217
+ } finally {
218
+ TestDistCpUtils .delete (fs , "/tmp1" );
219
+ conf .unset (DistCpConstants .CONF_LABEL_PRESERVE_STATUS );
220
+ }
221
+ }
222
+
182
223
@ Test
183
224
public void testDeleteMissing () throws IOException {
184
225
TaskAttemptContext taskAttemptContext = getTaskAttemptContext (config );
@@ -207,8 +248,8 @@ public void testDeleteMissing() throws IOException {
207
248
Path listingFile = new Path ("/tmp1/" + String .valueOf (rand .nextLong ()));
208
249
listing .buildListing (listingFile , context );
209
250
210
- conf .set (DistCpConstants . CONF_LABEL_TARGET_WORK_PATH , targetBase );
211
- conf .set (DistCpConstants . CONF_LABEL_TARGET_FINAL_PATH , targetBase );
251
+ conf .set (CONF_LABEL_TARGET_WORK_PATH , targetBase );
252
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , targetBase );
212
253
213
254
committer .commitJob (jobContext );
214
255
verifyFoldersAreInSync (fs , targetBase , sourceBase );
@@ -256,8 +297,8 @@ public void testPreserveTimeWithDeleteMiss() throws IOException {
256
297
Path listingFile = new Path ("/tmp1/" + String .valueOf (rand .nextLong ()));
257
298
listing .buildListing (listingFile , context );
258
299
259
- conf .set (DistCpConstants . CONF_LABEL_TARGET_WORK_PATH , targetBase );
260
- conf .set (DistCpConstants . CONF_LABEL_TARGET_FINAL_PATH , targetBase );
300
+ conf .set (CONF_LABEL_TARGET_WORK_PATH , targetBase );
301
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , targetBase );
261
302
262
303
Path sourceListing = new Path (
263
304
conf .get (DistCpConstants .CONF_LABEL_LISTING_FILE_PATH ));
@@ -320,8 +361,8 @@ public void testDeleteMissingFlatInterleavedFiles() throws IOException {
320
361
Path listingFile = new Path ("/tmp1/" + String .valueOf (rand .nextLong ()));
321
362
listing .buildListing (listingFile , context );
322
363
323
- conf .set (DistCpConstants . CONF_LABEL_TARGET_WORK_PATH , targetBase );
324
- conf .set (DistCpConstants . CONF_LABEL_TARGET_FINAL_PATH , targetBase );
364
+ conf .set (CONF_LABEL_TARGET_WORK_PATH , targetBase );
365
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , targetBase );
325
366
326
367
committer .commitJob (jobContext );
327
368
verifyFoldersAreInSync (fs , targetBase , sourceBase );
@@ -353,8 +394,8 @@ public void testAtomicCommitMissingFinal() throws IOException {
353
394
fs = FileSystem .get (conf );
354
395
fs .mkdirs (new Path (workPath ));
355
396
356
- conf .set (DistCpConstants . CONF_LABEL_TARGET_WORK_PATH , workPath );
357
- conf .set (DistCpConstants . CONF_LABEL_TARGET_FINAL_PATH , finalPath );
397
+ conf .set (CONF_LABEL_TARGET_WORK_PATH , workPath );
398
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , finalPath );
358
399
conf .setBoolean (DistCpConstants .CONF_LABEL_ATOMIC_COPY , true );
359
400
360
401
assertPathExists (fs , "Work path" , new Path (workPath ));
@@ -391,8 +432,8 @@ public void testAtomicCommitExistingFinal() throws IOException {
391
432
fs .mkdirs (new Path (workPath ));
392
433
fs .mkdirs (new Path (finalPath ));
393
434
394
- conf .set (DistCpConstants . CONF_LABEL_TARGET_WORK_PATH , workPath );
395
- conf .set (DistCpConstants . CONF_LABEL_TARGET_FINAL_PATH , finalPath );
435
+ conf .set (CONF_LABEL_TARGET_WORK_PATH , workPath );
436
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , finalPath );
396
437
conf .setBoolean (DistCpConstants .CONF_LABEL_ATOMIC_COPY , true );
397
438
398
439
assertPathExists (fs , "Work path" , new Path (workPath ));
@@ -463,8 +504,8 @@ private void testCommitWithChecksumMismatch(boolean skipCrc)
463
504
+ String .valueOf (rand .nextLong ()));
464
505
listing .buildListing (listingFile , context );
465
506
466
- conf .set (DistCpConstants . CONF_LABEL_TARGET_WORK_PATH , targetBase );
467
- conf .set (DistCpConstants . CONF_LABEL_TARGET_FINAL_PATH , targetBase );
507
+ conf .set (CONF_LABEL_TARGET_WORK_PATH , targetBase );
508
+ conf .set (CONF_LABEL_TARGET_FINAL_PATH , targetBase );
468
509
469
510
OutputCommitter committer = new CopyCommitter (
470
511
null , taskAttemptContext );
0 commit comments