use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.
the class CopySessionTest method setup.
@Before
public void setup() {
this.timerManager = new TimerManager(5);
this.copyOpts = new CopyOptions();
this.rb = RpcRequests.GetFileRequest.newBuilder();
this.rb.setReaderId(99);
this.rb.setFilename("data");
this.raftOpts = new RaftOptions();
this.session = new CopySession(rpcService, timerManager, null, raftOpts, rb, address);
this.session.setCopyOptions(copyOpts);
}
use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.
the class RemoteFileCopierTest method testInit.
@Test
public void testInit() {
Mockito.when(rpcService.connect(new Endpoint("localhost", 8081))).thenReturn(true);
assertTrue(copier.init("remote://localhost:8081/999", null, new SnapshotCopierOptions(rpcService, timerManager, new RaftOptions(), new NodeOptions())));
assertEquals(999, copier.getReaderId());
Assert.assertEquals("localhost", copier.getEndpoint().getIp());
Assert.assertEquals(8081, copier.getEndpoint().getPort());
}
use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.
the class NodeTest method testNodeTaskOverload.
@Test
public void testNodeTaskOverload() throws Exception {
final Endpoint addr = new Endpoint(TestUtils.getMyIp(), TestUtils.INIT_PORT);
final PeerId peer = new PeerId(addr, 0);
NodeManager.getInstance().addAddress(addr);
final NodeOptions nodeOptions = createNodeOptionsWithSharedTimer();
final RaftOptions raftOptions = new RaftOptions();
raftOptions.setDisruptorBufferSize(2);
nodeOptions.setRaftOptions(raftOptions);
final MockStateMachine fsm = new MockStateMachine(addr);
nodeOptions.setFsm(fsm);
nodeOptions.setLogUri(this.dataPath + File.separator + "log");
nodeOptions.setRaftMetaUri(this.dataPath + File.separator + "meta");
nodeOptions.setSnapshotUri(this.dataPath + File.separator + "snapshot");
nodeOptions.setInitialConf(new Configuration(Collections.singletonList(peer)));
final Node node = new NodeImpl("unittest", peer);
assertTrue(node.init(nodeOptions));
assertEquals(1, node.listPeers().size());
assertTrue(node.listPeers().contains(peer));
while (!node.isLeader()) {
;
}
final List<Task> tasks = new ArrayList<>();
final AtomicInteger c = new AtomicInteger(0);
for (int i = 0; i < 10; i++) {
final ByteBuffer data = ByteBuffer.wrap(("hello" + i).getBytes());
final Task task = new Task(data, new JoinableClosure(status -> {
System.out.println(status);
if (!status.isOk()) {
assertTrue(status.getRaftError() == RaftError.EBUSY || status.getRaftError() == RaftError.EPERM);
}
c.incrementAndGet();
}));
node.apply(task);
tasks.add(task);
}
try {
Task.joinAll(tasks, TimeUnit.SECONDS.toMillis(30));
assertEquals(10, c.get());
} finally {
node.shutdown();
node.join();
}
}
use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.
the class ReadOnlyServiceTest method setup.
@Before
public void setup() {
this.readOnlyServiceImpl = new ReadOnlyServiceImpl();
final ReadOnlyServiceOptions opts = new ReadOnlyServiceOptions();
opts.setFsmCaller(this.fsmCaller);
opts.setNode(this.node);
opts.setRaftOptions(new RaftOptions());
Mockito.when(this.node.getNodeMetrics()).thenReturn(new NodeMetrics(false));
Mockito.when(this.node.getOptions()).thenReturn(new NodeOptions());
Mockito.when(this.node.getGroupId()).thenReturn("test");
Mockito.when(this.node.getServerId()).thenReturn(new PeerId("localhost:8081", 0));
assertTrue(this.readOnlyServiceImpl.init(opts));
}
use of com.alipay.sofa.jraft.option.RaftOptions in project incubator-hugegraph by apache.
the class RaftSharedContext method nodeOptions.
public NodeOptions nodeOptions() throws IOException {
HugeConfig config = this.config();
PeerId selfId = new PeerId();
selfId.parse(config.get(CoreOptions.RAFT_ENDPOINT));
NodeOptions nodeOptions = new NodeOptions();
nodeOptions.setEnableMetrics(false);
nodeOptions.setRpcProcessorThreadPoolSize(config.get(CoreOptions.RAFT_RPC_THREADS));
nodeOptions.setRpcConnectTimeoutMs(config.get(CoreOptions.RAFT_RPC_CONNECT_TIMEOUT));
nodeOptions.setRpcDefaultTimeout(config.get(CoreOptions.RAFT_RPC_TIMEOUT));
int electionTimeout = config.get(CoreOptions.RAFT_ELECTION_TIMEOUT);
nodeOptions.setElectionTimeoutMs(electionTimeout);
nodeOptions.setDisableCli(false);
int snapshotInterval = config.get(CoreOptions.RAFT_SNAPSHOT_INTERVAL);
nodeOptions.setSnapshotIntervalSecs(snapshotInterval);
Configuration groupPeers = new Configuration();
String groupPeersStr = config.get(CoreOptions.RAFT_GROUP_PEERS);
if (!groupPeers.parse(groupPeersStr)) {
throw new HugeException("Failed to parse group peers %s", groupPeersStr);
}
nodeOptions.setInitialConf(groupPeers);
String raftPath = config.get(CoreOptions.RAFT_PATH);
String logUri = Paths.get(raftPath, "log").toString();
FileUtils.forceMkdir(new File(logUri));
nodeOptions.setLogUri(logUri);
String metaUri = Paths.get(raftPath, "meta").toString();
FileUtils.forceMkdir(new File(metaUri));
nodeOptions.setRaftMetaUri(metaUri);
if (config.get(CoreOptions.RAFT_USE_SNAPSHOT)) {
String snapshotUri = Paths.get(raftPath, "snapshot").toString();
FileUtils.forceMkdir(new File(snapshotUri));
nodeOptions.setSnapshotUri(snapshotUri);
}
RaftOptions raftOptions = nodeOptions.getRaftOptions();
/*
* NOTE: if buffer size is too small(<=1024), will throw exception
* "LogManager is busy, disk queue overload"
*/
raftOptions.setApplyBatch(config.get(CoreOptions.RAFT_APPLY_BATCH));
raftOptions.setDisruptorBufferSize(config.get(CoreOptions.RAFT_QUEUE_SIZE));
raftOptions.setDisruptorPublishEventWaitTimeoutSecs(config.get(CoreOptions.RAFT_QUEUE_PUBLISH_TIMEOUT));
raftOptions.setReplicatorPipeline(config.get(CoreOptions.RAFT_REPLICATOR_PIPELINE));
raftOptions.setOpenStatistics(false);
raftOptions.setReadOnlyOptions(ReadOnlyOption.valueOf(config.get(CoreOptions.RAFT_READ_STRATEGY)));
return nodeOptions;
}
Aggregations