anujmodi2021 commented on code in PR #7880: URL: https://github.com/apache/hadoop/pull/7880#discussion_r2287443157
########## hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestFileSystemInitialization.java: ########## @@ -81,21 +89,123 @@ public void testFileSystemCapabilities() throws Throwable { final Path p = new Path("}"); // etags always present - Assertions.assertThat(fs.hasPathCapability(p, ETAGS_AVAILABLE)) + assertThat(fs.hasPathCapability(p, ETAGS_AVAILABLE)) .describedAs("path capability %s in %s", ETAGS_AVAILABLE, fs) .isTrue(); // readahead always correct - Assertions.assertThat(fs.hasPathCapability(p, CAPABILITY_SAFE_READAHEAD)) + assertThat(fs.hasPathCapability(p, CAPABILITY_SAFE_READAHEAD)) .describedAs("path capability %s in %s", CAPABILITY_SAFE_READAHEAD, fs) .isTrue(); // etags-over-rename and ACLs are either both true or both false. final boolean etagsAcrossRename = fs.hasPathCapability(p, ETAGS_PRESERVED_IN_RENAME); final boolean acls = fs.hasPathCapability(p, FS_ACLS); - Assertions.assertThat(etagsAcrossRename) + assertThat(etagsAcrossRename) .describedAs("capabilities %s=%s and %s=%s in %s", ETAGS_PRESERVED_IN_RENAME, etagsAcrossRename, FS_ACLS, acls, fs) .isEqualTo(acls); } + + /** + * Test that the AzureBlobFileSystem close without init works + * @throws Exception if an error occurs + */ + @Test + public void testABFSCloseWithoutInit() throws Exception { + AzureBlobFileSystem fs = new AzureBlobFileSystem(); + assertThat(fs.isClosed()).isTrue(); + fs.close(); + fs.initialize(this.getFileSystem().getUri(), getRawConfiguration()); + assertThat(fs.isClosed()).isFalse(); + fs.close(); + assertThat(fs.isClosed()).isTrue(); + } + + /** + * Test that the AzureBlobFileSystem throws an exception + * when trying to perform an operation without initialization. + * @throws Exception if an error occurs + */ + @Test + public void testABFSUninitializedFileSystem() throws Exception { + AzureBlobFileSystem fs = new AzureBlobFileSystem(); + assertThat(fs.isClosed()).isTrue(); + Path testPath = new Path("testPath"); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + fs::toString); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.open(testPath, ONE_MB)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.create(testPath, FsPermission.getDefault(), false, ONE_MB, + fs.getDefaultReplication(testPath), ONE_MB, null)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.createNonRecursive(testPath, FsPermission.getDefault(), false, ONE_MB, + fs.getDefaultReplication(testPath), ONE_MB, null)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.append(testPath, ONE_MB, null)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.rename(testPath, testPath)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.delete(testPath, true)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.listStatus(testPath)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.mkdirs(testPath, FsPermission.getDefault())); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.getFileStatus(testPath)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.breakLease(testPath)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.makeQualified(testPath)); + + intercept(IllegalStateException.class, ERR_INVALID_ABFS_STATE, + () -> fs.setOwner(testPath, "", "")); Review Comment: Will take up this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org