use of org.apache.ratis.RaftTestUtil.SimpleMessage in project incubator-ratis by apache.
the class MessageStreamApiTests method runTestStreamAsync.
void runTestStreamAsync(CLUSTER cluster) throws Exception {
RaftTestUtil.waitForLeader(cluster);
ByteString bytes = ByteString.EMPTY;
for (int i = 0; i < 10; ) {
final String s = (char) ('A' + i) + "1234567";
LOG.info("s=" + s);
final ByteString b = ByteString.copyFrom(s, StandardCharsets.UTF_8);
Assert.assertEquals(8, b.size());
for (int j = 0; j < 128; j++) {
bytes = bytes.concat(b);
}
i++;
Assert.assertEquals(i * SUBMESSAGE_SIZE.getSizeInt(), bytes.size());
}
try (RaftClient client = cluster.createClient()) {
final RaftClientReply reply = client.getMessageStreamApi().streamAsync(Message.valueOf(bytes)).get();
Assert.assertTrue(reply.isSuccess());
}
// check if all the parts are streamed as a single message.
try (RaftClient client = cluster.createClient()) {
final RaftClientReply reply = client.io().sendReadOnly(new SimpleMessage(bytes.toString(StandardCharsets.UTF_8)));
Assert.assertTrue(reply.isSuccess());
}
}
use of org.apache.ratis.RaftTestUtil.SimpleMessage in project incubator-ratis by apache.
the class MessageStreamApiTests method runTestStream.
void runTestStream(CLUSTER cluster) throws Exception {
RaftTestUtil.waitForLeader(cluster);
// stream multiple parts
final int numParts = 9;
final int endOfRequest = 6;
final StringBuilder key = new StringBuilder();
try (RaftClient client = cluster.createClient();
MessageOutputStream out = client.getMessageStreamApi().stream()) {
for (int i = 1; i <= numParts; i++) {
key.append(i);
out.sendAsync(new SimpleMessage(i + ""), i == endOfRequest);
}
}
// check if all the parts are streamed as a single message.
final String k = key.toString();
try (RaftClient client = cluster.createClient()) {
final String k1 = k.substring(0, endOfRequest);
final RaftClientReply r1 = client.io().sendReadOnly(new SimpleMessage(k1));
Assert.assertTrue(r1.isSuccess());
final String k2 = k.substring(endOfRequest);
final RaftClientReply r2 = client.io().sendReadOnly(new SimpleMessage(k2));
Assert.assertTrue(r2.isSuccess());
}
}
Aggregations