use of com.alipay.sofa.jraft.error.RaftError in project sofa-jraft by sofastack.
the class NodeTest method startChangePeersThread.
private Future<?> startChangePeersThread(final ChangeArg arg) {
final Set<RaftError> expectedErrors = new HashSet<>();
expectedErrors.add(RaftError.EBUSY);
expectedErrors.add(RaftError.EPERM);
expectedErrors.add(RaftError.ECATCHUP);
return Utils.runInThread(() -> {
try {
while (!arg.stop) {
arg.c.waitLeader();
final Node leader = arg.c.getLeader();
if (leader == null) {
continue;
}
// select peers in random
final Configuration conf = new Configuration();
if (arg.dontRemoveFirstPeer) {
conf.addPeer(arg.peers.get(0));
}
for (int i = 0; i < arg.peers.size(); i++) {
final boolean select = ThreadLocalRandom.current().nextInt(64) < 32;
if (select && !conf.contains(arg.peers.get(i))) {
conf.addPeer(arg.peers.get(i));
}
}
if (conf.isEmpty()) {
LOG.warn("No peer has been selected");
continue;
}
final SynchronizedClosure done = new SynchronizedClosure();
leader.changePeers(conf, done);
done.await();
assertTrue(done.getStatus().toString(), done.getStatus().isOk() || expectedErrors.contains(done.getStatus().getRaftError()));
}
} catch (final InterruptedException e) {
LOG.error("ChangePeersThread is interrupted", e);
}
});
}
Aggregations