Skip to content

Commit

Permalink
Add test for FileSystem caching
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnermarkd authored and dain committed Aug 31, 2018
1 parent 110a27d commit 93036d6
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 93036d6

Please sign in to comment.