PartitionMap { public synchronized boolean removePartition(Partition partition) { Set<Partition> partitions = partitionMap.get(partition.getStream()); return null != partitions && partitions.remove(partition); } PartitionMap(); synchronized boolean addPartition(Partition partition, int maxPartitions); synchronized boolean removePartition(Partition partition);  }
@Test(timeout = 20000) public void testRemovePartition() { PartitionMap map = new PartitionMap(); for (int i = 0; i < 3; i++) { assertTrue(map.addPartition(new Partition("test", i), 3)); } assertFalse(map.addPartition(new Partition("test", 3), 3)); assertFalse(map.removePartition(new Partition("test", 3))); assertTrue(map.removePartition(new Partition("test", 0))); assertTrue(map.addPartition(new Partition("test", 3), 3)); }