Skip to content

Commit 3f638c2

Browse files
HADOOP-19688. S3A: ITestS3ACommitterMRJob failing on JUnit5 (#7968)
Fixes the ITestS3ACommitterMRJob test suite to work on JUnit 5, through changes in local test directory creation and use. MapReduce FileInputFormat provides some more information when raising NPEs from null block location lists. Contributed by Steve Loughran
1 parent 1b152a4 commit 3f638c2

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/lib/input/FileInputFormat.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.slf4j.Logger;
5050
import org.slf4j.LoggerFactory;
5151

52+
import static java.util.Objects.requireNonNull;
5253
import static org.apache.hadoop.fs.FileUtil.maybeIgnoreMissingDirectory;
5354

5455
/**
@@ -455,10 +456,17 @@ public List<InputSplit> getSplits(JobContext job) throws IOException {
455456
if (length != 0) {
456457
BlockLocation[] blkLocations;
457458
if (file instanceof LocatedFileStatus) {
458-
blkLocations = ((LocatedFileStatus) file).getBlockLocations();
459+
blkLocations = requireNonNull(
460+
((LocatedFileStatus) file).getBlockLocations(),
461+
() -> String.format("No block locations in LocatedFileStatus %s; length=%d",
462+
file, length));
463+
459464
} else {
460465
FileSystem fs = path.getFileSystem(job.getConfiguration());
461-
blkLocations = fs.getFileBlockLocations(file, 0, length);
466+
blkLocations = requireNonNull(fs.getFileBlockLocations(file, 0, length), () ->
467+
String.format("No block locations returned from getFileBlockLocations(%s, 0, %d)"
468+
+ "; status=%s",
469+
path, length, file));
462470
}
463471
if (isSplitable(job, path)) {
464472
long blockSize = file.getBlockSize();

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3ALocatedFileStatus.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ public S3AFileStatus toS3AFileStatus() {
9595

9696
@Override
9797
public String toString() {
98-
final StringBuilder sb = new StringBuilder(
99-
super.toString());
98+
final StringBuilder sb = new StringBuilder("S3ALocatedFileStatus{");
99+
sb.append(super.toString());
100100
sb.append("[eTag='").
101101
append(eTag != null ? eTag : "")
102102
.append('\'');
103103
sb.append(", versionId='")
104104
.append(versionId != null ? versionId: "")
105105
.append('\'');
106-
sb.append(']');
106+
sb.append('}');
107107
return sb.toString();
108108
}
109109
}

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/integration/ITestS3ACommitterMRJob.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.FileNotFoundException;
2323
import java.io.FileOutputStream;
2424
import java.io.IOException;
25+
import java.net.URI;
2526
import java.net.URL;
2627
import java.nio.charset.StandardCharsets;
2728
import java.util.ArrayList;
@@ -74,6 +75,7 @@
7475

7576
import static org.apache.hadoop.fs.s3a.S3ATestUtils.disableFilesystemCaching;
7677
import static org.apache.hadoop.fs.s3a.S3ATestUtils.lsR;
78+
import static org.apache.hadoop.fs.s3a.S3ATestUtils.removeBaseAndBucketOverrides;
7779
import static org.apache.hadoop.fs.s3a.S3AUtils.applyLocatedFiles;
7880
import static org.apache.hadoop.fs.s3a.commit.CommitConstants.FS_S3A_COMMITTER_STAGING_TMP_PATH;
7981
import static org.apache.hadoop.fs.s3a.commit.CommitConstants.MAGIC_PATH_PREFIX;
@@ -82,6 +84,7 @@
8284
import static org.apache.hadoop.fs.s3a.commit.staging.Paths.getMultipartUploadCommitsDirectory;
8385
import static org.apache.hadoop.fs.s3a.commit.staging.StagingCommitterConstants.STAGING_UPLOADS;
8486
import static org.apache.hadoop.mapred.JobConf.MAPRED_TASK_ENV;
87+
import static org.apache.hadoop.mapreduce.lib.input.FileInputFormat.LIST_STATUS_NUM_THREADS;
8588

8689
/**
8790
* Test an MR Job with all the different committers.
@@ -105,24 +108,24 @@
105108
* <li>
106109
* The test suites are declared to be executed in ascending order, so
107110
* that for a specific binding, the order is
108-
* {@link #test_000(CommitterTestBinding)},
109-
* {@link #test_100(CommitterTestBinding)}
110-
* {@link #test_200_execute(CommitterTestBinding, java.nio.file.Path)} and finally
111-
* {@link #test_500(CommitterTestBinding)}.
111+
* {@link #test_000()},
112+
* {@link #test_100()}
113+
* {@link #test_200_execute()} and finally
114+
* {@link #test_500()}.
112115
* </li>
113116
* <li>
114-
* {@link #test_000(CommitterTestBinding)} calls
117+
* {@link #test_000()} calls
115118
* {@link CommitterTestBinding#validate()} to
116119
* as to validate the state of the committer. This is primarily to
117120
* verify that the binding setup mechanism is working.
118121
* </li>
119122
* <li>
120-
* {@link #test_100(CommitterTestBinding)} is relayed to
123+
* {@link #test_100()} is relayed to
121124
* {@link CommitterTestBinding#test_100()},
122125
* for any preflight tests.
123126
* </li>
124127
* <li>
125-
* The {@link #test_200_execute(CommitterTestBinding, java.nio.file.Path)}
128+
* The {@link #test_200_execute()}
126129
* test runs the MR job for that
127130
* particular binding with standard reporting and verification of the
128131
* outcome.
@@ -165,6 +168,9 @@ public static Collection<Object[]> params() {
165168
*/
166169
private final CommitterTestBinding committerTestBinding;
167170

171+
@TempDir
172+
private java.nio.file.Path localFilesDir;
173+
168174
/**
169175
* Parameterized constructor.
170176
* @param committerTestBinding binding for the test.
@@ -186,6 +192,9 @@ public void setup() throws Exception {
186192
protected Configuration createConfiguration() {
187193
Configuration conf = super.createConfiguration();
188194
disableFilesystemCaching(conf);
195+
removeBaseAndBucketOverrides(conf,
196+
LIST_STATUS_NUM_THREADS);
197+
conf.setInt(LIST_STATUS_NUM_THREADS, 16);
189198
return conf;
190199
}
191200

@@ -208,9 +217,9 @@ public void test_100() throws Throwable {
208217
}
209218

210219
@Test
211-
public void test_200_execute(
212-
@TempDir java.nio.file.Path localFilesDir) throws Exception {
220+
public void test_200_execute() throws Exception {
213221
describe("Run an MR with committer %s", committerName());
222+
LOG.info("Local Temp directory is {}", localFilesDir);
214223

215224
S3AFileSystem fs = getFileSystem();
216225
// final dest is in S3A
@@ -253,8 +262,10 @@ public void test_200_execute(
253262
jobConf.set(FS_S3A_COMMITTER_UUID, commitUUID);
254263

255264
mrJob.setInputFormatClass(TextInputFormat.class);
256-
FileInputFormat.addInputPath(mrJob,
257-
new Path(localFilesDir.getRoot().toUri()));
265+
266+
final URI inputPath = localFilesDir.toUri();
267+
LOG.info("Job input path {}", inputPath);
268+
FileInputFormat.addInputPath(mrJob, new Path(inputPath));
258269

259270
mrJob.setMapperClass(MapClass.class);
260271
mrJob.setNumReduceTasks(0);

0 commit comments

Comments
 (0)