Search in sources :

Example 21 with RaftProperties

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);
    }
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) IOException(java.io.IOException) File(java.io.File)

Example 22 with RaftProperties

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());
}
Also used : RaftServer(org.apache.ratis.server.RaftServer) RaftProperties(org.apache.ratis.conf.RaftProperties) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) CompletableFuture(java.util.concurrent.CompletableFuture) MiniRaftCluster(org.apache.ratis.server.impl.MiniRaftCluster) TimeDuration(org.apache.ratis.util.TimeDuration)

Example 23 with RaftProperties

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

Example 24 with RaftProperties

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

Example 25 with RaftProperties

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;
}
Also used : DivisionInfo(org.apache.ratis.server.DivisionInfo) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) LeaderElectionMetrics(org.apache.ratis.server.metrics.LeaderElectionMetrics)

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