Search in sources :

Example 1 with MiniRaftCluster

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);
    }
}
Also used : MiniRaftCluster(org.apache.ratis.MiniRaftCluster)

Example 2 with MiniRaftCluster

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();
}
Also used : MiniRaftCluster(org.apache.ratis.MiniRaftCluster) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 3 with MiniRaftCluster

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();
}
Also used : MiniRaftCluster(org.apache.ratis.MiniRaftCluster) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 4 with MiniRaftCluster

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();
}
Also used : MiniRaftCluster(org.apache.ratis.MiniRaftCluster) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 5 with MiniRaftCluster

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();
    }
}
Also used : MiniRaftCluster(org.apache.ratis.MiniRaftCluster) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Aggregations

MiniRaftCluster (org.apache.ratis.MiniRaftCluster)19 BaseTest (org.apache.ratis.BaseTest)16 Test (org.junit.Test)16 RaftClient (org.apache.ratis.client.RaftClient)11 IOException (java.io.IOException)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 PeerChanges (org.apache.ratis.MiniRaftCluster.PeerChanges)6 SimpleMessage (org.apache.ratis.RaftTestUtil.SimpleMessage)4 RaftClientRpc (org.apache.ratis.client.RaftClientRpc)4 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 RaftGroup (org.apache.ratis.protocol.RaftGroup)2 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)2 RaftPeer (org.apache.ratis.protocol.RaftPeer)2 RaftLog (org.apache.ratis.server.storage.RaftLog)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1