Search in sources :

Example 16 with RaftProperties

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());
}
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 17 with RaftProperties

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());
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) RaftProperties(org.apache.ratis.conf.RaftProperties)

Example 18 with RaftProperties

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

Example 19 with RaftProperties

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);
}
Also used : Parameters(org.apache.ratis.conf.Parameters) GrpcFactory(org.apache.ratis.grpc.GrpcFactory) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftGroup(org.apache.ratis.protocol.RaftGroup) RaftClient(org.apache.ratis.client.RaftClient)

Example 20 with RaftProperties

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();
}
Also used : Parameters(org.apache.ratis.conf.Parameters) GrpcFactory(org.apache.ratis.grpc.GrpcFactory) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftClient(org.apache.ratis.client.RaftClient)

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