Search in sources :

Example 11 with RaftProperties

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

the class TestExceptionDependentRetry method testExceptionRetryAttempts.

@Test
public void testExceptionRetryAttempts() throws Exception {
    final RaftProperties prop = getProperties();
    RaftClientConfigKeys.Rpc.setRequestTimeout(prop, TimeDuration.valueOf(100, TimeUnit.MILLISECONDS));
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    RaftServerConfigKeys.Write.setElementLimit(prop, 1);
    runWithNewCluster(1, this::runTestExceptionRetryAttempts);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 12 with RaftProperties

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

the class ServerRestartTests method testRestartWithCorruptedLogEntryWithException.

@Test
public void testRestartWithCorruptedLogEntryWithException() throws Exception {
    final RaftProperties p = getProperties();
    final Log.CorruptionPolicy policy = Log.corruptionPolicy(p);
    Log.setCorruptionPolicy(p, Log.CorruptionPolicy.EXCEPTION);
    testFailureCase("restart-fail-ChecksumException", () -> runWithNewCluster(1, this::runTestRestartWithCorruptedLogEntry), CompletionException.class, ChecksumException.class);
    Log.setCorruptionPolicy(p, policy);
}
Also used : RaftLog(org.apache.ratis.server.raftlog.RaftLog) TestSegmentedRaftLog(org.apache.ratis.server.raftlog.segmented.TestSegmentedRaftLog) Log(org.apache.ratis.server.RaftServerConfigKeys.Log) RaftProperties(org.apache.ratis.conf.RaftProperties) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 13 with RaftProperties

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

the class MemoryRaftLogTest method testEntryPerformTruncation.

@Test
public void testEntryPerformTruncation() throws Exception {
    final RaftProperties prop = new RaftProperties();
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    final RaftPeerId peerId = RaftPeerId.valueOf("s0");
    final RaftGroupId groupId = RaftGroupId.randomId();
    final RaftGroupMemberId memberId = RaftGroupMemberId.valueOf(peerId, groupId);
    MemoryRaftLog raftLog = new MemoryRaftLog(memberId, () -> -1, prop);
    raftLog.open(RaftLog.INVALID_LOG_INDEX, null);
    LogEntryProto[] entries1 = new LogEntryProto[2];
    entries1[0] = LogEntryProto.newBuilder().setIndex(0).setTerm(0).build();
    entries1[1] = LogEntryProto.newBuilder().setIndex(1).setTerm(0).build();
    raftLog.append(entries1).forEach(CompletableFuture::join);
    LogEntryProto[] entries2 = new LogEntryProto[1];
    entries2[0] = LogEntryProto.newBuilder().setIndex(0).setTerm(2).build();
    raftLog.append(entries2).forEach(CompletableFuture::join);
    final LogEntryHeader[] termIndices = raftLog.getEntries(0, 10);
    assertEquals(1, termIndices.length);
    assertEquals(entries2[0].getIndex(), termIndices[0].getIndex());
    assertEquals(entries2[0].getTerm(), termIndices[0].getTerm());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) LogEntryHeader(org.apache.ratis.server.raftlog.LogEntryHeader) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 14 with RaftProperties

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

the class TestRaftServerConfigKeys method testStorageDirProperty.

/**
 * Sets the value to <code>raft.server.storage.dir</code> via
 * RaftServerConfigKeys and verifies it by reading directly from property.
 */
@Test
public void testStorageDirProperty() {
    final File testDir = new File(rootTestDir.get(), UUID.randomUUID().toString());
    final List<File> directories = new ArrayList<>();
    final RaftProperties properties = new RaftProperties();
    IntStream.range(0, 10).mapToObj((i) -> new File(testDir, Integer.toString(i))).forEach(directories::add);
    RaftServerConfigKeys.setStorageDir(properties, directories);
    final String expected = directories.stream().map(File::getAbsolutePath).collect(Collectors.joining(","));
    final String actual = properties.get(RaftServerConfigKeys.STORAGE_DIR_KEY);
    Assert.assertEquals(expected, actual);
}
Also used : IntStream(java.util.stream.IntStream) AfterClass(org.junit.AfterClass) ConfUtils.setSizeInBytes(org.apache.ratis.conf.ConfUtils.setSizeInBytes) Test(org.junit.Test) IOException(java.io.IOException) UUID(java.util.UUID) BaseTest(org.apache.ratis.BaseTest) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) File(java.io.File) FileUtils(org.apache.ratis.util.FileUtils) ArrayList(java.util.ArrayList) BYTE_LIMIT_KEY(org.apache.ratis.server.RaftServerConfigKeys.Write.BYTE_LIMIT_KEY) List(java.util.List) ConfUtils.requireMin(org.apache.ratis.conf.ConfUtils.requireMin) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RaftProperties(org.apache.ratis.conf.RaftProperties) JavaUtils(org.apache.ratis.util.JavaUtils) Assert(org.junit.Assert) SizeInBytes(org.apache.ratis.util.SizeInBytes) ArrayList(java.util.ArrayList) RaftProperties(org.apache.ratis.conf.RaftProperties) File(java.io.File) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 15 with RaftProperties

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

the class TestRaftServerConfigKeys method testPendingRequestSize.

/**
 * Sets the value to <code>raft.server.write.byte-limit</code> via
 * RaftServerConfigKeys and also verifies the same via RaftServerConfigKeys.
 */
@Test
public void testPendingRequestSize() {
    RaftProperties properties = new RaftProperties();
    // setting to 4GB
    setSizeInBytes(properties::set, BYTE_LIMIT_KEY, SizeInBytes.valueOf("4gb"), requireMin(1L));
    int pendingRequestMegabyteLimit = Math.toIntExact(RaftServerConfigKeys.Write.byteLimit(properties).getSize() / SizeInBytes.ONE_MB.getSize());
    Assert.assertEquals(4096, pendingRequestMegabyteLimit);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) 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