smengcl commented on a change in pull request #1791:
URL: https://github.com/apache/ozone/pull/1791#discussion_r556756818
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java
##########
@@ -107,17 +107,68 @@ public TestOzoneFileSystem(boolean setDefaultFs, boolean
enableOMRatis) {
private static final Logger LOG =
LoggerFactory.getLogger(TestOzoneFileSystem.class);
- private boolean enabledFileSystemPaths;
- private boolean omRatisEnabled;
+ private static boolean enabledFileSystemPaths;
+ private static boolean omRatisEnabled;
- private MiniOzoneCluster cluster;
- private FileSystem fs;
- private OzoneFileSystem o3fs;
- private String volumeName;
- private String bucketName;
- private int rootItemCount;
- private Trash trash;
+ private static MiniOzoneCluster cluster;
+ private static FileSystem fs;
+ private static OzoneFileSystem o3fs;
+ private static String volumeName;
+ private static String bucketName;
+ private static Trash trash;
+ @BeforeClass
+ public static void init() throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setInt(FS_TRASH_INTERVAL_KEY, 1);
+ conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, omRatisEnabled);
+ conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
+ enabledFileSystemPaths);
+ cluster = MiniOzoneCluster.newBuilder(conf)
+ .setNumDatanodes(3)
+ .build();
+ cluster.waitForClusterToBeReady();
+
+ // create a volume and a bucket to be used by OzoneFileSystem
+ OzoneBucket bucket = TestDataUtil.createVolumeAndBucket(cluster);
+ volumeName = bucket.getVolumeName();
+ bucketName = bucket.getName();
+
+ String rootPath = String.format("%s://%s.%s/",
+ OzoneConsts.OZONE_URI_SCHEME, bucketName, volumeName);
+
+ // Set the fs.defaultFS and start the filesystem
+ conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
+ // Set the number of keys to be processed during batch operate.
+ conf.setInt(OZONE_FS_ITERATE_BATCH_SIZE, 5);
+
+ fs = FileSystem.get(conf);
+ trash = new Trash(conf);
+ o3fs = (OzoneFileSystem) fs;
+ }
+
+ @AfterClass
+ public static void teardown() {
+ if (cluster != null) {
+ cluster.shutdown();
+ }
+ IOUtils.closeQuietly(fs);
+ }
+
+ @After
+ public void cleanup() {
+ try {
+ Path root = new Path("/");
+ FileStatus[] fileStatuses = fs.listStatus(root);
+ for (FileStatus fileStatus : fileStatuses) {
+ fs.delete(fileStatus.getPath(), true);
+ }
+ }catch (IOException ex){
Review comment:
style nit: add spaces: `} catch (IOException ex) {`
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java
##########
@@ -187,119 +236,46 @@ public void testMakeDirsWithAnExistingDirectoryPath()
throws Exception {
Path subdir = new Path("/d1/d2/");
boolean status = fs.mkdirs(subdir);
assertTrue("Shouldn't send error if dir exists", status);
- // Cleanup
- fs.delete(new Path("/d1"), true);
}
+ @Test
public void testCreateWithInvalidPaths() throws Exception {
+ // Test for path with ..
Path parent = new Path("../../../../../d1/d2/");
Path file1 = new Path(parent, "key1");
checkInvalidPath(file1);
+ // Test for path with :
file1 = new Path("/:/:");
checkInvalidPath(file1);
+
+ // Test for path with scheme and authority.
+ file1 = new Path(fs.getUri() + "/:/:");
+ checkInvalidPath(file1);
}
private void checkInvalidPath(Path path) throws Exception {
- FSDataOutputStream outputStream = null;
- try {
- outputStream = fs.create(path, false);
+ try{
+ LambdaTestUtils.intercept(InvalidPathException.class, "Invalid path
Name",
+ () -> fs.create(path, false));
+ }catch (AssertionError e){
Review comment:
same nit: `} catch (AssertionError e) {`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]