@Test
public void testChooseRandomWithStorageType() throws Exception {

  Node n;
  DatanodeDescriptor dd;
  // test the choose random can return desired storage type nodes without
  // exclude
  Set<String> diskUnderL1 =
      Sets.newHashSet("host2", "host4", "host5", "host6");
  Set<String> archiveUnderL1 = Sets.newHashSet("host1", "host3");
  Set<String> ramdiskUnderL1 = Sets.newHashSet("host7");
  Set<String> ssdUnderL1 = Sets.newHashSet("host8");
  Set<String> nvdimmUnderL1 = Sets.newHashSet("host9");
  for (int i = 0; i < 10; i++) {
    n = CLUSTER.chooseRandomWithStorageType("/l1", null, null,
        StorageType.DISK);
    assertTrue(n instanceof DatanodeDescriptor);
    dd = (DatanodeDescriptor) n;
    assertTrue(diskUnderL1.contains(dd.getHostName()));
    n = CLUSTER.chooseRandomWithStorageType("/l1", null, null,
        StorageType.RAM_DISK);
    assertTrue(n instanceof DatanodeDescriptor);
    dd = (DatanodeDescriptor) n;
    assertTrue(ramdiskUnderL1.contains(dd.getHostName()));
    n = CLUSTER.chooseRandomWithStorageType("/l1", null, null,
        StorageType.ARCHIVE);
    assertTrue(n instanceof DatanodeDescriptor);
    dd = (DatanodeDescriptor) n;
    assertTrue(archiveUnderL1.contains(dd.getHostName()));
    n = CLUSTER.chooseRandomWithStorageType("/l1", null, null,
        StorageType.SSD);
    assertTrue(n instanceof DatanodeDescriptor);
    dd = (DatanodeDescriptor) n;
    assertTrue(ssdUnderL1.contains(dd.getHostName()));
  }
}