Exemplo n.º 1
0
 @Test
 public void testEqualsWithRealUser() throws Exception {
   UserGroupInformation realUgi1 =
       UserGroupInformation.createUserForTesting("RealUser", GROUP_NAMES);
   UserGroupInformation realUgi2 =
       UserGroupInformation.createUserForTesting("RealUser", GROUP_NAMES);
   UserGroupInformation proxyUgi1 = UserGroupInformation.createProxyUser(USER_NAME, realUgi1);
   UserGroupInformation proxyUgi2 = new UserGroupInformation(proxyUgi1.getSubject());
   UserGroupInformation remoteUgi = UserGroupInformation.createRemoteUser(USER_NAME);
   assertEquals(proxyUgi1, proxyUgi2);
   assertFalse(remoteUgi.equals(proxyUgi1));
 }
Exemplo n.º 2
0
  @Test
  public void testEquals() throws Exception {
    UserGroupInformation uugi = UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES);

    assertEquals(uugi, uugi);
    // The subjects should be different, so this should fail
    UserGroupInformation ugi2 = UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES);
    assertFalse(uugi.equals(ugi2));
    assertFalse(uugi.hashCode() == ugi2.hashCode());

    // two ugi that have the same subject need to be equal
    UserGroupInformation ugi3 = new UserGroupInformation(uugi.getSubject());
    assertEquals(uugi, ugi3);
    assertEquals(uugi.hashCode(), ugi3.hashCode());

    // ensure that different UGI with the same subject are equal
    assertEquals(uugi, new UserGroupInformation(uugi.getSubject()));
  }
Exemplo n.º 3
0
  /** Test login method */
  @Test
  public void testLogin() throws Exception {
    // login from unix
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    assertEquals(UserGroupInformation.getCurrentUser(), UserGroupInformation.getLoginUser());
    assertTrue(ugi.getGroupNames().length >= 1);

    // ensure that doAs works correctly
    UserGroupInformation userGroupInfo =
        UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES);
    UserGroupInformation curUGI =
        userGroupInfo.doAs(
            new PrivilegedExceptionAction<UserGroupInformation>() {
              public UserGroupInformation run() throws IOException {
                return UserGroupInformation.getCurrentUser();
              }
            });
    // make sure in the scope of the doAs, the right user is current
    assertEquals(curUGI, userGroupInfo);
    // make sure it is not the same as the login user
    assertFalse(curUGI.equals(UserGroupInformation.getLoginUser()));
  }