use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestSegmentedRaftLog method setup.
@Before
public void setup() throws Exception {
storageDir = getTestDir();
properties = new RaftProperties();
RaftServerConfigKeys.setStorageDir(properties, storageDir);
storage = new RaftStorage(storageDir, RaftServerConstants.StartupOption.REGULAR);
this.segmentMaxSize = RaftServerConfigKeys.Log.segmentSizeMax(properties).getSize();
this.preallocatedSize = RaftServerConfigKeys.Log.preallocatedSize(properties).getSize();
this.bufferSize = RaftServerConfigKeys.Log.writeBufferSize(properties).getSizeInt();
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class ServerRestartTests method testRestartWithCorruptedLogEntryWithWarnAndReturn.
@Test
public void testRestartWithCorruptedLogEntryWithWarnAndReturn() throws Exception {
final RaftProperties p = getProperties();
final Log.CorruptionPolicy policy = Log.corruptionPolicy(p);
Log.setCorruptionPolicy(p, Log.CorruptionPolicy.WARN_AND_RETURN);
runWithNewCluster(1, this::runTestRestartWithCorruptedLogEntry);
Log.setCorruptionPolicy(p, policy);
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestRaftServerJmx method testJmxBeans.
@Test(timeout = 30000)
public void testJmxBeans() throws Exception {
final int NUM_SERVERS = 3;
final MiniRaftClusterWithSimulatedRpc cluster = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster(3, new RaftProperties());
cluster.start();
waitForLeader(cluster);
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectInstance> objectInstances = platformMBeanServer.queryMBeans(new ObjectName("Ratis:*"), null);
Assert.assertEquals(NUM_SERVERS, objectInstances.size());
for (ObjectInstance instance : objectInstances) {
Object groupId = platformMBeanServer.getAttribute(instance.getObjectName(), "GroupId");
Assert.assertEquals(cluster.getGroupId().toString(), groupId);
}
cluster.shutdown();
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class MemoryRaftLogTest method testEntryDoNotPerformTruncation.
@Test
public void testEntryDoNotPerformTruncation() 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(0).build();
raftLog.append(entries2).forEach(CompletableFuture::join);
final LogEntryHeader[] termIndices = raftLog.getEntries(0, 10);
assertEquals(2, termIndices.length);
for (int i = 0; i < 2; i++) {
assertEquals(entries1[i].getIndex(), termIndices[i].getIndex());
assertEquals(entries1[i].getTerm(), termIndices[i].getTerm());
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestCacheEviction method testEvictionInSegmentedLog.
@Test
public void testEvictionInSegmentedLog() throws Exception {
final RaftProperties prop = new RaftProperties();
prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
RaftServerConfigKeys.Log.setSegmentSizeMax(prop, SizeInBytes.valueOf("8KB"));
RaftServerConfigKeys.Log.setPreallocatedSize(prop, SizeInBytes.valueOf("8KB"));
final RaftPeerId peerId = RaftPeerId.valueOf("s0");
final RaftGroupId groupId = RaftGroupId.randomId();
final RaftGroupMemberId memberId = RaftGroupMemberId.valueOf(peerId, groupId);
final int maxCachedNum = RaftServerConfigKeys.Log.segmentCacheNumMax(prop);
File storageDir = getTestDir();
RaftServerConfigKeys.setStorageDir(prop, Collections.singletonList(storageDir));
RaftStorage storage = RaftStorageTestUtils.newRaftStorage(storageDir);
final DivisionInfo info = Mockito.mock(DivisionInfo.class);
Mockito.when(info.getLastAppliedIndex()).thenReturn(0L);
Mockito.when(info.getFollowerNextIndices()).thenReturn(new long[] {});
final SegmentedRaftLog raftLog = RaftServerTestUtil.newSegmentedRaftLog(memberId, info, storage, prop);
raftLog.open(RaftLog.INVALID_LOG_INDEX, null);
List<SegmentRange> slist = TestSegmentedRaftLog.prepareRanges(0, maxCachedNum, 7, 0);
LogEntryProto[] entries = generateEntries(slist);
raftLog.append(entries).forEach(CompletableFuture::join);
// check the current cached segment number: the last segment is still open
Assert.assertEquals(maxCachedNum - 1, raftLog.getRaftLogCache().getCachedSegmentNum());
Mockito.when(info.getLastAppliedIndex()).thenReturn(35L);
Mockito.when(info.getFollowerNextIndices()).thenReturn(new long[] { 21, 40, 40 });
slist = TestSegmentedRaftLog.prepareRanges(maxCachedNum, maxCachedNum + 2, 7, 7 * maxCachedNum);
entries = generateEntries(slist);
raftLog.append(entries).forEach(CompletableFuture::join);
// check the cached segment number again. since the slowest follower is on
// index 21, the eviction should happen and evict 3 segments
Assert.assertEquals(maxCachedNum + 1 - 3, raftLog.getRaftLogCache().getCachedSegmentNum());
}
Aggregations