use of org.apache.ignite.raft.jraft.Node in project ignite-3 by apache.
the class ItNodeTest method testSetPeer1.
@Test
public void testSetPeer1() throws Exception {
cluster = new TestCluster("testSetPeer1", dataPath, new ArrayList<>(), testInfo);
PeerId bootPeer = new PeerId(TestUtils.getLocalAddress(), TestUtils.INIT_PORT);
assertTrue(cluster.start(bootPeer.getEndpoint()));
List<Node> nodes = cluster.getFollowers();
assertEquals(1, nodes.size());
List<PeerId> peers = new ArrayList<>();
peers.add(bootPeer);
// reset peers from empty
assertTrue(nodes.get(0).resetPeers(new Configuration(peers)).isOk());
cluster.waitLeader();
assertNotNull(cluster.getLeader());
}
use of org.apache.ignite.raft.jraft.Node in project ignite-3 by apache.
the class ItNodeTest method testLeaderTransfer.
@Test
public void testLeaderTransfer() throws Exception {
List<PeerId> peers = TestUtils.generatePeers(3);
cluster = new TestCluster("unitest", dataPath, peers, ELECTION_TIMEOUT_MILLIS, testInfo);
for (PeerId peer : peers) assertTrue(cluster.start(peer.getEndpoint()));
cluster.waitLeader();
Node leader = cluster.getLeader();
assertNotNull(leader);
sendTestTaskAndWait(leader);
Thread.sleep(100);
List<Node> followers = cluster.getFollowers();
assertEquals(2, followers.size());
PeerId targetPeer = followers.get(0).getNodeId().getPeerId().copy();
LOG.info("Transfer leadership from {} to {}", leader, targetPeer);
assertTrue(leader.transferLeadershipTo(targetPeer).isOk());
cluster.waitLeader();
leader = cluster.getLeader();
assertEquals(leader.getNodeId().getPeerId(), targetPeer);
}
use of org.apache.ignite.raft.jraft.Node in project ignite-3 by apache.
the class ItNodeTest method testRestoreSnapshot.
/**
* @throws Exception
*/
@Test
public void testRestoreSnapshot() throws Exception {
List<PeerId> peers = TestUtils.generatePeers(3);
cluster = new TestCluster("unitest", dataPath, peers, testInfo);
for (PeerId peer : peers) assertTrue(cluster.start(peer.getEndpoint()));
cluster.waitLeader();
// get leader
Node leader = cluster.getLeader();
LOG.info("Leader: " + leader);
assertNotNull(leader);
// apply tasks to leader
sendTestTaskAndWait(leader);
cluster.ensureSame();
triggerLeaderSnapshot(cluster, leader);
// stop leader
Endpoint leaderAddr = leader.getNodeId().getPeerId().getEndpoint().copy();
assertTrue(cluster.stop(leaderAddr));
// restart leader
cluster.waitLeader();
assertEquals(0, cluster.getLeaderFsm().getLoadSnapshotTimes());
assertTrue(cluster.start(leaderAddr));
cluster.ensureSame();
assertEquals(0, cluster.getLeaderFsm().getLoadSnapshotTimes());
}
use of org.apache.ignite.raft.jraft.Node in project ignite-3 by apache.
the class ItNodeTest method testLeaderShouldNotChange.
@Test
public void testLeaderShouldNotChange() throws Exception {
List<PeerId> peers = TestUtils.generatePeers(3);
cluster = new TestCluster("unitest", dataPath, peers, testInfo);
for (PeerId peer : peers) assertTrue(cluster.start(peer.getEndpoint()));
cluster.waitLeader();
// get leader
Node leader0 = cluster.getLeader();
assertNotNull(leader0);
long savedTerm = ((NodeImpl) leader0).getCurrentTerm();
LOG.info("Current leader is {}, term is {}", leader0, savedTerm);
Thread.sleep(5000);
cluster.waitLeader();
Node leader1 = cluster.getLeader();
assertNotNull(leader1);
LOG.info("Current leader is {}", leader1);
assertEquals(savedTerm, ((NodeImpl) leader1).getCurrentTerm());
}
use of org.apache.ignite.raft.jraft.Node in project ignite-3 by apache.
the class ItNodeTest method testBlockedElection.
@Test
public void testBlockedElection() throws Exception {
List<PeerId> peers = TestUtils.generatePeers(3);
cluster = new TestCluster("unittest", dataPath, peers, testInfo);
for (PeerId peer : peers) assertTrue(cluster.start(peer.getEndpoint()));
cluster.waitLeader();
Node leader = cluster.getLeader();
LOG.warn("Current leader {}, electTimeout={}", leader.getNodeId().getPeerId(), leader.getOptions().getElectionTimeoutMs());
List<Node> followers = cluster.getFollowers();
blockMessagesOnFollowers(followers, (msg, nodeId) -> {
if (msg instanceof RpcRequests.RequestVoteRequest) {
RpcRequests.RequestVoteRequest msg0 = (RpcRequests.RequestVoteRequest) msg;
return !msg0.preVote();
}
return false;
});
LOG.warn("Stop leader {}, curTerm={}", leader.getNodeId().getPeerId(), ((NodeImpl) leader).getCurrentTerm());
assertTrue(cluster.stop(leader.getNodeId().getPeerId().getEndpoint()));
assertNull(cluster.getLeader());
Thread.sleep(2000);
assertNull(cluster.getLeader());
stopBlockingMessagesOnFollowers(followers);
// elect new leader
cluster.waitLeader();
leader = cluster.getLeader();
LOG.info("Elect new leader is {}, curTerm={}", leader.getLeaderId(), ((NodeImpl) leader).getCurrentTerm());
}
Aggregations