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());
}
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));
}
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());
}
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());
}
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());
}
Aggregations