From 93036d64e2625f82b56d0bff9fb97dbea68e1d8a Mon Sep 17 00:00:00 2001 From: Mark Wagner Date: Wed, 28 Feb 2018 10:34:59 -0800 Subject: [PATCH] Add test for FileSystem caching --- .../presto/hive/TestFileSystemCache.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 presto-hive/src/test/java/com/facebook/presto/hive/TestFileSystemCache.java diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/TestFileSystemCache.java b/presto-hive/src/test/java/com/facebook/presto/hive/TestFileSystemCache.java new file mode 100644 index 000000000000..177d72503a24 --- /dev/null +++ b/presto-hive/src/test/java/com/facebook/presto/hive/TestFileSystemCache.java @@ -0,0 +1,56 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.hive; + +import com.facebook.presto.hive.authentication.ImpersonatingHdfsAuthentication; +import com.facebook.presto.hive.authentication.SimpleHadoopAuthentication; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.testng.annotations.Test; + +import java.io.IOException; + +import static org.testng.Assert.assertNotSame; +import static org.testng.Assert.assertSame; + +public class TestFileSystemCache +{ + @Test + public void testFileSystemCache() + throws IOException + { + ImpersonatingHdfsAuthentication auth = new ImpersonatingHdfsAuthentication(new SimpleHadoopAuthentication()); + HdfsEnvironment environment = + new HdfsEnvironment( + new HiveHdfsConfiguration(new HdfsConfigurationUpdater(new HiveClientConfig())), + new HiveClientConfig(), + auth); + FileSystem fs1 = getFileSystem(environment, "user"); + FileSystem fs2 = getFileSystem(environment, "user"); + assertSame(fs1, fs2); + + FileSystem fs3 = getFileSystem(environment, "other_user"); + assertNotSame(fs1, fs3); + + FileSystem fs4 = getFileSystem(environment, "other_user"); + assertSame(fs3, fs4); + } + + private FileSystem getFileSystem(HdfsEnvironment environment, String user) + throws IOException + { + return environment.getFileSystem(user, new Path("/"), new Configuration(false)); + } +}