@Test
public void removeReader() throws Exception {

  String resource = "resource1";
  TestReader reader1 = new TestReader();
  resourcePartitionMap.addReader(resource, "part1", reader1);
  TestReader reader2 = new TestReader();
  resourcePartitionMap.addReader(resource, "part2", reader2);
  // Remove reader1.
  assertEquals(reader1, resourcePartitionMap.removeReader(resource, "part1"));
  // Make sure we throw the correct exception if we try to access resource1, part1.
  testGetExceptionErrorCode(resource, "part1", TerrapinGetErrorCode.NOT_SERVING_PARTITION);
  // Remove a partition for which none of the resources exist. Check that we throw
  // UnsupportedOperationException.
  boolean gotUnsupportedOpException = false;
  try {
    resourcePartitionMap.removeReader(resource, "part3");
  } catch (UnsupportedOperationException e) {
    gotUnsupportedOpException = true;
  }
  assertTrue(gotUnsupportedOpException);
  // We should still have access to reader2.
  assertEquals(reader2, resourcePartitionMap.getReader(resource, "part2"));
  // Remove reader2.
  assertEquals(reader2, resourcePartitionMap.removeReader(resource, "part2"));
  // Make sure we throw the correct exception if we try to access resource1, part2.
  // We throw NOT_SERVING_RESOURCE since all partitions for the resource have been removed.
  testGetExceptionErrorCode(resource, "part2", TerrapinGetErrorCode.NOT_SERVING_RESOURCE);
}