SingleUGIResolver extends UGIResolver implements Configurable { @Override public void setConf(Configuration conf) { this.conf = conf; uid = conf.getInt(UID, 0); user = conf.get(USER); if (null == user) { try { user = UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { user = "hadoop"; } } gid = conf.getInt(GID, 1); group = conf.get(GROUP); if (null == group) { group = user; } resetUGInfo(); addUser(user, uid); addGroup(group, gid); }  @Override void setConf(Configuration conf); @Override Configuration getConf(); @Override String user(String s); @Override String group(String s); @Override void addUser(String name); @Override void addGroup(String name); static final String UID; static final String USER; static final String GID; static final String GROUP; }
@Test public void testDefault() { String user; try { user = UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { user = "hadoop"; } Configuration conf = new Configuration(false); ugi.setConf(conf); Map<Integer, String> ids = ugi.ugiMap(); assertEquals(2, ids.size()); assertEquals(user, ids.get(0)); assertEquals(user, ids.get(1)); }
@Test(expected=IllegalStateException.class) public void testDuplicateIds() { Configuration conf = new Configuration(false); conf.setInt(SingleUGIResolver.UID, 4344); conf.setInt(SingleUGIResolver.GID, 4344); conf.set(SingleUGIResolver.USER, TESTUSER); conf.set(SingleUGIResolver.GROUP, TESTGROUP); ugi.setConf(conf); ugi.ugiMap(); }