@Test
  public void testHelixParticipantPartitionStateTransitionMetrics() throws Exception {
    props.setProperty("clustermap.enable.partition.state.transition.metrics", "true");
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    HelixParticipant participant =
        new HelixParticipant(mock(HelixClusterManager.class), clusterMapConfig, helixManagerFactory,
            new MetricRegistry(), getDefaultZkConnectStr(clusterMapConfig), true);
    HelixParticipantMetrics metrics = participant.participantMetrics;
    metrics.incStateTransitionMetric("test-1", ReplicaState.BOOTSTRAP, ReplicaState.STANDBY);
    assertNotNull(metrics.partitionTransitionToCount.get("State-Transition-Partition-test-1-from-BOOTSTRAP-to-STANDBY"));

    assertNull(metrics.partitionTransitionToCount.get(
        "State-Transition-Partition-test-1-from-" + ReplicaState.STANDBY.name() + "-to-" + ReplicaState.LEADER.name()));

    metrics.incStateTransitionMetric("test-1", ReplicaState.STANDBY, ReplicaState.LEADER);
    assertNotNull(metrics.partitionTransitionToCount.get(
        "State-Transition-Partition-test-1-from-" + ReplicaState.STANDBY.name() + "-to-" + ReplicaState.LEADER.name()));

    metrics.incStateTransitionMetric("test-2", ReplicaState.BOOTSTRAP, ReplicaState.STANDBY);
    assertNotNull(metrics.partitionTransitionToCount.get(
        "State-Transition-Partition-test-2-from-" + ReplicaState.BOOTSTRAP.name() + "-to-" + ReplicaState.STANDBY.name()));

    metrics.clearStateTransitionMetric("test-1");
    assertNull(metrics.partitionTransitionToCount.get("Partition-test-1-from-BOOTSTRAP-to-STANDBY"));
    assertNotNull(metrics.partitionTransitionToCount.get(
        "State-Transition-Partition-test-2-from-" + ReplicaState.BOOTSTRAP.name() + "-to-" + ReplicaState.STANDBY.name()));

    metrics.clearStateTransitionMetric("test-2");
    assertNull(metrics.partitionTransitionToCount.get(
        "State-Transition-Partition-test-2-from-" + ReplicaState.BOOTSTRAP.name() + "-to-" + ReplicaState.STANDBY.name()));
  }
Tests whether the correct metrics that are getting logged for state transitions
and correct clearance of metrics
@throws Exception exception
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixParticipantTest.java