use of org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory 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));
}
use of org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory in project ignite-3 by apache.
the class ClusterServiceTestUtils method clusterService.
/**
* Creates a cluster service and required node configuration manager beneath it. Populates node configuration with specified port.
* Manages configuration manager lifecycle: on cluster service start starts node configuration manager, on cluster service stop - stops
* node configuration manager.
*
* @param testInfo Test info.
* @param port Local port.
* @param nodeFinder Node finder.
* @param clusterSvcFactory Cluster service factory.
*/
public static ClusterService clusterService(TestInfo testInfo, int port, NodeFinder nodeFinder, TestScaleCubeClusterServiceFactory clusterSvcFactory) {
var registry = new MessageSerializationRegistryImpl();
REGISTRY_INITIALIZERS.forEach(c -> {
try {
c.invoke(c.getDeclaringClass(), registry);
} catch (Throwable e) {
throw new RuntimeException("Failed to invoke registry initializer", e);
}
});
var ctx = new ClusterLocalConfiguration(testNodeName(testInfo, port), registry);
ConfigurationManager nodeConfigurationMgr = new ConfigurationManager(Collections.singleton(NetworkConfiguration.KEY), Map.of(), new TestConfigurationStorage(ConfigurationType.LOCAL), List.of(), List.of());
NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
var bootstrapFactory = new NettyBootstrapFactory(configuration, ctx.getName());
var clusterSvc = clusterSvcFactory.createClusterService(ctx, configuration, bootstrapFactory);
assert nodeFinder instanceof StaticNodeFinder : "Only StaticNodeFinder is supported at the moment";
return new ClusterService() {
@Override
public TopologyService topologyService() {
return clusterSvc.topologyService();
}
@Override
public MessagingService messagingService() {
return clusterSvc.messagingService();
}
@Override
public ClusterLocalConfiguration localConfiguration() {
return clusterSvc.localConfiguration();
}
@Override
public boolean isStopped() {
return clusterSvc.isStopped();
}
@Override
public void start() {
nodeConfigurationMgr.start();
NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
configuration.change(netCfg -> netCfg.changePort(port).changeNodeFinder(c -> c.changeType(NodeFinderType.STATIC.toString()).changeNetClusterNodes(nodeFinder.findNodes().stream().map(NetworkAddress::toString).toArray(String[]::new)))).join();
bootstrapFactory.start();
clusterSvc.start();
}
@Override
public void stop() {
try {
clusterSvc.stop();
bootstrapFactory.stop();
nodeConfigurationMgr.stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
use of org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory in project ignite-3 by apache.
the class ItNodeTest method createService.
/**
* @param groupId Group id.
* @param peerId Peer id.
* @param nodeOptions Node options.
* @return Raft group service.
*/
private RaftGroupService createService(String groupId, PeerId peerId, NodeOptions nodeOptions) {
Configuration initialConf = nodeOptions.getInitialConf();
nodeOptions.setStripes(1);
Stream<PeerId> peers = initialConf == null ? Stream.empty() : Stream.concat(initialConf.getPeers().stream(), initialConf.getLearners().stream());
List<NetworkAddress> addressList = peers.map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
var nodeManager = new NodeManager();
ClusterService clusterService = ClusterServiceTestUtils.clusterService(testInfo, peerId.getEndpoint().getPort(), new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
ExecutorService requestExecutor = JRaftUtils.createRequestExecutor(nodeOptions);
executors.add(requestExecutor);
IgniteRpcServer rpcServer = new TestIgniteRpcServer(clusterService, nodeManager, nodeOptions, requestExecutor);
nodeOptions.setRpcClient(new IgniteRpcClient(clusterService));
clusterService.start();
var service = new RaftGroupService(groupId, peerId, nodeOptions, rpcServer, nodeManager) {
@Override
public synchronized void shutdown() {
rpcServer.shutdown();
super.shutdown();
clusterService.stop();
}
};
services.add(service);
return service;
}
use of org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory in project ignite-3 by apache.
the class TestCluster method start.
public boolean start(Endpoint listenAddr, boolean emptyPeers, int snapshotIntervalSecs, boolean enableMetrics, SnapshotThrottle snapshotThrottle, RaftOptions raftOptions, int priority) throws IOException {
this.lock.lock();
try {
if (this.serverMap.get(listenAddr) != null) {
return true;
}
// Start node in non shared pools mode. Pools will be managed by node itself.
NodeOptions nodeOptions = new NodeOptions();
nodeOptions.setServerName(listenAddr.toString());
nodeOptions.setElectionTimeoutMs(this.electionTimeoutMs);
nodeOptions.setEnableMetrics(enableMetrics);
nodeOptions.setSnapshotThrottle(snapshotThrottle);
nodeOptions.setSnapshotIntervalSecs(snapshotIntervalSecs);
nodeOptions.setServiceFactory(this.raftServiceFactory);
if (raftOptions != null) {
nodeOptions.setRaftOptions(raftOptions);
}
String serverDataPath = this.dataPath + File.separator + listenAddr.toString().replace(':', '_');
new File(serverDataPath).mkdirs();
nodeOptions.setLogUri(serverDataPath + File.separator + "logs");
nodeOptions.setRaftMetaUri(serverDataPath + File.separator + "meta");
nodeOptions.setSnapshotUri(serverDataPath + File.separator + "snapshot");
nodeOptions.setElectionPriority(priority);
// Align rpc options with election timeout.
nodeOptions.setRpcConnectTimeoutMs(this.electionTimeoutMs / 3);
nodeOptions.setRpcDefaultTimeout(this.electionTimeoutMs / 2);
// Reduce default threads count per test node.
nodeOptions.setRaftRpcThreadPoolSize(Utils.cpus());
nodeOptions.setTimerPoolSize(Utils.cpus() * 2);
nodeOptions.setRpcProcessorThreadPoolSize(Utils.cpus() * 3);
nodeOptions.setElectionTimeoutStrategy(new ExponentialBackoffTimeoutStrategy());
MockStateMachine fsm = new MockStateMachine(listenAddr);
nodeOptions.setFsm(fsm);
if (!emptyPeers)
nodeOptions.setInitialConf(new Configuration(this.peers, this.learners));
List<NetworkAddress> addressList = (emptyPeers ? Stream.<PeerId>empty() : peers.stream()).map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
NodeManager nodeManager = new NodeManager();
ClusterService clusterService = ClusterServiceTestUtils.clusterService(testInfo, listenAddr.getPort(), new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
var rpcClient = new IgniteRpcClient(clusterService);
nodeOptions.setRpcClient(rpcClient);
ExecutorService requestExecutor = JRaftUtils.createRequestExecutor(nodeOptions);
var rpcServer = new TestIgniteRpcServer(clusterService, nodeManager, nodeOptions, requestExecutor);
clusterService.start();
if (optsClo != null)
optsClo.accept(nodeOptions);
RaftGroupService server = new RaftGroupService(this.name, new PeerId(listenAddr, 0, priority), nodeOptions, rpcServer, nodeManager) {
@Override
public synchronized void shutdown() {
// This stop order is consistent with JRaftServerImpl
rpcServer.shutdown();
ExecutorServiceHelper.shutdownAndAwaitTermination(requestExecutor);
super.shutdown();
// Network service must be stopped after a node because raft initiates timeoutnowrequest on stop for faster
// leader election.
clusterService.stop();
}
};
this.serverMap.put(listenAddr, server);
Node node = server.start();
this.fsms.put(new PeerId(listenAddr, 0), fsm);
this.nodes.add((NodeImpl) node);
return true;
} finally {
this.lock.unlock();
}
}
use of org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory in project ignite-3 by apache.
the class IgniteRpcTest method createServer.
/**
* {@inheritDoc}
*/
@Override
public RpcServer<?> createServer(Endpoint endpoint) {
ClusterService service = ClusterServiceTestUtils.clusterService(testInfo, endpoint.getPort(), new StaticNodeFinder(Collections.emptyList()), new TestScaleCubeClusterServiceFactory());
NodeOptions nodeOptions = new NodeOptions();
requestExecutor = JRaftUtils.createRequestExecutor(nodeOptions);
var server = new TestIgniteRpcServer(service, new NodeManager(), nodeOptions, requestExecutor) {
@Override
public void shutdown() {
super.shutdown();
service.stop();
}
};
service.start();
return server;
}
Aggregations