use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestRaftServerConfigKeys method testStorageDir.
/**
* Sets the value to <code>raft.server.storage.dir</code> via
* RaftServerConfigKeys and also verifies the same via RaftServerConfigKeys.
*/
@Test
public void testStorageDir() {
final File testDir = new File(rootTestDir.get(), UUID.randomUUID().toString());
final List<File> directories = new ArrayList<>();
IntStream.range(0, 10).mapToObj((i) -> new File(testDir, Integer.toString(i))).forEach(directories::add);
RaftProperties properties = new RaftProperties();
RaftServerConfigKeys.setStorageDir(properties, directories);
final List<File> storageDirs = RaftServerConfigKeys.storageDir(properties);
final List<String> expectedDirs = directories.stream().map(File::getAbsolutePath).collect(Collectors.toList());
final List<String> actualDirs = storageDirs.stream().map(File::getAbsolutePath).collect(Collectors.toList());
actualDirs.removeAll(expectedDirs);
Assert.assertEquals(directories.size(), storageDirs.size());
Assert.assertEquals(0, actualDirs.size());
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestSegmentedRaftLog method purgeAndVerify.
private void purgeAndVerify(int startTerm, int endTerm, int segmentSize, int purgeGap, long purgeIndex, long expectedIndex) throws Exception {
List<SegmentRange> ranges = prepareRanges(startTerm, endTerm, segmentSize, 0);
List<LogEntryProto> entries = prepareLogEntries(ranges, null);
final RaftProperties p = new RaftProperties();
RaftServerConfigKeys.Log.setPurgeGap(p, purgeGap);
try (SegmentedRaftLog raftLog = newSegmentedRaftLog(storage, p)) {
raftLog.open(RaftLog.INVALID_LOG_INDEX, null);
entries.stream().map(raftLog::appendEntry).forEach(CompletableFuture::join);
final CompletableFuture<Long> f = raftLog.purge(purgeIndex);
final Long purged = f.get();
LOG.info("purgeIndex = {}, purged = {}", purgeIndex, purged);
Assert.assertEquals(expectedIndex, raftLog.getRaftLogCache().getStartIndex());
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestStateMachine method runTestTransactionContextIsPassedBack.
void runTestTransactionContextIsPassedBack(boolean useMemory) throws Throwable {
final RaftProperties properties = new RaftProperties();
properties.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SMTransactionContext.class, StateMachine.class);
RaftServerConfigKeys.Log.setUseMemory(properties, useMemory);
try (MiniRaftClusterWithSimulatedRpc cluster = getFactory().newCluster(NUM_SERVERS, properties)) {
cluster.start();
runTestTransactionContextIsPassedBack(cluster);
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class Client method run.
@Override
public void run() throws Exception {
RaftProperties raftProperties = new RaftProperties();
final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers());
RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties);
builder.setRaftGroup(raftGroup);
builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
RaftClient client = builder.build();
operation(client);
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class CounterClient method buildClient.
/**
* build the RaftClient instance which is used to communicate to
* Counter cluster
*
* @return the created client of Counter cluster
*/
private static RaftClient buildClient() {
RaftProperties raftProperties = new RaftProperties();
RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties).setRaftGroup(Constants.RAFT_GROUP).setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
return builder.build();
}
Aggregations