@Test
  public void testGetRandomFullyWritablePartition() {
    List<PartitionId> partitionIdsToExclude = new ArrayList<>();
    List<? extends PartitionId> allPartitionIds = clusterManager.getAllPartitionIds(null);
    int totalFullyWritablePartitions = (int) allPartitionIds.stream()
        .filter(partitionId -> partitionId.getPartitionState() == PartitionState.READ_WRITE)
        .count();

    // Call getRandomFullyWritablePartition as many times as there are fully writable partitions. It should always return fully writable partition.
    for (int i = 0; i < totalFullyWritablePartitions; i++) {
      PartitionId partitionId = clusterManager.getRandomFullyWritablePartition(null, partitionIdsToExclude);
      assertEquals("getRandomFullyWritablePartition should always return partitions in READ_WRITE states only.",
          PartitionState.READ_WRITE, partitionId.getPartitionState());
      partitionIdsToExclude.add(partitionId);
    }
    // Now that all the fully writable partitions are in the excluded list, getRandomWritablePartition should not return any partition.
    assertNull(clusterManager.getRandomFullyWritablePartition(null, partitionIdsToExclude));
  }
Test for {@link HelixClusterManager#getRandomFullyWritablePartition(String, List)}.
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixClusterManagerTest.java