use of org.apache.ratis.MiniRaftCluster in project incubator-ratis by apache.
the class ParameterizedBaseTest method setAndStart.
/**
* Set {@link #currentCluster} to the given cluster and start it if {@link #currentCluster} is changed.
*/
public static void setAndStart(MiniRaftCluster cluster) throws InterruptedException {
final MiniRaftCluster previous = currentCluster.getAndSet(cluster);
if (previous != cluster) {
if (previous != null) {
previous.shutdown();
}
cluster.start();
RaftTestUtil.waitForLeader(cluster);
}
}
use of org.apache.ratis.MiniRaftCluster in project incubator-ratis by apache.
the class LeaderElectionTests method testEnforceLeader.
@Test
public void testEnforceLeader() throws Exception {
final int numServer = 3;
LOG.info("Running testEnforceLeader");
final String leader = "s" + ThreadLocalRandom.current().nextInt(numServer);
LOG.info("enforce leader to " + leader);
final MiniRaftCluster cluster = newCluster(numServer);
cluster.start();
waitForLeader(cluster);
waitForLeader(cluster, leader);
cluster.shutdown();
}
use of org.apache.ratis.MiniRaftCluster in project incubator-ratis by apache.
the class LeaderElectionTests method testChangeLeader.
@Test
public void testChangeLeader() throws Exception {
RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.TRACE);
LOG.info("Running testChangeLeader");
final MiniRaftCluster cluster = newCluster(3);
cluster.start();
RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId();
for (int i = 0; i < 10; i++) {
leader = RaftTestUtil.changeLeader(cluster, leader);
ExitUtils.assertNotTerminated();
}
RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.INFO);
cluster.shutdown();
}
use of org.apache.ratis.MiniRaftCluster in project incubator-ratis by apache.
the class LeaderElectionTests method testBasicLeaderElection.
@Test
public void testBasicLeaderElection() throws Exception {
LOG.info("Running testBasicLeaderElection");
final MiniRaftCluster cluster = newCluster(5);
cluster.start();
waitAndKillLeader(cluster, true);
waitAndKillLeader(cluster, true);
waitAndKillLeader(cluster, true);
waitAndKillLeader(cluster, false);
cluster.shutdown();
}
use of org.apache.ratis.MiniRaftCluster in project incubator-ratis by apache.
the class RaftReconfigurationBaseTest method testAddPeers.
/**
* add 2 new peers (3 peers -> 5 peers), no leader change
*/
@Test
public void testAddPeers() throws Exception {
LOG.info("Start testAddPeers");
MiniRaftCluster cluster = getCluster(3);
cluster.start();
try {
RaftTestUtil.waitForLeader(cluster);
// add new peers
RaftPeer[] allPeers = cluster.addNewPeers(2, true).allPeersInNewConf;
// trigger setConfiguration
cluster.setConfiguration(allPeers);
// wait for the new configuration to take effect
waitAndCheckNewConf(cluster, allPeers, 0, null);
} finally {
cluster.shutdown();
}
}
Aggregations