use of org.apache.ratis.proto.RaftProtos.LogEntryProto.LogEntryBodyCase in project incubator-ratis by apache.
the class LogAppenderTests method runTest.
void runTest(CLUSTER cluster) throws Exception {
final int numMsgs = 10;
final int numClients = 5;
final RaftPeerId leaderId = RaftTestUtil.waitForLeader(cluster).getId();
List<RaftClient> clients = new ArrayList<>();
try {
List<Sender> senders = new ArrayList<>();
// start several clients and write concurrently
final CountDownLatch latch = new CountDownLatch(1);
for (int i = 0; i < numClients; i++) {
RaftClient client = cluster.createClient(leaderId);
clients.add(client);
senders.add(new Sender(client, numMsgs, latch));
}
senders.forEach(Thread::start);
latch.countDown();
for (Sender s : senders) {
s.join();
final Exception e = s.exception.get();
if (e != null) {
throw e;
}
Assert.assertTrue(s.succeed.get());
}
} finally {
for (int i = 0; i < clients.size(); i++) {
try {
clients.get(i).close();
} catch (Exception ignored) {
LOG.warn("{} is ignored", JavaUtils.getClassSimpleName(ignored.getClass()), ignored);
}
}
}
final RaftServer.Division leader = cluster.getLeader();
final RaftLog leaderLog = cluster.getLeader().getRaftLog();
final EnumMap<LogEntryBodyCase, AtomicLong> counts = RaftTestUtil.countEntries(leaderLog);
LOG.info("counts = " + counts);
Assert.assertEquals(6 * numMsgs * numClients, counts.get(LogEntryBodyCase.STATEMACHINELOGENTRY).get());
final LogEntryProto last = RaftTestUtil.getLastEntry(LogEntryBodyCase.STATEMACHINELOGENTRY, leaderLog);
LOG.info("last = {}", LogProtoUtils.toLogEntryString(last));
Assert.assertNotNull(last);
Assert.assertTrue(last.getIndex() <= leader.getInfo().getLastAppliedIndex());
}
use of org.apache.ratis.proto.RaftProtos.LogEntryProto.LogEntryBodyCase in project incubator-ratis by apache.
the class RaftTestUtil method countEntries.
static EnumMap<LogEntryBodyCase, AtomicLong> countEntries(RaftLog raftLog) throws Exception {
final EnumMap<LogEntryBodyCase, AtomicLong> counts = new EnumMap<>(LogEntryBodyCase.class);
for (long i = 0; i < raftLog.getNextIndex(); i++) {
final LogEntryProto e = raftLog.get(i);
counts.computeIfAbsent(e.getLogEntryBodyCase(), c -> new AtomicLong()).incrementAndGet();
}
return counts;
}
use of org.apache.ratis.proto.RaftProtos.LogEntryProto.LogEntryBodyCase in project incubator-ratis by apache.
the class OutputStreamBaseTest method assertRaftLog.
private RaftLog assertRaftLog(int expectedEntries, RaftServer.Division server) throws Exception {
final RaftLog raftLog = server.getRaftLog();
final EnumMap<LogEntryBodyCase, AtomicLong> counts = RaftTestUtil.countEntries(raftLog);
Assert.assertEquals(expectedEntries, counts.get(LogEntryBodyCase.STATEMACHINELOGENTRY).get());
final LogEntryProto last = RaftTestUtil.getLastEntry(LogEntryBodyCase.STATEMACHINELOGENTRY, raftLog);
Assert.assertNotNull(last);
Assert.assertTrue(raftLog.getLastCommittedIndex() >= last.getIndex());
Assert.assertTrue(server.getInfo().getLastAppliedIndex() >= last.getIndex());
return raftLog;
}
Aggregations