use of org.apache.ratis.client.RaftClient in project incubator-ratis by apache.
the class TestDataStreamDisabled method testDataStreamDisabled.
@Test
public void testDataStreamDisabled() {
final RaftProperties properties = new RaftProperties();
Assert.assertEquals(SupportedDataStreamType.DISABLED, RaftConfigKeys.DataStream.type(properties, LOG::info));
final RaftPeer server = RaftPeer.newBuilder().setId("s0").build();
final RaftClient client = RaftClient.newBuilder().setRaftGroup(RaftGroup.valueOf(RaftGroupId.randomId(), server)).setProperties(properties).build();
exception.expect(UnsupportedOperationException.class);
exception.expectMessage(DisabledDataStreamClientFactory.class.getName() + "$1 does not support streamAsync");
// stream() will create a header request, thus it will hit UnsupportedOperationException due to
// DisabledDataStreamFactory.
client.getDataStreamApi().stream();
}
use of org.apache.ratis.client.RaftClient 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.client.RaftClient in project incubator-ratis by apache.
the class Client method getClients.
public List<FileStoreClient> getClients(RaftProperties raftProperties) {
List<FileStoreClient> fileStoreClients = new ArrayList<>();
for (int i = 0; i < numClients; i++) {
final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers());
RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties);
builder.setRaftGroup(raftGroup);
builder.setClientRpc(new GrpcFactory(new org.apache.ratis.conf.Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
RaftPeer[] peers = getPeers();
builder.setPrimaryDataStreamServer(peers[0]);
RaftClient client = builder.build();
fileStoreClients.add(new FileStoreClient(client));
}
return fileStoreClients;
}
use of org.apache.ratis.client.RaftClient in project incubator-ratis by apache.
the class Client method run.
@Override
public void run() throws Exception {
RaftProperties raftProperties = new RaftProperties();
final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers());
RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties);
builder.setRaftGroup(raftGroup);
builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
RaftClient client = builder.build();
operation(client);
}
use of org.apache.ratis.client.RaftClient in project incubator-ratis by apache.
the class CounterClient method buildClient.
/**
* build the RaftClient instance which is used to communicate to
* Counter cluster
*
* @return the created client of Counter cluster
*/
private static RaftClient buildClient() {
RaftProperties raftProperties = new RaftProperties();
RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties).setRaftGroup(Constants.RAFT_GROUP).setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
return builder.build();
}
Aggregations