Search in sources :

Example 6 with StaticNodeFinder

use of org.apache.ignite.network.StaticNodeFinder 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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) Path(java.nio.file.Path) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) KeyValueStorage(org.apache.ignite.internal.metastorage.server.KeyValueStorage) Cursor(org.apache.ignite.internal.util.Cursor) Status(org.apache.ignite.raft.jraft.Status) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) Collectors(java.util.stream.Collectors) TestUtils(org.apache.ignite.raft.jraft.test.TestUtils) TestInfo(org.junit.jupiter.api.TestInfo) RaftServer(org.apache.ignite.internal.raft.server.RaftServer) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Replicator(org.apache.ignite.raft.jraft.core.Replicator) NotNull(org.jetbrains.annotations.NotNull) RaftGroupServiceImpl(org.apache.ignite.raft.jraft.rpc.impl.RaftGroupServiceImpl) ClusterServiceTestUtils.findLocalAddresses(org.apache.ignite.utils.ClusterServiceTestUtils.findLocalAddresses) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ClusterServiceTestUtils(org.apache.ignite.utils.ClusterServiceTestUtils) Mock(org.mockito.Mock) Loza(org.apache.ignite.internal.raft.Loza) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) ArrayList(java.util.ArrayList) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) TestUtils.waitForTopology(org.apache.ignite.raft.jraft.test.TestUtils.waitForTopology) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Iterator(java.util.Iterator) ByteArray(org.apache.ignite.lang.ByteArray) Mockito.when(org.mockito.Mockito.when) WorkDirectory(org.apache.ignite.internal.testframework.WorkDirectory) NetworkAddress(org.apache.ignite.network.NetworkAddress) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Peer(org.apache.ignite.raft.client.Peer) AfterEach(org.junit.jupiter.api.AfterEach) ClusterService(org.apache.ignite.network.ClusterService) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) WorkDirectoryExtension(org.apache.ignite.internal.testframework.WorkDirectoryExtension) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with StaticNodeFinder

use of org.apache.ignite.network.StaticNodeFinder 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;
}
Also used : TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) IgniteRpcClient(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) IgniteRpcServer(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer) TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer) NodeManager(org.apache.ignite.raft.jraft.NodeManager) ClusterService(org.apache.ignite.network.ClusterService) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) NetworkAddress(org.apache.ignite.network.NetworkAddress) ExecutorService(java.util.concurrent.ExecutorService) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 8 with StaticNodeFinder

use of org.apache.ignite.network.StaticNodeFinder in project ignite-3 by apache.

the class RaftServerAbstractTest method clusterService.

/**
 * Creates a client cluster view.
 *
 * @param port    Local port.
 * @param servers Server nodes of the cluster.
 * @return The client cluster view.
 */
protected ClusterService clusterService(int port, List<NetworkAddress> servers, boolean start) {
    var network = ClusterServiceTestUtils.clusterService(testInfo, port, new StaticNodeFinder(servers), NETWORK_FACTORY);
    if (start) {
        network.start();
    }
    clusterServices.add(network);
    return network;
}
Also used : StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder)

Example 9 with StaticNodeFinder

use of org.apache.ignite.network.StaticNodeFinder in project ignite-3 by apache.

the class ItLozaTest method clusterService.

/**
 * Returns the client cluster view.
 *
 * @param testInfo Test info.
 * @param port     Local port.
 * @param srvs     Server nodes of the cluster.
 * @return The client cluster view.
 */
private static ClusterService clusterService(TestInfo testInfo, int port, List<NetworkAddress> srvs) {
    var network = ClusterServiceTestUtils.clusterService(testInfo, port, new StaticNodeFinder(srvs), NETWORK_FACTORY);
    network.start();
    return network;
}
Also used : StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder)

Example 10 with StaticNodeFinder

use of org.apache.ignite.network.StaticNodeFinder in project ignite-3 by apache.

the class ItAbstractListenerSnapshotTest method clusterService.

/**
 * Creates a cluster service.
 */
private ClusterService clusterService(TestInfo testInfo, int port, NetworkAddress otherPeer) {
    var network = ClusterServiceTestUtils.clusterService(testInfo, port, new StaticNodeFinder(List.of(otherPeer)), NETWORK_FACTORY);
    network.start();
    cluster.add(network);
    return network;
}
Also used : StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder)

Aggregations

StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)15 ClusterService (org.apache.ignite.network.ClusterService)11 NetworkAddress (org.apache.ignite.network.NetworkAddress)10 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)9 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4 NamedThreadFactory (org.apache.ignite.internal.thread.NamedThreadFactory)4 Map (java.util.Map)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Loza (org.apache.ignite.internal.raft.Loza)3 IgniteUtils (org.apache.ignite.internal.util.IgniteUtils)3 Peer (org.apache.ignite.raft.client.Peer)3 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)3 NodeManager (org.apache.ignite.raft.jraft.NodeManager)3 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)3 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)3 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)3