Search in sources :

Example 6 with RaftServerMetricsImpl

use of org.apache.ratis.server.metrics.RaftServerMetricsImpl in project incubator-ratis by apache.

the class TestRaftServerWithGrpc method testRaftClientRequestMetrics.

void testRaftClientRequestMetrics(MiniRaftClusterWithGrpc cluster) throws IOException, ExecutionException, InterruptedException {
    final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
    final RaftServerMetricsImpl raftServerMetrics = getRaftServerMetrics(leader);
    try (final RaftClient client = cluster.createClient()) {
        final CompletableFuture<RaftClientReply> f1 = client.async().send(new SimpleMessage("testing"));
        Assert.assertTrue(f1.get().isSuccess());
        Assert.assertTrue(raftServerMetrics.getTimer(RAFT_CLIENT_WRITE_REQUEST).getCount() > 0);
        final CompletableFuture<RaftClientReply> f2 = client.async().sendReadOnly(new SimpleMessage("testing"));
        Assert.assertTrue(f2.get().isSuccess());
        Assert.assertTrue(raftServerMetrics.getTimer(RAFT_CLIENT_READ_REQUEST).getCount() > 0);
        final CompletableFuture<RaftClientReply> f3 = client.async().sendStaleRead(new SimpleMessage("testing"), 0, leader.getId());
        Assert.assertTrue(f3.get().isSuccess());
        Assert.assertTrue(raftServerMetrics.getTimer(RAFT_CLIENT_STALE_READ_REQUEST).getCount() > 0);
        final CompletableFuture<RaftClientReply> f4 = client.async().watch(0, RaftProtos.ReplicationLevel.ALL);
        Assert.assertTrue(f4.get().isSuccess());
        Assert.assertTrue(raftServerMetrics.getTimer(String.format(RAFT_CLIENT_WATCH_REQUEST, "-ALL")).getCount() > 0);
        final CompletableFuture<RaftClientReply> f5 = client.async().watch(0, RaftProtos.ReplicationLevel.MAJORITY);
        Assert.assertTrue(f5.get().isSuccess());
        Assert.assertTrue(raftServerMetrics.getTimer(String.format(RAFT_CLIENT_WATCH_REQUEST, "")).getCount() > 0);
    }
}
Also used : RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftServer(org.apache.ratis.server.RaftServer) SimpleMessage(org.apache.ratis.RaftTestUtil.SimpleMessage) RaftClient(org.apache.ratis.client.RaftClient) RaftServerMetricsImpl(org.apache.ratis.server.metrics.RaftServerMetricsImpl)

Aggregations

RaftServerMetricsImpl (org.apache.ratis.server.metrics.RaftServerMetricsImpl)6 RaftServer (org.apache.ratis.server.RaftServer)4 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)3 Gauge (com.codahale.metrics.Gauge)2 IOException (java.io.IOException)2 List (java.util.List)2 SortedMap (java.util.SortedMap)2 Level (org.apache.log4j.Level)2 SimpleMessage (org.apache.ratis.RaftTestUtil.SimpleMessage)2 RaftClient (org.apache.ratis.client.RaftClient)2 RaftProperties (org.apache.ratis.conf.RaftProperties)2 RatisMetricRegistry (org.apache.ratis.metrics.RatisMetricRegistry)2 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)2 RaftServerConfigKeys (org.apache.ratis.server.RaftServerConfigKeys)2 MiniRaftCluster (org.apache.ratis.server.impl.MiniRaftCluster)2 SimpleStateMachine4Testing (org.apache.ratis.statemachine.SimpleStateMachine4Testing)2 StateMachine (org.apache.ratis.statemachine.StateMachine)2 Log4jUtils (org.apache.ratis.util.Log4jUtils)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2