Search in sources :

Example 46 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class RaftSnapshotBaseTest method setup.

@Before
public void setup() throws IOException {
    final RaftProperties prop = new RaftProperties();
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    RaftServerConfigKeys.Snapshot.setAutoTriggerThreshold(prop, SNAPSHOT_TRIGGER_THRESHOLD);
    RaftServerConfigKeys.Snapshot.setAutoTriggerEnabled(prop, true);
    this.cluster = getFactory().newCluster(1, prop);
    cluster.start();
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Before(org.junit.Before)

Example 47 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class SnapshotManagementTest method setup.

@Before
public void setup() {
    final RaftProperties p = getProperties();
    p.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    RaftServerConfigKeys.Snapshot.setCreationGap(p, 20L);
    RaftServerConfigKeys.Snapshot.setAutoTriggerEnabled(p, false);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Before(org.junit.Before)

Example 48 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class TestNettyDataStreamWithMock method setup.

@Before
public void setup() {
    properties = new RaftProperties();
    RaftConfigKeys.DataStream.setType(properties, SupportedDataStreamType.NETTY);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Before(org.junit.Before)

Example 49 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class TestLogAppenderWithGrpc method testPendingLimits.

@Test
public void testPendingLimits() throws IOException, InterruptedException {
    int maxAppends = 10;
    RaftProperties properties = new RaftProperties();
    properties.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    GrpcConfigKeys.Server.setLeaderOutstandingAppendsMax(properties, maxAppends);
    RaftServerConfigKeys.Log.Appender.setBufferElementLimit(properties, 1);
    MiniRaftClusterWithGrpc cluster = getFactory().newCluster(3, properties);
    cluster.start();
    // client and leader setup
    try (final RaftClient client = cluster.createClient(cluster.getGroup())) {
        client.io().send(new RaftTestUtil.SimpleMessage("m"));
        final RaftServer.Division leader = waitForLeader(cluster);
        long initialNextIndex = RaftServerTestUtil.getNextIndex(leader);
        for (RaftServer.Division server : cluster.getFollowers()) {
            // block the appends in the follower
            SimpleStateMachine4Testing.get(server).blockWriteStateMachineData();
        }
        Collection<CompletableFuture<RaftClientReply>> futures = new ArrayList<>(maxAppends * 2);
        for (int i = 0; i < maxAppends * 2; i++) {
            futures.add(client.async().send(new RaftTestUtil.SimpleMessage("m")));
        }
        FIVE_SECONDS.sleep();
        for (long nextIndex : leader.getInfo().getFollowerNextIndices()) {
            // Verify nextIndex does not progress due to pendingRequests limit
            Assert.assertEquals(initialNextIndex + maxAppends, nextIndex);
        }
        ONE_SECOND.sleep();
        for (RaftServer.Division server : cluster.getFollowers()) {
            // unblock the appends in the follower
            SimpleStateMachine4Testing.get(server).unblockWriteStateMachineData();
        }
        JavaUtils.allOf(futures).join();
        cluster.shutdown();
    }
}
Also used : RaftTestUtil(org.apache.ratis.RaftTestUtil) RaftServer(org.apache.ratis.server.RaftServer) RaftProperties(org.apache.ratis.conf.RaftProperties) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) RaftClient(org.apache.ratis.client.RaftClient) Test(org.junit.Test)

Example 50 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class StateMachineShutdownTests method testStateMachineShutdownWaitsForApplyTxn.

@Test
public void testStateMachineShutdownWaitsForApplyTxn() throws Exception {
    final RaftProperties prop = getProperties();
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, StateMachineWithConditionalWait.class, StateMachine.class);
    final MiniRaftCluster cluster = newCluster(3);
    cluster.start();
    RaftTestUtil.waitForLeader(cluster);
    final RaftServer.Division leader = cluster.getLeader();
    RaftPeerId leaderId = leader.getId();
    // Unblock leader and one follower
    ((StateMachineWithConditionalWait) leader.getStateMachine()).unBlockApplyTxn();
    ((StateMachineWithConditionalWait) cluster.getFollowers().get(0).getStateMachine()).unBlockApplyTxn();
    cluster.getLeaderAndSendFirstMessage(true);
    try (final RaftClient client = cluster.createClient(leaderId)) {
        client.io().send(new RaftTestUtil.SimpleMessage("message"));
        RaftClientReply reply = client.io().send(new RaftTestUtil.SimpleMessage("message2"));
        long logIndex = reply.getLogIndex();
        // Confirm that followers have committed
        RaftClientReply watchReply = client.io().watch(logIndex, RaftProtos.ReplicationLevel.ALL_COMMITTED);
        watchReply.getCommitInfos().forEach(val -> Assert.assertTrue(val.getCommitIndex() >= logIndex));
        final RaftServer.Division secondFollower = cluster.getFollowers().get(1);
        // Second follower is blocked in apply transaction
        Assert.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < logIndex);
        // Now shutdown the follower in a separate thread
        final Thread t = new Thread(secondFollower::close);
        t.start();
        // The second follower should still be blocked in apply transaction
        Assert.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < logIndex);
        // Now unblock the second follower
        ((StateMachineWithConditionalWait) secondFollower.getStateMachine()).unBlockApplyTxn();
        // Now wait for the thread
        t.join(5000);
        Assert.assertEquals(logIndex, secondFollower.getInfo().getLastAppliedIndex());
        cluster.shutdown();
    }
}
Also used : RaftTestUtil(org.apache.ratis.RaftTestUtil) RaftServer(org.apache.ratis.server.RaftServer) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftClient(org.apache.ratis.client.RaftClient) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Aggregations

RaftProperties (org.apache.ratis.conf.RaftProperties)54 Test (org.junit.Test)22 BaseTest (org.apache.ratis.BaseTest)14 Before (org.junit.Before)12 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)9 RaftServer (org.apache.ratis.server.RaftServer)8 File (java.io.File)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 RaftClient (org.apache.ratis.client.RaftClient)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Parameters (org.apache.ratis.conf.Parameters)4 LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)4 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)4 RaftGroupMemberId (org.apache.ratis.protocol.RaftGroupMemberId)4 RaftGroup (org.apache.ratis.protocol.RaftGroup)3 StateMachine (org.apache.ratis.statemachine.StateMachine)3 TimeDuration (org.apache.ratis.util.TimeDuration)3 List (java.util.List)2 UUID (java.util.UUID)2