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();
}
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);
}
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);
}
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();
}
}
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();
}
}
Aggregations