@Test(timeout = 30000)
public void testRemoveVolumes() throws IOException {

  // Feed FsDataset with block metadata.
  final int NUM_BLOCKS = 100;
  for (int i = 0; i < NUM_BLOCKS; i++) {
    String bpid = BLOCK_POOL_IDS[NUM_BLOCKS % BLOCK_POOL_IDS.length];
    ExtendedBlock eb = new ExtendedBlock(bpid, i);
    try (ReplicaHandler replica =
        dataset.createRbw(StorageType.DEFAULT, eb, false)) {
    }
  }
  final String[] dataDirs =
      conf.get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY).split(",");
  final String volumePathToRemove = dataDirs[0];
  Set<File> volumesToRemove = new HashSet<>();
  volumesToRemove.add(StorageLocation.parse(volumePathToRemove).getFile());
  dataset.removeVolumes(volumesToRemove, true);
  int expectedNumVolumes = dataDirs.length - 1;
  assertEquals("The volume has been removed from the volumeList.",
      expectedNumVolumes, dataset.getVolumes().size());
  assertEquals("The volume has been removed from the storageMap.",
      expectedNumVolumes, dataset.storageMap.size());
  try {
    dataset.asyncDiskService.execute(volumesToRemove.iterator().next(),
        new Runnable() {
          @Override
          public void run() {}
        });
    fail("Expect RuntimeException: the volume has been removed from the "
         + "AsyncDiskService.");
  } catch (RuntimeException e) {
    GenericTestUtils.assertExceptionContains("Cannot find root", e);
  }
  int totalNumReplicas = 0;
  for (String bpid : dataset.volumeMap.getBlockPoolList()) {
    totalNumReplicas += dataset.volumeMap.size(bpid);
  }
  assertEquals("The replica infos on this volume has been removed from the "
               + "volumeMap.", NUM_BLOCKS / NUM_INIT_VOLUMES,
               totalNumReplicas);
}