Search in sources :

Example 6 with MockFileSystem

use of org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem in project hadoop by apache.

the class TestFileSystemTokens method testFsWithMyOwnExistsAndChildTokens.

@Test
public void testFsWithMyOwnExistsAndChildTokens() throws Exception {
    Credentials credentials = new Credentials();
    Text service1 = new Text("singleTokenFs1");
    Text service2 = new Text("singleTokenFs2");
    Text myService = new Text("multiTokenFs");
    Token<?> token = mock(Token.class);
    credentials.addToken(myService, token);
    MockFileSystem fs1 = createFileSystemForServiceName(service1);
    MockFileSystem fs2 = createFileSystemForServiceName(service2);
    MockFileSystem multiFs = createFileSystemForServiceName(myService, fs1, fs2);
    multiFs.addDelegationTokens(renewer, credentials);
    // we had added its token to credentials
    verifyTokenFetch(multiFs, false);
    verifyTokenFetch(fs1, true);
    verifyTokenFetch(fs2, true);
    assertEquals(3, credentials.numberOfTokens());
    assertSame(token, credentials.getToken(myService));
    assertNotNull(credentials.getToken(service1));
    assertNotNull(credentials.getToken(service2));
}
Also used : Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Example 7 with MockFileSystem

use of org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem in project hadoop by apache.

the class TestFileSystemTokens method testFsWithTokenExists.

@Test
public void testFsWithTokenExists() throws Exception {
    Credentials credentials = new Credentials();
    Text service = new Text("singleTokenFs");
    MockFileSystem fs = createFileSystemForServiceName(service);
    Token<?> token = mock(Token.class);
    credentials.addToken(service, token);
    fs.addDelegationTokens(renewer, credentials);
    verifyTokenFetch(fs, false);
    assertEquals(1, credentials.numberOfTokens());
    assertSame(token, credentials.getToken(service));
}
Also used : Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Example 8 with MockFileSystem

use of org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem in project hadoop by apache.

the class TestFileSystemTokens method testFsWithDuplicateChildren.

@Test
public void testFsWithDuplicateChildren() throws Exception {
    Credentials credentials = new Credentials();
    Text service = new Text("singleTokenFs1");
    MockFileSystem fs = createFileSystemForServiceName(service);
    MockFileSystem multiFs = createFileSystemForServiceName(null, fs, new FilterFileSystem(fs));
    multiFs.addDelegationTokens(renewer, credentials);
    verifyTokenFetch(multiFs, false);
    verifyTokenFetch(fs, true);
    assertEquals(1, credentials.numberOfTokens());
    assertNotNull(credentials.getToken(service));
}
Also used : Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Example 9 with MockFileSystem

use of org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem in project hadoop by apache.

the class TestTokenCache method testSingleTokenFetch.

@Test
public void testSingleTokenFetch() throws Exception {
    Configuration conf = new Configuration();
    conf.set(YarnConfiguration.RM_PRINCIPAL, "mapred/host@REALM");
    String renewer = Master.getMasterPrincipal(conf);
    Credentials credentials = new Credentials();
    final MockFileSystem fs = new MockFileSystem();
    final MockFileSystem mockFs = (MockFileSystem) fs.getRawFileSystem();
    when(mockFs.getCanonicalServiceName()).thenReturn("host:0");
    when(mockFs.getUri()).thenReturn(new URI("mockfs://host:0"));
    Path mockPath = mock(Path.class);
    when(mockPath.getFileSystem(conf)).thenReturn(mockFs);
    Path[] paths = new Path[] { mockPath, mockPath };
    when(mockFs.addDelegationTokens("me", credentials)).thenReturn(null);
    TokenCache.obtainTokensForNamenodesInternal(credentials, paths, conf);
    verify(mockFs, times(1)).addDelegationTokens(renewer, credentials);
}
Also used : Path(org.apache.hadoop.fs.Path) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Example 10 with MockFileSystem

use of org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem in project hadoop by apache.

the class TestFileSystemTokens method testFsWithMyOwnAndChildTokens.

@Test
public void testFsWithMyOwnAndChildTokens() throws Exception {
    Credentials credentials = new Credentials();
    Text service1 = new Text("singleTokenFs1");
    Text service2 = new Text("singleTokenFs2");
    Text myService = new Text("multiTokenFs");
    Token<?> token = mock(Token.class);
    credentials.addToken(service2, token);
    MockFileSystem fs1 = createFileSystemForServiceName(service1);
    MockFileSystem fs2 = createFileSystemForServiceName(service2);
    MockFileSystem multiFs = createFileSystemForServiceName(myService, fs1, fs2);
    multiFs.addDelegationTokens(renewer, credentials);
    // its own token and also of its children
    verifyTokenFetch(multiFs, true);
    verifyTokenFetch(fs1, true);
    // we had added its token to credentials 
    verifyTokenFetch(fs2, false);
    assertEquals(3, credentials.numberOfTokens());
    assertNotNull(credentials.getToken(myService));
    assertNotNull(credentials.getToken(service1));
    assertNotNull(credentials.getToken(service2));
}
Also used : Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) MockFileSystem(org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem) Test(org.junit.Test)

Aggregations

MockFileSystem (org.apache.hadoop.fs.FileSystemTestHelper.MockFileSystem)15 Credentials (org.apache.hadoop.security.Credentials)13 Test (org.junit.Test)12 Text (org.apache.hadoop.io.Text)11 Path (org.apache.hadoop.fs.Path)3 Token (org.apache.hadoop.security.token.Token)2 TokenIdentifier (org.apache.hadoop.security.token.TokenIdentifier)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 URI (java.net.URI)1 Configuration (org.apache.hadoop.conf.Configuration)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1