use of com.alipay.sofa.jraft.option.CliOptions in project sofa-jraft by sofastack.
the class AbstractRheaKVStoreTest method rangeSplitTest.
@Test
public void rangeSplitTest() {
final RheaKVStore store = getRandomLeaderStore();
final long regionId = 1;
for (int i = 0; i < 20; i++) {
store.bPut("a" + i, BytesUtil.writeUtf8("split"));
}
final CliOptions opts = new CliOptions();
opts.setTimeoutMs(30000);
final RheaKVCliService cliService = RheaKVServiceFactory.createAndInitRheaKVCliService(opts);
final long newRegionId = 101;
final String groupId = JRaftHelper.getJRaftGroupId("rhea_test", regionId);
final Configuration conf = JRaftUtils.getConfiguration("127.0.0.1:18181,127.0.0.1:18182,127.0.0.1:18183");
final Status st = cliService.rangeSplit(regionId, newRegionId, groupId, conf);
System.err.println("Status:" + st);
assertTrue(st.isOk());
final RheaKVStore newStore = getLeaderStore(101);
newStore.bPut("f_first_key", BytesUtil.writeUtf8("split_ok"));
assertArrayEquals(BytesUtil.writeUtf8("split_ok"), newStore.bGet("f_first_key"));
}
use of com.alipay.sofa.jraft.option.CliOptions in project sofa-jraft by sofastack.
the class AtomicClientTest method main.
public static void main(String[] args) throws Exception {
final RouteTable table = RouteTable.getInstance();
table.updateConfiguration("atomic_0", JRaftUtils.getConfiguration("127.0.0.1:8609,127.0.0.1:8610,127.0.0.1:8611"));
final CliClientServiceImpl cliClientService = new CliClientServiceImpl();
cliClientService.init(new CliOptions());
final Status st = table.refreshLeader(cliClientService, "atomic_0", 10000);
System.out.println(st);
final AtomicClient cli = new AtomicClient("atomic", JRaftUtils.getConfiguration("localhost:8610"));
final PeerId leader = table.selectLeader("atomic_0");
cli.start();
final int threads = 30;
final int count = 10000;
final CyclicBarrier barrier = new CyclicBarrier(threads + 1);
for (int t = 0; t < threads; t++) {
new Thread() {
@Override
public void run() {
long sum = 0;
try {
barrier.await();
final PeerId peer = new PeerId("localhost", 8611);
for (int i = 0; i < count; i++) {
sum += cli.get(leader, "a", true, false);
// sum += cli.addAndGet(leader, "a", i);
}
barrier.await();
} catch (final Exception e) {
e.printStackTrace();
} finally {
System.out.println("sum=" + sum);
}
}
}.start();
}
final long start = System.currentTimeMillis();
barrier.await();
barrier.await();
final long cost = System.currentTimeMillis() - start;
final long tps = Math.round(threads * count * 1000.0 / cost);
System.out.println("tps=" + tps + ",cost=" + cost + " ms.");
cli.shutdown();
}
use of com.alipay.sofa.jraft.option.CliOptions in project sofa-jraft by sofastack.
the class DefaultRheaKVCliService method initCli.
private void initCli(CliOptions cliOpts) {
if (cliOpts == null) {
cliOpts = new CliOptions();
cliOpts.setTimeoutMs(5000);
cliOpts.setMaxRetry(3);
}
this.opts = cliOpts;
this.cliService = RaftServiceFactory.createAndInitCliService(cliOpts);
final CliClientService cliClientService = ((CliServiceImpl) this.cliService).getCliClientService();
Requires.requireNonNull(cliClientService, "cliClientService");
this.rpcClient = ((AbstractClientService) cliClientService).getRpcClient();
}
use of com.alipay.sofa.jraft.option.CliOptions in project sofa-jraft by sofastack.
the class RouteTableTest method setup.
@Before
public void setup() throws Exception {
cliClientService = new CliClientServiceImpl();
cliClientService.init(new CliOptions());
this.dataPath = TestUtils.mkTempDir();
FileUtils.forceMkdir(new File(this.dataPath));
assertEquals(NodeImpl.GLOBAL_NUM_NODES.get(), 0);
final List<PeerId> peers = TestUtils.generatePeers(3);
cluster = new TestCluster(groupId, dataPath, peers);
for (final PeerId peer : peers) {
cluster.start(peer.getEndpoint());
}
cluster.waitLeader();
}
use of com.alipay.sofa.jraft.option.CliOptions in project sofa-jraft by sofastack.
the class CliServiceTest method setup.
@Before
public void setup() throws Exception {
System.out.println(">>>>>>>>>>>>>>> Start test method: " + this.testName.getMethodName());
this.dataPath = TestUtils.mkTempDir();
FileUtils.forceMkdir(new File(this.dataPath));
assertEquals(NodeImpl.GLOBAL_NUM_NODES.get(), 0);
final List<PeerId> peers = TestUtils.generatePeers(3);
final LinkedHashSet<PeerId> learners = new LinkedHashSet<>();
// 2 learners
for (int i = 0; i < 2; i++) {
learners.add(new PeerId(TestUtils.getMyIp(), TestUtils.INIT_PORT + LEARNER_PORT_STEP + i));
}
this.cluster = new TestCluster(this.groupId, this.dataPath, peers, learners, 300);
for (final PeerId peer : peers) {
this.cluster.start(peer.getEndpoint());
}
for (final PeerId peer : learners) {
this.cluster.startLearner(peer);
}
this.cluster.waitLeader();
this.cliService = new CliServiceImpl();
this.conf = new Configuration(peers, learners);
assertTrue(this.cliService.init(new CliOptions()));
}
Aggregations