use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItMetaStorageRaftGroupTest method beforeTest.
/**
* Run {@code NODES} cluster nodes.
*/
@BeforeEach
public void beforeTest(TestInfo testInfo) {
List<NetworkAddress> localAddresses = findLocalAddresses(NODE_PORT_BASE, NODE_PORT_BASE + NODES);
var nodeFinder = new StaticNodeFinder(localAddresses);
localAddresses.stream().map(addr -> ClusterServiceTestUtils.clusterService(testInfo, addr.port(), nodeFinder, NETWORK_FACTORY)).forEach(clusterService -> {
clusterService.start();
cluster.add(clusterService);
});
for (ClusterService node : cluster) {
assertTrue(waitForTopology(node, NODES, 1000));
}
LOG.info("Cluster started.");
executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItNodeTest method waitForTopology.
/**
* TODO asch get rid of waiting for topology IGNITE-14832
*
* @param cluster
* @param addr
* @param expected
* @param timeout
* @return
*/
private boolean waitForTopology(TestCluster cluster, Endpoint addr, int expected, long timeout) {
RaftGroupService grp = cluster.getServer(addr);
if (grp == null) {
LOG.warn("Node has not been found {}", addr);
return false;
}
RpcServer rpcServer = grp.getRpcServer();
if (!(rpcServer instanceof IgniteRpcServer))
return true;
ClusterService service = ((IgniteRpcServer) grp.getRpcServer()).clusterService();
long stop = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < stop) {
if (service.topologyService().allMembers().size() >= expected)
return true;
try {
Thread.sleep(50);
} catch (InterruptedException e) {
return false;
}
}
return false;
}
use of org.apache.ignite.network.ClusterService 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.ClusterService in project ignite-3 by apache.
the class ItJraftCounterServerTest method startClient.
/**
* Starts client.
*
* @param groupId Group id.
* @return The client.
* @throws Exception If failed.
*/
private RaftGroupService startClient(String groupId) throws Exception {
var addr = new NetworkAddress(getLocalAddress(), PORT);
ClusterService clientNode = clusterService(CLIENT_PORT + clients.size(), List.of(addr), true);
RaftGroupService client = RaftGroupServiceImpl.start(groupId, clientNode, FACTORY, 10_000, List.of(new Peer(addr)), false, 200, executor).get(3, TimeUnit.SECONDS);
clients.add(client);
return client;
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItJraftCounterServerTest method startServer.
/**
* Starts server.
*
* @param idx The index.
* @param clo Init closure.
* @param cons Node options updater.
*
* @return Raft server instance.
*/
private JraftServerImpl startServer(int idx, Consumer<RaftServer> clo, Consumer<NodeOptions> cons) {
var addr = new NetworkAddress(getLocalAddress(), PORT);
ClusterService service = clusterService(PORT + idx, List.of(addr), true);
NodeOptions opts = new NodeOptions();
cons.accept(opts);
JraftServerImpl server = new JraftServerImpl(service, dataPath, opts) {
@Override
public void stop() {
servers.remove(this);
super.stop();
service.stop();
}
};
server.start();
clo.accept(server);
servers.add(server);
assertTrue(waitForTopology(service, servers.size(), 15_000));
return server;
}
Aggregations