Skip to content

Commit

Permalink
Take CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkumarchacko committed Sep 9, 2024
1 parent 16ff443 commit 2349976
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ public FSDataInputStream open(Path hadoopPath, int bufferSize) throws IOExceptio
public FSDataInputStream open(FileStatus status) throws IOException {
logger.atFine().log("openWithStatus(%s)", status);

if (!GoogleHadoopFileStatus.class.isAssignableFrom(status.getClass())) {
throw new IllegalArgumentException(
String.format(
"Expected status to be of type GoogleHadoopFileStatus, but found %s",
status.getClass()));
}

GoogleHadoopFileStatus fileStatus = (GoogleHadoopFileStatus) status;

checkPath(status.getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ public void testTotalTimeStatistics() throws IOException {
}

@Test
@SuppressWarnings("CheckReturnValue")
public void testStatus() throws Exception {
public void testFileOpenWithStatus() throws Exception {
URI bucketName = new URI("gs://read-test-bucket/");
URI failureBucketName = new URI("gs://read-test-bucket-other/");

Expand All @@ -296,19 +295,31 @@ public void testStatus() throws Exception {
GoogleHadoopFileStatus fileStatus =
new GoogleHadoopFileStatus(
fileInfo, new Path(fileInfo.getPath()), 1, 2, FsPermission.getFileDefault(), "foo");
new GoogleHadoopFileSystem();
GoogleHadoopFileSystem fs = new GoogleHadoopFileSystem();
fs.initialize(bucketName, new Configuration());
fs.open(fileStatus);

fs.initialize(failureBucketName, new Configuration());

IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> fs.open(fileStatus));
assertThat(exception.getMessage())
.isEqualTo(
"Wrong bucket: read-test-bucket, in path: gs://read-test-bucket/bar/test/object, expected bucket: read-test-bucket-other");
fs.close();
try (GoogleHadoopFileSystem fs = new GoogleHadoopFileSystem()) {
fs.initialize(bucketName, new Configuration());
fs.open(fileStatus);

fs.initialize(failureBucketName, new Configuration());

IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> fs.open(fileStatus));
assertThat(exception.getMessage())
.isEqualTo(
"Wrong bucket: read-test-bucket, in path: gs://read-test-bucket/bar/test/object, expected bucket: read-test-bucket-other");
}
}

@Test
public void testFileOpenWithStatusInvalidType() throws Exception {
try (GoogleHadoopFileSystem fs = new GoogleHadoopFileSystem()) {
fs.initialize(new URI("gs://read-test-bucket/"), new Configuration());

IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> fs.open(new FileStatus()));
assertThat(exception.getMessage())
.isEqualTo(
"Expected status to be of type GoogleHadoopFileStatus, but found class org.apache.hadoop.fs.FileStatus");
}
}

// -----------------------------------------------------------------
Expand Down

0 comments on commit 2349976

Please sign in to comment.