ResourcePartitionMap { public Reader removeReader(String resource, String partition) throws UnsupportedOperationException { Pair<String, String> readerMapKey = new ImmutablePair(resource, partition); synchronized (this) { Reader r = this.readerMap.get(readerMapKey); if (r != null) { readerMap.remove(readerMapKey); decrementPartitionCount(resource); return r; } else { throw new UnsupportedOperationException("Partition " + partition + " not found for Resource " + resource); } } } ResourcePartitionMap(); void addReader(String resource,
                        String partition,
                        Reader r); Reader removeReader(String resource, String partition); Reader getReader(String resource, String partition); void close();  }
@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); assertEquals(reader1, resourcePartitionMap.removeReader(resource, "part1")); testGetExceptionErrorCode(resource, "part1", TerrapinGetErrorCode.NOT_SERVING_PARTITION); boolean gotUnsupportedOpException = false; try { resourcePartitionMap.removeReader(resource, "part3"); } catch (UnsupportedOperationException e) { gotUnsupportedOpException = true; } assertTrue(gotUnsupportedOpException); assertEquals(reader2, resourcePartitionMap.getReader(resource, "part2")); assertEquals(reader2, resourcePartitionMap.removeReader(resource, "part2")); testGetExceptionErrorCode(resource, "part2", TerrapinGetErrorCode.NOT_SERVING_RESOURCE); }