Add test cases for making temp dir under both exist and non-exist folder
@@ -17,6 +17,7 @@ import com.google.common.io.Files;
import org.apache.hadoop.fs.Path;
import org.testng.annotations.Test;
+import java.io.File;
import java.util.UUID;
import static com.facebook.presto.hive.HiveTestUtils.SESSION;
@@ -31,7 +32,6 @@ import static org.testng.Assert.fail;
public class TestHiveWriteUtils
{
- //HdfsContext CONTEXT = new HdfsContext(new ConnectorIdentity("test", Optional.empty(), Optional.empty()));
private static final HdfsContext CONTEXT = new HdfsContext(SESSION, "test_schema");
@Test
@@ -61,9 +61,11 @@ public class TestHiveWriteUtils
HdfsEnvironment hdfsEnvironment = createTestHdfsEnvironment(new HiveClientConfig(), new MetastoreClientConfig());
Path viewfsPath = new Path("viewfs://ns-default/test-dir");
- // ViewFS check requires the mount point config
- hdfsEnvironment.getConfiguration(CONTEXT, viewfsPath).set("fs.viewfs.mounttable.ns-default.link./test-dir", "file://" + Files.createTempDir());
+ File storageDir = Files.createTempDir();
+ // ViewFS check requires the mount point config, using system temporary folder as the storage
+ hdfsEnvironment.getConfiguration(CONTEXT, viewfsPath).set("fs.viewfs.mounttable.ns-default.link./test-dir", "file://" + storageDir);
+ //Make temporary folder under an existing data folder without staging folder ".hive-staging"
Path temporaryPath = createTemporaryPath(SESSION, CONTEXT, hdfsEnvironment, viewfsPath);
assertEquals(temporaryPath.getParent().toString(), "viewfs://ns-default/test-dir/.hive-staging");
@@ -73,6 +75,27 @@ public class TestHiveWriteUtils
catch (IllegalArgumentException e) {
fail("Expected a UUID folder name ");
}
+
+ //Make temporary folder under an existing data folder with an existing staging folder ".hive-staging"
+ temporaryPath = createTemporaryPath(SESSION, CONTEXT, hdfsEnvironment, viewfsPath);
+
+ assertEquals(temporaryPath.getParent().toString(), "viewfs://ns-default/test-dir/.hive-staging");
+ try {
+ UUID.fromString(temporaryPath.getName());
+ }
+ catch (IllegalArgumentException e) {
+ fail("Expected a UUID folder name ");
+ }
+
+ //Make temporary folder under a non-existing data folder (for new tables), it would use the temporary folder of the parent
+ temporaryPath = createTemporaryPath(SESSION, CONTEXT, hdfsEnvironment, new Path(viewfsPath, "non-existing"));
+ assertEquals(temporaryPath.getParent().toString(), "viewfs://ns-default/test-dir/.hive-staging");
+ try {
+ UUID.fromString(temporaryPath.getName());
+ }
+ catch (IllegalArgumentException e) {
+ fail("Expected a UUID folder name ");
+ }
}
@Test void testCreateTemporaryPathOnNonViewFS()
