Search in sources :

Example 1 with RaftGroupService

use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.

the class ItJraftCounterServerTest method after.

/**
 * After each.
 */
@AfterEach
@Override
protected void after() throws Exception {
    super.after();
    LOG.info("Start client shutdown");
    Iterator<RaftGroupService> iterClients = clients.iterator();
    while (iterClients.hasNext()) {
        RaftGroupService client = iterClients.next();
        iterClients.remove();
        client.shutdown();
    }
    LOG.info("Start server shutdown servers={}", servers.size());
    Iterator<JraftServerImpl> iterSrv = servers.iterator();
    while (iterSrv.hasNext()) {
        JraftServerImpl server = iterSrv.next();
        iterSrv.remove();
        Set<String> grps = server.startedGroups();
        for (String grp : grps) {
            server.stopRaftGroup(grp);
        }
        server.beforeNodeStop();
        server.stop();
    }
    IgniteUtils.shutdownAndAwaitTermination(executor, 10, TimeUnit.SECONDS);
    TestUtils.assertAllJraftThreadsStopped();
    LOG.info(">>>>>>>>>>>>>>> End test method: {}", testInfo.getTestMethod().orElseThrow().getName());
}
Also used : RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) AfterEach(org.junit.jupiter.api.AfterEach)

Example 2 with RaftGroupService

use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.

the class ItInternalTableScanTest method setUp.

/**
 * Prepare test environment.
 * <ol>
 * <li>Start network node.</li>
 * <li>Start raft server.</li>
 * <li>Prepare partitioned raft group.</li>
 * <li>Prepare partitioned raft group service.</li>
 * <li>Prepare internal table as a test object.</li>
 * </ol>
 *
 * @throws Exception If any.
 */
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
    NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
    network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
    network.start();
    raftSrv = new RaftServerImpl(network, FACTORY);
    raftSrv.start();
    String grpName = "test_part_grp";
    List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
    mockStorage = mock(PartitionStorage.class);
    txManager = new TxManagerImpl(network, new HeapLockManager());
    txManager.start();
    UUID tblId = UUID.randomUUID();
    raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {

        @Override
        protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
            // Return as is.
            return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
        }
    }), conf);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
    internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) Timestamp(org.apache.ignite.internal.tx.Timestamp) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable) PartitionStorage(org.apache.ignite.internal.storage.PartitionStorage) Pair(org.apache.ignite.internal.util.Pair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with RaftGroupService

use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.

the class RaftGroupServiceTest method testTransferLeadership.

/**
 * @throws Exception
 */
@Test
public void testTransferLeadership() throws Exception {
    String groupId = "test";
    when(messagingService.invoke(any(NetworkAddress.class), eq(FACTORY.transferLeaderRequest().leaderId(PeerId.fromPeer(NODES.get(1)).toString()).groupId(groupId).build()), anyLong())).then(invocation -> completedFuture(RaftRpcFactory.DEFAULT.newResponse(FACTORY, Status.OK())));
    mockLeaderRequest(false);
    RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, true, DELAY, executor).get(3, TimeUnit.SECONDS);
    assertEquals(NODES.get(0), service.leader());
    service.transferLeadership(NODES.get(1)).get();
    assertEquals(NODES.get(1), service.leader());
}
Also used : NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Test(org.junit.jupiter.api.Test)

Example 4 with RaftGroupService

use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.

the class RaftGroupServiceTest method testUserRequestLeaderElectedAfterDelay.

/**
 * @throws Exception
 */
@Test
public void testUserRequestLeaderElectedAfterDelay() throws Exception {
    String groupId = "test";
    mockLeaderRequest(false);
    mockUserInput(false, null);
    RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, true, DELAY, executor).get(3, TimeUnit.SECONDS);
    Peer leader = this.leader;
    assertEquals(leader, service.leader());
    this.leader = null;
    assertEquals(leader, service.leader());
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            RaftGroupServiceTest.this.leader = NODES.get(0);
        }
    }, 500);
    TestResponse resp = service.<TestResponse>run(new TestCommand()).get();
    assertNotNull(resp);
    assertEquals(NODES.get(0), service.leader());
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) Test(org.junit.jupiter.api.Test)

Example 5 with RaftGroupService

use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.

the class RaftGroupServiceTest method testChangePeers.

/**
 * @throws Exception
 */
@Test
public void testChangePeers() throws Exception {
    String groupId = "test";
    List<String> shrunkPeers = peersToIds(NODES.subList(0, 1));
    List<String> extendedPeers = peersToIds(NODES);
    when(messagingService.invoke(any(NetworkAddress.class), eq(FACTORY.changePeersRequest().newPeersList(shrunkPeers).groupId(groupId).build()), anyLong())).then(invocation -> completedFuture(FACTORY.changePeersResponse().newPeersList(shrunkPeers).build()));
    when(messagingService.invoke(any(NetworkAddress.class), eq(FACTORY.changePeersRequest().newPeersList(extendedPeers).groupId(groupId).build()), anyLong())).then(invocation -> completedFuture(FACTORY.changePeersResponse().newPeersList(extendedPeers).build()));
    mockLeaderRequest(false);
    RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES.subList(0, 2), true, DELAY, executor).get(3, TimeUnit.SECONDS);
    assertEquals(NODES.subList(0, 2), service.peers());
    assertEquals(Collections.emptyList(), service.learners());
    service.changePeers(NODES.subList(0, 1)).get();
    assertEquals(NODES.subList(0, 1), service.peers());
    assertEquals(Collections.emptyList(), service.learners());
    service.changePeers(NODES).get();
    assertEquals(NODES, service.peers());
    assertEquals(Collections.emptyList(), service.learners());
}
Also used : NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Test(org.junit.jupiter.api.Test)

Aggregations

RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)46 Test (org.junit.jupiter.api.Test)33 NetworkAddress (org.apache.ignite.network.NetworkAddress)24 Peer (org.apache.ignite.raft.client.Peer)22 List (java.util.List)11 Path (java.nio.file.Path)9 ArrayList (java.util.ArrayList)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 TimeoutException (java.util.concurrent.TimeoutException)8 Collectors (java.util.stream.Collectors)8 Loza (org.apache.ignite.internal.raft.Loza)8 IgniteLogger (org.apache.ignite.lang.IgniteLogger)8 NotNull (org.jetbrains.annotations.NotNull)8 ExecutionException (java.util.concurrent.ExecutionException)7 TxManager (org.apache.ignite.internal.tx.TxManager)7 IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)7 AfterEach (org.junit.jupiter.api.AfterEach)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 IOException (java.io.IOException)6 UUID (java.util.UUID)6