|
@@ -24,7 +24,16 @@ import static junit.framework.Assert.assertNotSame;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.security.UserGroupInformation;
|
|
|
|
+import org.apache.hadoop.security.token.Token;
|
|
|
|
+import org.apache.hadoop.security.token.TokenIdentifier;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
+import java.security.PrivilegedAction;
|
|
|
|
+import java.security.PrivilegedActionException;
|
|
|
|
+import java.security.PrivilegedExceptionAction;
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
public class TestFileSystemCaching {
|
|
public class TestFileSystemCaching {
|
|
|
|
|
|
@@ -46,5 +55,60 @@ public class TestFileSystemCaching {
|
|
FileSystem fs2 = FileSystem.get(new URI("uncachedfile://a"), conf);
|
|
FileSystem fs2 = FileSystem.get(new URI("uncachedfile://a"), conf);
|
|
assertNotSame(fs1, fs2);
|
|
assertNotSame(fs1, fs2);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ @Test
|
|
|
|
+ public <T extends TokenIdentifier> void testCacheForUgi() throws Exception {
|
|
|
|
+ final Configuration conf = new Configuration();
|
|
|
|
+ conf.set("fs.cachedfile.impl", conf.get("fs.file.impl"));
|
|
|
|
+ UserGroupInformation ugiA = UserGroupInformation.createRemoteUser("foo");
|
|
|
|
+ UserGroupInformation ugiB = UserGroupInformation.createRemoteUser("bar");
|
|
|
|
+ FileSystem fsA = ugiA.doAs(new PrivilegedExceptionAction<FileSystem>() {
|
|
|
|
+ public FileSystem run() throws Exception {
|
|
|
|
+ return FileSystem.get(new URI("cachedfile://a"), conf);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ FileSystem fsA1 = ugiA.doAs(new PrivilegedExceptionAction<FileSystem>() {
|
|
|
|
+ public FileSystem run() throws Exception {
|
|
|
|
+ return FileSystem.get(new URI("cachedfile://a"), conf);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //Since the UGIs are the same, we should have the same filesystem for both
|
|
|
|
+ assertSame(fsA, fsA1);
|
|
|
|
+
|
|
|
|
+ FileSystem fsB = ugiB.doAs(new PrivilegedExceptionAction<FileSystem>() {
|
|
|
|
+ public FileSystem run() throws Exception {
|
|
|
|
+ return FileSystem.get(new URI("cachedfile://a"), conf);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //Since the UGIs are different, we should end up with different filesystems
|
|
|
|
+ //corresponding to the two UGIs
|
|
|
|
+ assertNotSame(fsA, fsB);
|
|
|
|
+
|
|
|
|
+ Token<T> t1 = mock(Token.class);
|
|
|
|
+ ugiA = UserGroupInformation.createRemoteUser("foo");
|
|
|
|
+ ugiA.addToken(t1);
|
|
|
|
+
|
|
|
|
+ fsA = ugiA.doAs(new PrivilegedExceptionAction<FileSystem>() {
|
|
|
|
+ public FileSystem run() throws Exception {
|
|
|
|
+ return FileSystem.get(new URI("cachedfile://a"), conf);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //Although the users in the UGI are same, ugiA has tokens in it, and
|
|
|
|
+ //we should end up with different filesystems corresponding to the two UGIs
|
|
|
|
+ assertNotSame(fsA, fsA1);
|
|
|
|
+
|
|
|
|
+ ugiA = UserGroupInformation.createRemoteUser("foo");
|
|
|
|
+ ugiA.addToken(t1);
|
|
|
|
+
|
|
|
|
+ fsA1 = ugiA.doAs(new PrivilegedExceptionAction<FileSystem>() {
|
|
|
|
+ public FileSystem run() throws Exception {
|
|
|
|
+ return FileSystem.get(new URI("cachedfile://a"), conf);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //Now the users in the UGI are the same, and they also have the same token.
|
|
|
|
+ //We should have the same filesystem for both
|
|
|
|
+ assertSame(fsA, fsA1);
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|