@Test
  public void helixDuplicatePartitionInIdealStateChangeTest() throws Exception {
    assumeTrue(!useComposite && !overrideEnabled);
    HelixClusterManager helixClusterManager = (HelixClusterManager) clusterManager;
    verifyInitialClusterChanges(helixClusterManager, helixCluster, helixDcs);

    Map<String, Map<String, Set<String>>> partitionToResourceByDc = helixClusterManager.getPartitionToResourceMapByDC();
    Map<String, Set<String>> localDCPartitionToResource = partitionToResourceByDc.get(localDc);

    Map.Entry<String, Set<String>> randomPartitionAndResource = localDCPartitionToResource.entrySet().iterator().next();
    String partitionName = randomPartitionAndResource.getKey();
    Assert.assertEquals(1, randomPartitionAndResource.getValue().size());
    String resourceName = randomPartitionAndResource.getValue().iterator().next();
    String newResourceName = String.valueOf(Integer.valueOf(resourceName) + 1000);

    IdealState idealState = new IdealState(newResourceName);
    IdealState oldIdealState = helixCluster.getResourceIdealState(resourceName, localDc);
    idealState.setPreferenceList(partitionName, oldIdealState.getPreferenceList(partitionName));
    helixCluster.addNewResource(newResourceName, idealState, localDc);

    // Local dc's partition's resource should be updated to newResource name
    Map<String, Set<String>> partitionToResourceAfterUpdate =
        (helixClusterManager).getPartitionToResourceMapByDC().get(localDc);
    assertEquals(localDCPartitionToResource.size(), partitionToResourceAfterUpdate.size());

    // Only partitionName changes resource
    for (Map.Entry<String, Set<String>> partitionAndResource : partitionToResourceAfterUpdate.entrySet()) {
      String pName = partitionAndResource.getKey();
      Set<String> rNames = partitionAndResource.getValue();
      if (pName.equals(partitionName)) {
        assertTrue(rNames.contains(newResourceName));
        assertFalse(rNames.contains(resourceName));
      } else {
        assertEquals(localDCPartitionToResource.get(pName), rNames);
      }
    }
    Map<String, String> partitionToDuplicateResourceAfterUpdate =
        (helixClusterManager).getPartitionToDuplicateResourceMapByDC().get(localDc);
    assertEquals(1, partitionToDuplicateResourceAfterUpdate.size());
    assertEquals(resourceName, partitionToDuplicateResourceAfterUpdate.get(partitionName));
  }
Test duplicate partition ids in ideal state.
@throws Exception
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixClusterManagerTest.java