Search in sources :

Example 1 with ClusterService

use of org.apache.ignite.network.ClusterService 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)

Example 2 with ClusterService

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

the class ItMetaStorageRaftGroupTest method afterTest.

/**
 * Shutdown raft server and stop all cluster nodes.
 *
 * @throws Exception If failed to shutdown raft server,
 */
@AfterEach
public void afterTest() throws Exception {
    if (metaStorageRaftSrv3 != null) {
        metaStorageRaftSrv3.stopRaftGroup(METASTORAGE_RAFT_GROUP_NAME);
        metaStorageRaftSrv3.stop();
        metaStorageRaftGrpSvc3.shutdown();
    }
    if (metaStorageRaftSrv2 != null) {
        metaStorageRaftSrv2.stopRaftGroup(METASTORAGE_RAFT_GROUP_NAME);
        metaStorageRaftSrv2.stop();
        metaStorageRaftGrpSvc2.shutdown();
    }
    if (metaStorageRaftSrv1 != null) {
        metaStorageRaftSrv1.stopRaftGroup(METASTORAGE_RAFT_GROUP_NAME);
        metaStorageRaftSrv1.stop();
        metaStorageRaftGrpSvc1.shutdown();
    }
    IgniteUtils.shutdownAndAwaitTermination(executor, 10, TimeUnit.SECONDS);
    for (ClusterService node : cluster) {
        node.stop();
    }
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) AfterEach(org.junit.jupiter.api.AfterEach)

Example 3 with ClusterService

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

the class ItTablePersistenceTest method createListener.

/**
 * {@inheritDoc}
 */
@Override
public RaftGroupListener createListener(ClusterService service, Path workDir) {
    return paths.entrySet().stream().filter(entry -> entry.getValue().equals(workDir)).map(Map.Entry::getKey).findAny().orElseGet(() -> {
        TableTxManagerImpl txManager = new TableTxManagerImpl(service, new HeapLockManager());
        // Init listener.
        txManager.start();
        PartitionListener listener = new PartitionListener(UUID.randomUUID(), new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager));
        paths.put(listener, workDir);
        return listener;
    });
}
Also used : ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ItAbstractListenerSnapshotTest(org.apache.ignite.raft.client.service.ItAbstractListenerSnapshotTest) RaftGroupListener(org.apache.ignite.raft.client.service.RaftGroupListener) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) Row(org.apache.ignite.internal.schema.row.Row) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) Path(java.nio.file.Path) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Int2ObjectMaps(it.unimi.dsi.fastutil.ints.Int2ObjectMaps) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) TxManager(org.apache.ignite.internal.tx.TxManager) NetworkAddress(org.apache.ignite.network.NetworkAddress) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) AfterEach(org.junit.jupiter.api.AfterEach) Column(org.apache.ignite.internal.schema.Column) ClusterService(org.apache.ignite.network.ClusterService) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) Mockito.mock(org.mockito.Mockito.mock) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl)

Example 4 with ClusterService

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

the class ItNodeRestartsTest method testRestarts.

/**
 * Tests that restarting nodes get discovered in an established topology.
 */
@Test
public void testRestarts(TestInfo testInfo) {
    final int initPort = 3344;
    List<NetworkAddress> addresses = findLocalAddresses(initPort, initPort + 5);
    var nodeFinder = new StaticNodeFinder(addresses);
    services = addresses.stream().map(addr -> startNetwork(testInfo, addr, nodeFinder)).collect(// ensure mutability
    Collectors.toCollection(ArrayList::new));
    for (ClusterService service : services) {
        assertTrue(waitForTopology(service, 5, 5_000), service.topologyService().localMember().toString() + ", topSize=" + service.topologyService().allMembers().size());
    }
    int idx0 = 0;
    int idx1 = 2;
    LOG.info("Shutdown {}", addresses.get(idx0));
    services.get(idx0).stop();
    LOG.info("Shutdown {}", addresses.get(idx1));
    services.get(idx1).stop();
    LOG.info("Starting {}", addresses.get(idx0));
    ClusterService svc0 = startNetwork(testInfo, addresses.get(idx0), nodeFinder);
    services.set(idx0, svc0);
    LOG.info("Starting {}", addresses.get(idx1));
    ClusterService svc2 = startNetwork(testInfo, addresses.get(idx1), nodeFinder);
    services.set(idx1, svc2);
    for (ClusterService service : services) {
        assertTrue(waitForTopology(service, 5, 10_000), service.topologyService().localMember().toString() + ", topSize=" + service.topologyService().allMembers().size());
    }
    LOG.info("Reached stable state");
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 5 with ClusterService

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

the class ItNodeRestartsTest method startNetwork.

/**
 * Creates a {@link ClusterService} using the given local address and the node finder.
 *
 * @param testInfo   Test info.
 * @param addr       Node address.
 * @param nodeFinder Node finder.
 * @return Created Cluster Service.
 */
private ClusterService startNetwork(TestInfo testInfo, NetworkAddress addr, NodeFinder nodeFinder) {
    ClusterService clusterService = ClusterServiceTestUtils.clusterService(testInfo, addr.port(), nodeFinder, networkFactory);
    clusterService.start();
    return clusterService;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService)

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