Search in sources :

Example 21 with ClusterService

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));
}
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 22 with ClusterService

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;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) RpcServer(org.apache.ignite.raft.jraft.rpc.RpcServer) IgniteRpcServer(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer) TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer) IgniteRpcServer(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer) TestIgniteRpcServer(org.apache.ignite.raft.jraft.rpc.TestIgniteRpcServer)

Example 23 with ClusterService

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;
}
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 24 with ClusterService

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;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer)

Example 25 with ClusterService

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;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl)

Aggregations

ClusterService (org.apache.ignite.network.ClusterService)42 NetworkAddress (org.apache.ignite.network.NetworkAddress)18 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)12 Test (org.junit.jupiter.api.Test)12 ConcurrentHashMapPartitionStorage (org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage)11 VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)11 HeapLockManager (org.apache.ignite.internal.tx.impl.HeapLockManager)11 TxManagerImpl (org.apache.ignite.internal.tx.impl.TxManagerImpl)11 List (java.util.List)10 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)10 ClusterNode (org.apache.ignite.network.ClusterNode)9 MessagingService (org.apache.ignite.network.MessagingService)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 DummyInternalTableImpl (org.apache.ignite.internal.table.impl.DummyInternalTableImpl)7 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)7 TxManager (org.apache.ignite.internal.tx.TxManager)7 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)7 AfterEach (org.junit.jupiter.api.AfterEach)7 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)6 Peer (org.apache.ignite.raft.client.Peer)6