Search in sources :

Example 1 with GrpcServerMetrics

use of org.apache.ratis.grpc.metrics.GrpcServerMetrics in project incubator-ratis by apache.

the class TestLogAppenderWithGrpc method runTestRestartLogAppender.

private void runTestRestartLogAppender(MiniRaftClusterWithGrpc cluster) throws Exception {
    final RaftServer.Division leader = waitForLeader(cluster);
    int messageCount = 0;
    // Send some messages
    try (RaftClient client = cluster.createClient(leader.getId())) {
        for (int i = 0; i < 10; i++) {
            final RaftClientReply reply = client.io().send(new RaftTestUtil.SimpleMessage("m" + ++messageCount));
            Assert.assertTrue(reply.isSuccess());
        }
    }
    // assert INCONSISTENCY counter == 0
    final GrpcServerMetrics leaderMetrics = new GrpcServerMetrics(leader.getMemberId().toString());
    final String counter = String.format(GrpcServerMetrics.RATIS_GRPC_METRICS_LOG_APPENDER_INCONSISTENCY, cluster.getFollowers().iterator().next().getMemberId().getPeerId());
    Assert.assertEquals(0L, leaderMetrics.getRegistry().counter(counter).getCount());
    // restart LogAppender
    RaftServerTestUtil.restartLogAppenders(leader);
    // Send some more messages
    try (RaftClient client = cluster.createClient(leader.getId())) {
        for (int i = 0; i < 10; i++) {
            final RaftClientReply reply = client.io().send(new RaftTestUtil.SimpleMessage("m" + ++messageCount));
            Assert.assertTrue(reply.isSuccess());
        }
    }
    final RaftServer.Division newLeader = waitForLeader(cluster);
    if (leader == newLeader) {
        final GrpcServerMetrics newleaderMetrics = new GrpcServerMetrics(leader.getMemberId().toString());
        // assert INCONSISTENCY counter >= 1
        // If old LogAppender die before new LogAppender start, INCONSISTENCY equal to 1,
        // else INCONSISTENCY greater than 1
        Assert.assertTrue(newleaderMetrics.getRegistry().counter(counter).getCount() >= 1L);
    }
}
Also used : RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftTestUtil(org.apache.ratis.RaftTestUtil) RaftServer(org.apache.ratis.server.RaftServer) GrpcServerMetrics(org.apache.ratis.grpc.metrics.GrpcServerMetrics) RaftClient(org.apache.ratis.client.RaftClient)

Example 2 with GrpcServerMetrics

use of org.apache.ratis.grpc.metrics.GrpcServerMetrics in project incubator-ratis by apache.

the class TestGrpcServerMetrics method setUp.

@BeforeClass
public static void setUp() throws Exception {
    raftGroupId = RaftGroupId.randomId();
    raftPeerId = RaftPeerId.valueOf("TestId");
    followerId = RaftPeerId.valueOf("FollowerId");
    RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId);
    grpcServerMetrics = new GrpcServerMetrics(raftGroupMemberId.toString());
    ratisMetricRegistry = grpcServerMetrics.getRegistry();
}
Also used : RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) GrpcServerMetrics(org.apache.ratis.grpc.metrics.GrpcServerMetrics) BeforeClass(org.junit.BeforeClass)

Aggregations

GrpcServerMetrics (org.apache.ratis.grpc.metrics.GrpcServerMetrics)2 RaftTestUtil (org.apache.ratis.RaftTestUtil)1 RaftClient (org.apache.ratis.client.RaftClient)1 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)1 RaftGroupMemberId (org.apache.ratis.protocol.RaftGroupMemberId)1 RaftServer (org.apache.ratis.server.RaftServer)1 BeforeClass (org.junit.BeforeClass)1