Java 类org.apache.hadoop.security.ShellBasedIdMapping.PassThroughMap 实例源码

项目:hadoop-oss    文件:TestShellBasedIdMapping.java   
@Test
public void testStaticMapping() throws IOException {
  assumeTrue(!Shell.WINDOWS);
  Map<Integer, Integer> uidStaticMap = new PassThroughMap<Integer>();
  Map<Integer, Integer> gidStaticMap = new PassThroughMap<Integer>();

  uidStaticMap.put(11501, 10);
  gidStaticMap.put(497, 200);

  // Maps for id to name map
  BiMap<Integer, String> uMap = HashBiMap.create();
  BiMap<Integer, String> gMap = HashBiMap.create();

  String GET_ALL_USERS_CMD =
      "echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
      + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\""
      + " | cut -d: -f1,3";

  String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
      + "mapred:x:497\n"
      + "mapred2:x:498\""
      + " | cut -d: -f1,3";

  ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
      uidStaticMap);
  ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
      gidStaticMap);

  assertEquals("hdfs", uMap.get(10));
  assertEquals(10, (int)uMap.inverse().get("hdfs"));
  assertEquals("atm", uMap.get(1000));
  assertEquals(1000, (int)uMap.inverse().get("atm"));

  assertEquals("hdfs", gMap.get(11501));
  assertEquals(11501, (int)gMap.inverse().get("hdfs"));
  assertEquals("mapred", gMap.get(200));
  assertEquals(200, (int)gMap.inverse().get("mapred"));
  assertEquals("mapred2", gMap.get(498));
  assertEquals(498, (int)gMap.inverse().get("mapred2"));
}
项目:hadoop    文件:TestShellBasedIdMapping.java   
@Test
public void testStaticMapping() throws IOException {
  assumeTrue(!Shell.WINDOWS);
  Map<Integer, Integer> uidStaticMap = new PassThroughMap<Integer>();
  Map<Integer, Integer> gidStaticMap = new PassThroughMap<Integer>();

  uidStaticMap.put(11501, 10);
  gidStaticMap.put(497, 200);

  // Maps for id to name map
  BiMap<Integer, String> uMap = HashBiMap.create();
  BiMap<Integer, String> gMap = HashBiMap.create();

  String GET_ALL_USERS_CMD =
      "echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
      + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\""
      + " | cut -d: -f1,3";

  String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
      + "mapred:x:497\n"
      + "mapred2:x:498\""
      + " | cut -d: -f1,3";

  ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
      uidStaticMap);
  ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
      gidStaticMap);

  assertEquals("hdfs", uMap.get(10));
  assertEquals(10, (int)uMap.inverse().get("hdfs"));
  assertEquals("atm", uMap.get(1000));
  assertEquals(1000, (int)uMap.inverse().get("atm"));

  assertEquals("hdfs", gMap.get(11501));
  assertEquals(11501, (int)gMap.inverse().get("hdfs"));
  assertEquals("mapred", gMap.get(200));
  assertEquals(200, (int)gMap.inverse().get("mapred"));
  assertEquals("mapred2", gMap.get(498));
  assertEquals(498, (int)gMap.inverse().get("mapred2"));
}
项目:aliyun-oss-hadoop-fs    文件:TestShellBasedIdMapping.java   
@Test
public void testStaticMapping() throws IOException {
  assumeTrue(!Shell.WINDOWS);
  Map<Integer, Integer> uidStaticMap = new PassThroughMap<Integer>();
  Map<Integer, Integer> gidStaticMap = new PassThroughMap<Integer>();

  uidStaticMap.put(11501, 10);
  gidStaticMap.put(497, 200);

  // Maps for id to name map
  BiMap<Integer, String> uMap = HashBiMap.create();
  BiMap<Integer, String> gMap = HashBiMap.create();

  String GET_ALL_USERS_CMD =
      "echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
      + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\""
      + " | cut -d: -f1,3";

  String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
      + "mapred:x:497\n"
      + "mapred2:x:498\""
      + " | cut -d: -f1,3";

  ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
      uidStaticMap);
  ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
      gidStaticMap);

  assertEquals("hdfs", uMap.get(10));
  assertEquals(10, (int)uMap.inverse().get("hdfs"));
  assertEquals("atm", uMap.get(1000));
  assertEquals(1000, (int)uMap.inverse().get("atm"));

  assertEquals("hdfs", gMap.get(11501));
  assertEquals(11501, (int)gMap.inverse().get("hdfs"));
  assertEquals("mapred", gMap.get(200));
  assertEquals(200, (int)gMap.inverse().get("mapred"));
  assertEquals("mapred2", gMap.get(498));
  assertEquals(498, (int)gMap.inverse().get("mapred2"));
}
项目:big-c    文件:TestShellBasedIdMapping.java   
@Test
public void testStaticMapping() throws IOException {
  assumeTrue(!Shell.WINDOWS);
  Map<Integer, Integer> uidStaticMap = new PassThroughMap<Integer>();
  Map<Integer, Integer> gidStaticMap = new PassThroughMap<Integer>();

  uidStaticMap.put(11501, 10);
  gidStaticMap.put(497, 200);

  // Maps for id to name map
  BiMap<Integer, String> uMap = HashBiMap.create();
  BiMap<Integer, String> gMap = HashBiMap.create();

  String GET_ALL_USERS_CMD =
      "echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
      + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\""
      + " | cut -d: -f1,3";

  String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
      + "mapred:x:497\n"
      + "mapred2:x:498\""
      + " | cut -d: -f1,3";

  ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
      uidStaticMap);
  ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
      gidStaticMap);

  assertEquals("hdfs", uMap.get(10));
  assertEquals(10, (int)uMap.inverse().get("hdfs"));
  assertEquals("atm", uMap.get(1000));
  assertEquals(1000, (int)uMap.inverse().get("atm"));

  assertEquals("hdfs", gMap.get(11501));
  assertEquals(11501, (int)gMap.inverse().get("hdfs"));
  assertEquals("mapred", gMap.get(200));
  assertEquals(200, (int)gMap.inverse().get("mapred"));
  assertEquals("mapred2", gMap.get(498));
  assertEquals(498, (int)gMap.inverse().get("mapred2"));
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestShellBasedIdMapping.java   
@Test
public void testStaticMapping() throws IOException {
  assumeTrue(!Shell.WINDOWS);
  Map<Integer, Integer> uidStaticMap = new PassThroughMap<Integer>();
  Map<Integer, Integer> gidStaticMap = new PassThroughMap<Integer>();

  uidStaticMap.put(11501, 10);
  gidStaticMap.put(497, 200);

  // Maps for id to name map
  BiMap<Integer, String> uMap = HashBiMap.create();
  BiMap<Integer, String> gMap = HashBiMap.create();

  String GET_ALL_USERS_CMD =
      "echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
      + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\""
      + " | cut -d: -f1,3";

  String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
      + "mapred:x:497\n"
      + "mapred2:x:498\""
      + " | cut -d: -f1,3";

  ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
      uidStaticMap);
  ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
      gidStaticMap);

  assertEquals("hdfs", uMap.get(10));
  assertEquals(10, (int)uMap.inverse().get("hdfs"));
  assertEquals("atm", uMap.get(1000));
  assertEquals(1000, (int)uMap.inverse().get("atm"));

  assertEquals("hdfs", gMap.get(11501));
  assertEquals(11501, (int)gMap.inverse().get("hdfs"));
  assertEquals("mapred", gMap.get(200));
  assertEquals(200, (int)gMap.inverse().get("mapred"));
  assertEquals("mapred2", gMap.get(498));
  assertEquals(498, (int)gMap.inverse().get("mapred2"));
}
项目:hops    文件:TestShellBasedIdMapping.java   
@Test
public void testStaticMapping() throws IOException {
  assumeTrue(!Shell.WINDOWS);
  Map<Integer, Integer> uidStaticMap = new PassThroughMap<Integer>();
  Map<Integer, Integer> gidStaticMap = new PassThroughMap<Integer>();

  uidStaticMap.put(11501, 10);
  gidStaticMap.put(497, 200);

  // Maps for id to name map
  BiMap<Integer, String> uMap = HashBiMap.create();
  BiMap<Integer, String> gMap = HashBiMap.create();

  String GET_ALL_USERS_CMD =
      "echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
      + "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\""
      + " | cut -d: -f1,3";

  String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
      + "mapred:x:497\n"
      + "mapred2:x:498\""
      + " | cut -d: -f1,3";

  ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
      uidStaticMap);
  ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
      gidStaticMap);

  assertEquals("hdfs", uMap.get(10));
  assertEquals(10, (int)uMap.inverse().get("hdfs"));
  assertEquals("atm", uMap.get(1000));
  assertEquals(1000, (int)uMap.inverse().get("atm"));

  assertEquals("hdfs", gMap.get(11501));
  assertEquals(11501, (int)gMap.inverse().get("hdfs"));
  assertEquals("mapred", gMap.get(200));
  assertEquals(200, (int)gMap.inverse().get("mapred"));
  assertEquals("mapred2", gMap.get(498));
  assertEquals(498, (int)gMap.inverse().get("mapred2"));
}