@Test
  public void replicaFromLeaderToStandbyTest() throws Exception {
    MockClusterMap clusterMap = new MockClusterMap();
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(verifiableProperties);
    MockHelixParticipant.metricRegistry = new MetricRegistry();
    MockHelixParticipant mockHelixParticipant = new MockHelixParticipant(clusterMapConfig);

    ReplicationConfig initialReplicationConfig = replicationConfig;
    properties.setProperty("replication.model.across.datacenters", "LEADER_BASED");
    replicationConfig = new ReplicationConfig(new VerifiableProperties(properties));

    Pair<StorageManager, ReplicationManager> managers =
        createStorageManagerAndReplicationManager(clusterMap, clusterMapConfig, mockHelixParticipant);
    StorageManager storageManager = managers.getFirst();
    MockReplicationManager replicationManager = (MockReplicationManager) managers.getSecond();
    PartitionId existingPartition = replicationManager.partitionToPartitionInfo.keySet().iterator().next();
    mockHelixParticipant.onPartitionBecomeLeaderFromStandby(existingPartition.toPathString());
    Map<String, Set<ReplicaId>> peerLeaderReplicasByPartition =
        replicationManager.leaderBasedReplicationAdmin.getLeaderPartitionToPeerLeaderReplicas();
    assertTrue(
        "Partition is not present in the map of partition to peer leader replicas after it moved from standby to leader",
        peerLeaderReplicasByPartition.containsKey(existingPartition.toPathString()));
    mockHelixParticipant.onPartitionBecomeStandbyFromLeader(existingPartition.toPathString());
    assertFalse(
        "Partition is still present in the map of partition to peer leader replicas after it moved from leader to standby",
        peerLeaderReplicasByPartition.containsKey(existingPartition.toPathString()));
    storageManager.shutdown();

    replicationConfig = initialReplicationConfig;
  }
Test state transition in replication manager from LEADER to STANDBY
Test setup: When creating partitions, make sure that there is exactly one replica in LEADER STATE on each data center
Test condition: When a partition on the current node moves from leader to standby, verify that in-memory map storing
partition to peer leader replicas is updated correctly
@throws Exception
ambry-replication/src/test/java/com/github/ambry/replication/ReplicationTest.java