Search in sources :

Example 1 with CliOptions

use of org.apache.ignite.raft.jraft.option.CliOptions in project ignite-3 by apache.

the class ItCliServiceTest method setup.

/**
 * Executes before each test.
 */
@BeforeEach
public void setup(TestInfo testInfo, @WorkDirectory Path dataPath) throws Exception {
    LOG.info(">>>>>>>>>>>>>>> Start test method: " + testInfo.getDisplayName());
    List<PeerId> peers = TestUtils.generatePeers(3);
    LinkedHashSet<PeerId> learners = new LinkedHashSet<>();
    // 2 learners
    for (int i = 0; i < 2; i++) {
        learners.add(new PeerId(TestUtils.getLocalAddress(), TestUtils.INIT_PORT + LEARNER_PORT_STEP + i));
    }
    cluster = new TestCluster(groupId, dataPath.toString(), peers, learners, ELECTION_TIMEOUT_MILLIS, testInfo);
    for (PeerId peer : peers) {
        cluster.start(peer.getEndpoint());
    }
    for (PeerId peer : learners) {
        cluster.startLearner(peer);
    }
    cluster.waitLeader();
    cluster.ensureLeader(cluster.getLeader());
    cliService = new CliServiceImpl();
    conf = new Configuration(peers, learners);
    CliOptions opts = new CliOptions();
    clientExecutor = JRaftUtils.createClientExecutor(opts, "client");
    opts.setClientExecutor(clientExecutor);
    List<NetworkAddress> addressList = peers.stream().map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
    ClusterService clientSvc = ClusterServiceTestUtils.clusterService(testInfo, TestUtils.INIT_PORT - 1, new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
    clientSvc.start();
    IgniteRpcClient rpcClient = new IgniteRpcClient(clientSvc) {

        @Override
        public void shutdown() {
            super.shutdown();
            clientSvc.stop();
        }
    };
    opts.setRpcClient(rpcClient);
    assertTrue(cliService.init(opts));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) IgniteRpcClient(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient) CliOptions(org.apache.ignite.raft.jraft.option.CliOptions) ClusterService(org.apache.ignite.network.ClusterService) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) NetworkAddress(org.apache.ignite.network.NetworkAddress) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 ClusterService (org.apache.ignite.network.ClusterService)1 NetworkAddress (org.apache.ignite.network.NetworkAddress)1 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)1 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)1 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)1 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)1 CliOptions (org.apache.ignite.raft.jraft.option.CliOptions)1 IgniteRpcClient (org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1