Search in sources :

Example 6 with CliOptions

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"));
}
Also used : Status(com.alipay.sofa.jraft.Status) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) RheaKVCliService(com.alipay.sofa.jraft.rhea.client.RheaKVCliService) Configuration(com.alipay.sofa.jraft.conf.Configuration) CliOptions(com.alipay.sofa.jraft.option.CliOptions) Test(org.junit.Test)

Example 7 with CliOptions

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();
}
Also used : RouteTable(com.alipay.sofa.jraft.RouteTable) Status(com.alipay.sofa.jraft.Status) CliClientServiceImpl(com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl) CliOptions(com.alipay.sofa.jraft.option.CliOptions) PeerId(com.alipay.sofa.jraft.entity.PeerId) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 8 with CliOptions

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();
}
Also used : CliServiceImpl(com.alipay.sofa.jraft.core.CliServiceImpl) CliOptions(com.alipay.sofa.jraft.option.CliOptions) CliClientService(com.alipay.sofa.jraft.rpc.CliClientService)

Example 9 with CliOptions

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();
}
Also used : CliClientServiceImpl(com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl) TestCluster(com.alipay.sofa.jraft.core.TestCluster) File(java.io.File) CliOptions(com.alipay.sofa.jraft.option.CliOptions) PeerId(com.alipay.sofa.jraft.entity.PeerId) Before(org.junit.Before)

Example 10 with CliOptions

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()));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Configuration(com.alipay.sofa.jraft.conf.Configuration) File(java.io.File) PeerId(com.alipay.sofa.jraft.entity.PeerId) CliOptions(com.alipay.sofa.jraft.option.CliOptions) Before(org.junit.Before)

Aggregations

CliOptions (com.alipay.sofa.jraft.option.CliOptions)13 PeerId (com.alipay.sofa.jraft.entity.PeerId)6 Configuration (com.alipay.sofa.jraft.conf.Configuration)5 CliServiceImpl (com.alipay.sofa.jraft.core.CliServiceImpl)4 CliClientServiceImpl (com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl)4 Status (com.alipay.sofa.jraft.Status)3 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)2 RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)2 RheaKVCliService (com.alipay.sofa.jraft.rhea.client.RheaKVCliService)2 RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)2 Endpoint (com.alipay.sofa.jraft.util.Endpoint)2 File (java.io.File)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RouteTable (com.alipay.sofa.jraft.RouteTable)1 TestCluster (com.alipay.sofa.jraft.core.TestCluster)1 CliClientService (com.alipay.sofa.jraft.rpc.CliClientService)1 BooleanCommand (com.alipay.sofa.jraft.test.atomic.command.BooleanCommand)1 GetSlotsCommand (com.alipay.sofa.jraft.test.atomic.command.GetSlotsCommand)1 SlotsResponseCommand (com.alipay.sofa.jraft.test.atomic.command.SlotsResponseCommand)1