use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class MiniRaftCluster method newRaftServer.
private RaftServerProxy newRaftServer(RaftPeerId id, RaftGroup group, boolean format) {
LOG.info("newRaftServer: {}, {}, format? {}", id, group, format);
try {
final File dir = getStorageDir(id);
if (format) {
FileUtils.deleteFully(dir);
LOG.info("Formatted directory {}", dir);
}
final RaftProperties prop = new RaftProperties(properties);
RaftServerConfigKeys.setStorageDir(prop, Collections.singletonList(dir));
return ServerImplUtils.newRaftServer(id, group, getStateMachineRegistry(prop), prop, setPropertiesAndInitParameters(id, group, prop));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class WatchRequestTests method runTestWatchRequestTimeout.
static void runTestWatchRequestTimeout(TestParameters p) throws Exception {
final Logger LOG = p.log;
final MiniRaftCluster cluster = p.cluster;
final int numMessages = p.numMessages;
final RaftProperties properties = cluster.getProperties();
final TimeDuration watchTimeout = RaftServerConfigKeys.Watch.timeout(properties);
final TimeDuration watchTimeoutDenomination = RaftServerConfigKeys.Watch.timeoutDenomination(properties);
// blockStartTransaction of the leader so that no transaction can be committed MAJORITY
final RaftServer.Division leader = cluster.getLeader();
LOG.info("block leader {}", leader.getId());
SimpleStateMachine4Testing.get(leader).blockStartTransaction();
// blockFlushStateMachineData a follower so that no transaction can be ALL_COMMITTED
final List<RaftServer.Division> followers = cluster.getFollowers();
final RaftServer.Division blockedFollower = followers.get(ThreadLocalRandom.current().nextInt(followers.size()));
LOG.info("block follower {}", blockedFollower.getId());
SimpleStateMachine4Testing.get(blockedFollower).blockFlushStateMachineData();
// send a message
final List<CompletableFuture<RaftClientReply>> replies = new ArrayList<>();
final List<CompletableFuture<WatchReplies>> watches = new ArrayList<>();
p.sendRequests(replies, watches);
Assert.assertEquals(numMessages, replies.size());
Assert.assertEquals(numMessages, watches.size());
watchTimeout.sleep();
// for roundup error
watchTimeoutDenomination.sleep();
assertNotDone(replies);
assertNotDone(watches);
// unblock leader so that the transaction can be committed.
SimpleStateMachine4Testing.get(leader).unblockStartTransaction();
LOG.info("unblock leader {}", leader.getId());
checkMajority(replies, watches, LOG);
checkTimeout(replies, watches, LOG);
SimpleStateMachine4Testing.get(blockedFollower).unblockFlushStateMachineData();
LOG.info("unblock follower {}", blockedFollower.getId());
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class WatchRequestTests method testWatchRequestClientTimeout.
@Test
public void testWatchRequestClientTimeout() throws Exception {
final RaftProperties p = getProperties();
RaftServerConfigKeys.Watch.setTimeout(p, TimeDuration.valueOf(100, TimeUnit.SECONDS));
RaftClientConfigKeys.Rpc.setWatchRequestTimeout(p, TimeDuration.valueOf(15, TimeUnit.SECONDS));
try {
runWithNewCluster(NUM_SERVERS, cluster -> runSingleTest(WatchRequestTests::runTestWatchRequestClientTimeout, cluster, LOG));
} finally {
RaftServerConfigKeys.Watch.setTimeout(p, RaftServerConfigKeys.Watch.TIMEOUT_DEFAULT);
RaftClientConfigKeys.Rpc.setWatchRequestTimeout(p, RaftClientConfigKeys.Rpc.WATCH_REQUEST_TIMEOUT_DEFAULT);
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class WatchRequestTests method testWatchRequestTimeout.
@Test
public void testWatchRequestTimeout() throws Exception {
final RaftProperties p = getProperties();
RaftServerConfigKeys.Watch.setTimeout(p, TimeDuration.valueOf(500, TimeUnit.MILLISECONDS));
RaftServerConfigKeys.Watch.setTimeoutDenomination(p, TimeDuration.valueOf(100, TimeUnit.MILLISECONDS));
try {
runWithNewCluster(NUM_SERVERS, cluster -> runTest(WatchRequestTests::runTestWatchRequestTimeout, cluster, LOG));
} finally {
RaftServerConfigKeys.Watch.setTimeout(p, RaftServerConfigKeys.Watch.TIMEOUT_DEFAULT);
RaftServerConfigKeys.Watch.setTimeoutDenomination(p, RaftServerConfigKeys.Watch.TIMEOUT_DENOMINATION_DEFAULT);
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class LeaderElectionTests method createMockServer.
private static RaftServerImpl createMockServer(boolean alive) {
final DivisionInfo info = mock(DivisionInfo.class);
when(info.isAlive()).thenReturn(alive);
when(info.isCandidate()).thenReturn(false);
RaftServerImpl server = mock(RaftServerImpl.class);
when(server.getInfo()).thenReturn(info);
final RaftGroupMemberId memberId = RaftGroupMemberId.valueOf(RaftPeerId.valueOf("any"), RaftGroupId.randomId());
when(server.getMemberId()).thenReturn(memberId);
LeaderElectionMetrics leaderElectionMetrics = LeaderElectionMetrics.getLeaderElectionMetrics(memberId, () -> 0);
when(server.getLeaderElectionMetrics()).thenReturn(leaderElectionMetrics);
RaftServerProxy proxy = mock(RaftServerProxy.class);
RaftProperties properties = new RaftProperties();
RaftServerConfigKeys.LeaderElection.setPreVote(properties, true);
when(proxy.getProperties()).thenReturn(properties);
when(server.getRaftServer()).thenReturn(proxy);
return server;
}
Aggregations