Search in sources :

Example 1 with LogOffsetMetadata

use of org.apache.kafka.raft.LogOffsetMetadata in project kafka by apache.

the class KafkaRaftMetricsTest method shouldRecordVoterQuorumState.

@Test
public void shouldRecordVoterQuorumState() throws IOException {
    QuorumState state = buildQuorumState(Utils.mkSet(localId, 1, 2));
    state.initialize(new OffsetAndEpoch(0L, 0));
    raftMetrics = new KafkaRaftMetrics(metrics, "raft", state);
    assertEquals("unattached", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 0, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "high-watermark").metricValue());
    state.transitionToCandidate();
    assertEquals("candidate", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) localId, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 1, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "high-watermark").metricValue());
    state.candidateStateOrThrow().recordGrantedVote(1);
    state.transitionToLeader(2L, accumulator);
    assertEquals("leader", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) localId, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) localId, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 1, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) -1L, getMetric(metrics, "high-watermark").metricValue());
    state.leaderStateOrThrow().updateLocalState(0, new LogOffsetMetadata(5L));
    state.leaderStateOrThrow().updateReplicaState(1, 0, new LogOffsetMetadata(5L));
    assertEquals((double) 5L, getMetric(metrics, "high-watermark").metricValue());
    state.transitionToFollower(2, 1);
    assertEquals("follower", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) 1, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) -1, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 2, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) 5L, getMetric(metrics, "high-watermark").metricValue());
    state.followerStateOrThrow().updateHighWatermark(OptionalLong.of(10L));
    assertEquals((double) 10L, getMetric(metrics, "high-watermark").metricValue());
    state.transitionToVoted(3, 2);
    assertEquals("voted", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) -1, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) 2, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 3, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) 10L, getMetric(metrics, "high-watermark").metricValue());
    state.transitionToUnattached(4);
    assertEquals("unattached", getMetric(metrics, "current-state").metricValue());
    assertEquals((double) -1, getMetric(metrics, "current-leader").metricValue());
    assertEquals((double) -1, getMetric(metrics, "current-vote").metricValue());
    assertEquals((double) 4, getMetric(metrics, "current-epoch").metricValue());
    assertEquals((double) 10L, getMetric(metrics, "high-watermark").metricValue());
}
Also used : OffsetAndEpoch(org.apache.kafka.raft.OffsetAndEpoch) QuorumState(org.apache.kafka.raft.QuorumState) LogOffsetMetadata(org.apache.kafka.raft.LogOffsetMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

LogOffsetMetadata (org.apache.kafka.raft.LogOffsetMetadata)1 OffsetAndEpoch (org.apache.kafka.raft.OffsetAndEpoch)1 QuorumState (org.apache.kafka.raft.QuorumState)1 Test (org.junit.jupiter.api.Test)1