use of org.apache.kafka.raft.QuorumState in project kafka by apache.
the class KafkaRaftMetricsTest method shouldRecordLogEnd.
@Test
public void shouldRecordLogEnd() throws IOException {
QuorumState state = buildQuorumState(Collections.singleton(localId));
state.initialize(new OffsetAndEpoch(0L, 0));
raftMetrics = new KafkaRaftMetrics(metrics, "raft", state);
assertEquals((double) 0L, getMetric(metrics, "log-end-offset").metricValue());
assertEquals((double) 0, getMetric(metrics, "log-end-epoch").metricValue());
raftMetrics.updateLogEnd(new OffsetAndEpoch(5L, 1));
assertEquals((double) 5L, getMetric(metrics, "log-end-offset").metricValue());
assertEquals((double) 1, getMetric(metrics, "log-end-epoch").metricValue());
}
use of org.apache.kafka.raft.QuorumState 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());
}
Aggregations