|
@@ -20,15 +20,19 @@ package org.apache.hadoop.fs.azurebfs;
|
|
|
|
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
+import org.junit.Assume;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.FileAlreadyExistsException;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
|
|
|
|
-import static org.apache.hadoop.fs.contract.ContractTestUtils.assertMkdirs;
|
|
|
|
-
|
|
|
|
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.CONNECTIONS_MADE;
|
|
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.CONNECTIONS_MADE;
|
|
|
|
+import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ENABLE_MKDIR_OVERWRITE;
|
|
|
|
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.DEFAULT_FS_AZURE_ENABLE_MKDIR_OVERWRITE;
|
|
|
|
+import static org.apache.hadoop.fs.contract.ContractTestUtils.assertMkdirs;
|
|
|
|
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Test mkdir operation.
|
|
* Test mkdir operation.
|
|
@@ -41,12 +45,44 @@ public class ITestAzureBlobFileSystemMkDir extends AbstractAbfsIntegrationTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testCreateDirWithExistingDir() throws Exception {
|
|
public void testCreateDirWithExistingDir() throws Exception {
|
|
|
|
+ Assume.assumeTrue(DEFAULT_FS_AZURE_ENABLE_MKDIR_OVERWRITE || !getFileSystem()
|
|
|
|
+ .getIsNamespaceEnabled());
|
|
final AzureBlobFileSystem fs = getFileSystem();
|
|
final AzureBlobFileSystem fs = getFileSystem();
|
|
Path path = new Path("testFolder");
|
|
Path path = new Path("testFolder");
|
|
assertMkdirs(fs, path);
|
|
assertMkdirs(fs, path);
|
|
assertMkdirs(fs, path);
|
|
assertMkdirs(fs, path);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void testMkdirExistingDirOverwriteFalse() throws Exception {
|
|
|
|
+ Assume.assumeFalse("Ignore test until default overwrite is set to false",
|
|
|
|
+ DEFAULT_FS_AZURE_ENABLE_MKDIR_OVERWRITE);
|
|
|
|
+ Assume.assumeTrue("Ignore test for Non-HNS accounts",
|
|
|
|
+ getFileSystem().getIsNamespaceEnabled());
|
|
|
|
+ //execute test only for HNS account with default overwrite=false
|
|
|
|
+ Configuration config = new Configuration(this.getRawConfiguration());
|
|
|
|
+ config.set(FS_AZURE_ENABLE_MKDIR_OVERWRITE, Boolean.toString(false));
|
|
|
|
+ AzureBlobFileSystem fs = getFileSystem(config);
|
|
|
|
+ Path path = new Path("testFolder");
|
|
|
|
+ assertMkdirs(fs, path); //checks that mkdirs returns true
|
|
|
|
+ long timeCreated = fs.getFileStatus(path).getModificationTime();
|
|
|
|
+ assertMkdirs(fs, path); //call to existing dir should return success
|
|
|
|
+ assertEquals("LMT should not be updated for existing dir", timeCreated,
|
|
|
|
+ fs.getFileStatus(path).getModificationTime());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void createDirWithExistingFilename() throws Exception {
|
|
|
|
+ Assume.assumeFalse("Ignore test until default overwrite is set to false",
|
|
|
|
+ DEFAULT_FS_AZURE_ENABLE_MKDIR_OVERWRITE && getFileSystem()
|
|
|
|
+ .getIsNamespaceEnabled());
|
|
|
|
+ final AzureBlobFileSystem fs = getFileSystem();
|
|
|
|
+ Path path = new Path("testFilePath");
|
|
|
|
+ fs.create(path);
|
|
|
|
+ assertTrue(fs.getFileStatus(path).isFile());
|
|
|
|
+ intercept(FileAlreadyExistsException.class, () -> fs.mkdirs(path));
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testCreateRoot() throws Exception {
|
|
public void testCreateRoot() throws Exception {
|
|
assertMkdirs(getFileSystem(), new Path("/"));
|
|
assertMkdirs(getFileSystem(), new Path("/"));
|