use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.
the class TestRaftConfiguration method testIsHighestPriority.
@Test
public void testIsHighestPriority() {
Integer node1 = 0;
Integer node2 = 1;
Integer node3 = 2;
PeerConfiguration peerConfig = new PeerConfiguration(raftPeersWithPriority(node1, node2, node3));
RaftConfiguration config = RaftConfigurationImpl.newBuilder().setConf(peerConfig).build();
RaftPeer[] allRaftPeers = peerConfig.getPeers().toArray(new RaftPeer[peerConfig.getPeers().size()]);
// First member should not have highest priority
Assert.assertFalse(RaftServerTestUtil.isHighestPriority(config, allRaftPeers[0].getId()));
// Last member should have highest priority
Assert.assertTrue(RaftServerTestUtil.isHighestPriority(config, allRaftPeers[allRaftPeers.length - 1].getId()));
// Should return false for non existent peer id
Assert.assertFalse(RaftServerTestUtil.isHighestPriority(config, RaftPeerId.valueOf("123456789")));
}
use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.
the class LeaderProtoUtils method toInstallSnapshotRequestProtoBuilder.
private static InstallSnapshotRequestProto.Builder toInstallSnapshotRequestProtoBuilder(RaftServer.Division server, RaftPeerId replyId) {
// term is not going to used by installSnapshot to update the RaftConfiguration
final RaftConfiguration conf = server.getRaftConf();
final LogEntryProto confLogEntryProto = LogProtoUtils.toLogEntryProto(conf, null, conf.getLogEntryIndex());
return InstallSnapshotRequestProto.newBuilder().setServerRequest(ClientProtoUtils.toRaftRpcRequestProtoBuilder(server.getMemberId(), replyId)).setLeaderTerm(server.getInfo().getCurrentTerm()).setLastRaftConfigurationLogEntryProto(confLogEntryProto);
}
use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.
the class ConfigurationManager method addConfiguration.
synchronized void addConfiguration(RaftConfiguration conf) {
final long logIndex = conf.getLogEntryIndex();
final RaftConfiguration found = configurations.get(logIndex);
if (found != null) {
Preconditions.assertTrue(found.equals(conf));
return;
}
addRaftConfigurationImpl(logIndex, (RaftConfigurationImpl) conf);
}
use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.
the class RaftReconfigurationBaseTest method checkPriority.
private void checkPriority(CLUSTER cluster, RaftGroupId groupId, List<RaftPeer> peersWithPriority) throws InterruptedException {
RaftTestUtil.waitForLeader(cluster, groupId);
for (int i = 0; i < peersWithPriority.size(); i++) {
RaftPeerId peerId = peersWithPriority.get(i).getId();
final RaftServer.Division server = cluster.getDivision(peerId, groupId);
final RaftConfiguration conf = server.getRaftConf();
for (int j = 0; j < peersWithPriority.size(); j++) {
int priorityInConf = conf.getPeer(peersWithPriority.get(j).getId()).getPriority();
Assert.assertEquals(priorityInConf, peersWithPriority.get(j).getPriority());
}
}
}
use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.
the class RaftReconfigurationBaseTest method runTestNoChangeRequest.
void runTestNoChangeRequest(CLUSTER cluster) throws Exception {
final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
try (final RaftClient client = cluster.createClient(leader.getId())) {
client.io().send(new SimpleMessage("m"));
final RaftLog leaderLog = leader.getRaftLog();
final long committedIndex = leaderLog.getLastCommittedIndex();
final RaftConfiguration confBefore = cluster.getLeader().getRaftConf();
// no real configuration change in the request
final RaftClientReply reply = client.admin().setConfiguration(cluster.getPeers().toArray(RaftPeer.emptyArray()));
Assert.assertTrue(reply.isSuccess());
final long newCommittedIndex = leaderLog.getLastCommittedIndex();
for (long i = committedIndex + 1; i <= newCommittedIndex; i++) {
final LogEntryProto e = leaderLog.get(i);
Assert.assertTrue(e.hasMetadataEntry());
}
Assert.assertSame(confBefore, cluster.getLeader().getRaftConf());
}
}
Aggregations