@Test
  public void filterPartitionMapsAndSwitchTest() {

    final String dc1 = "DC1";
    final String maxReplicasAllSites = "max-replicas-all-sites";
    final int minimumLocalReplicaCount = 3;

    MockDataNodeId dc1Dn1 = getDataNodeId("dc1dn1", dc1);
    MockDataNodeId dc1Dn2 = getDataNodeId("dc1dn2", dc1);
    MockDataNodeId dc1Dn3 = getDataNodeId("dc1dn3", dc1);

    List<MockDataNodeId> allDataNodes = Arrays.asList(dc1Dn1, dc1Dn2, dc1Dn3);
    MockPartitionId everywhere1 = new MockPartitionId(1, maxReplicasAllSites, allDataNodes, 0);
    MockPartitionId everywhere2 = new MockPartitionId(2, maxReplicasAllSites, allDataNodes, 0);
    List<ReplicaId> replicaIds = new ArrayList<>();
    for (ReplicaId replicaId : everywhere1.replicaIds) {
      replicaIds.add(replicaId);  // Add replicaId to the new list
    }

    Collection<MockPartitionId> allPartitionIdsMain = Collections.unmodifiableSet(
        new HashSet<>(Arrays.asList(everywhere1, everywhere2)));
    ClusterManagerQueryHelper mockClusterManagerQueryHelper = Mockito.mock(ClusterManagerQueryHelper.class);
    doReturn(false).when(mockClusterManagerQueryHelper).isPartitionFilteringEnabled();
    doReturn(allPartitionIdsMain).when(mockClusterManagerQueryHelper).getPartitions();

    ClusterMapUtils.PartitionSelectionHelper psh =
        new ClusterMapUtils.PartitionSelectionHelper(mockClusterManagerQueryHelper, dc1, minimumLocalReplicaCount,
            maxReplicasAllSites, null);

    // case 1: filtering disabled
    doReturn(false).when(mockClusterManagerQueryHelper).isPartitionFilteringEnabled();
    Set<MockPartitionId> allPartitionIds = new HashSet<>(Arrays.asList(everywhere1, everywhere2));
    psh.onReplicaAddedOrRemoved(replicaIds, null);
    assertCollectionEquals("Partitions returned not as expected", allPartitionIds, psh.getPartitions(maxReplicasAllSites));

    // case 2: filtering enabled
    doReturn(true).when(mockClusterManagerQueryHelper).isPartitionFilteringEnabled();
    doReturn(true).when(mockClusterManagerQueryHelper).isValidPartition("Partition[1]");
    psh.onReplicaAddedOrRemoved(replicaIds, null);
    allPartitionIds = new HashSet<>(Arrays.asList(everywhere1));
    assertCollectionEquals("Partitions returned not as expected", allPartitionIds, psh.getPartitions(maxReplicasAllSites));
  }
Tests for {@link ClusterMapUtils#areAllReplicasForPartitionUp(PartitionId)}.
ambry-clustermap/src/test/java/com/github/ambry/clustermap/ClusterMapUtilsTest.java