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);
}
}
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();
}
Aggregations