use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.
the class RaftGroupServiceTest method testAddPeer.
/**
* @throws Exception
*/
@Test
public void testAddPeer() throws Exception {
String groupId = "test";
List<String> respPeers = peersToIds(NODES);
when(messagingService.invoke(any(NetworkAddress.class), eq(FACTORY.addPeerRequest().peerId(PeerId.parsePeer(NODES.get(2).address().host() + ":" + NODES.get(2).address().port()).toString()).groupId(groupId).build()), anyLong())).then(invocation -> completedFuture(FACTORY.addPeerResponse().newPeersList(respPeers).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.addPeer(NODES.get(2)).get();
assertEquals(NODES, service.peers());
assertEquals(Collections.emptyList(), service.learners());
}
use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.
the class RaftGroupServiceTest method testRemoveLearners.
/**
* @throws Exception
*/
@Test
public void testRemoveLearners() throws Exception {
String groupId = "test";
List<String> addLearners = peersToIds(NODES.subList(1, 3));
List<String> removeLearners = peersToIds(NODES.subList(2, 3));
List<String> resultLearners = NODES.subList(1, 2).stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
when(messagingService.invoke(any(NetworkAddress.class), eq(FACTORY.removeLearnersRequest().learnersList(removeLearners).groupId(groupId).build()), anyLong())).then(invocation -> completedFuture(FACTORY.learnersOpResponse().newLearnersList(resultLearners).build()));
mockAddLearners(groupId, addLearners, addLearners);
mockLeaderRequest(false);
RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES.subList(0, 1), true, DELAY, executor).get(3, TimeUnit.SECONDS);
service.addLearners(NODES.subList(1, 3)).get();
assertEquals(NODES.subList(0, 1), service.peers());
assertEquals(NODES.subList(1, 3), service.learners());
service.removeLearners(NODES.subList(2, 3)).get();
assertEquals(NODES.subList(0, 1), service.peers());
assertEquals(NODES.subList(1, 2), service.learners());
}
use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.
the class RaftGroupServiceTest method testSnapshotExecutionException.
/**
* @throws Exception If failed.
*/
@Test
public void testSnapshotExecutionException() throws Exception {
String groupId = "test";
mockSnapshotRequest(1);
RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, false, DELAY, executor).get(3, TimeUnit.SECONDS);
var addr = new NetworkAddress("localhost", 8082);
CompletableFuture<Void> fut = service.snapshot(new Peer(addr));
try {
fut.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IgniteInternalException);
}
}
use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.
the class RaftGroupServiceTest method testRefreshMembers.
/**
* @throws Exception
*/
@Test
public void testRefreshMembers() throws Exception {
String groupId = "test";
List<String> respPeers = peersToIds(NODES.subList(0, 2));
List<String> respLearners = peersToIds(NODES.subList(2, 2));
when(messagingService.invoke(any(NetworkAddress.class), eq(FACTORY.getPeersRequest().onlyAlive(false).groupId(groupId).build()), anyLong())).then(invocation -> completedFuture(FACTORY.getPeersResponse().peersList(respPeers).learnersList(respLearners).build()));
mockLeaderRequest(false);
RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, true, DELAY, executor).get(3, TimeUnit.SECONDS);
assertEquals(NODES, service.peers());
assertEquals(Collections.emptyList(), service.learners());
service.refreshMembers(false).get(3, TimeUnit.SECONDS);
assertEquals(NODES.subList(0, 2), service.peers());
assertEquals(NODES.subList(2, 2), service.learners());
}
use of org.apache.ignite.raft.client.service.RaftGroupService in project ignite-3 by apache.
the class RaftGroupServiceTest method testRefreshLeaderElectedAfterDelay.
/**
* @throws Exception
*/
@Test
public void testRefreshLeaderElectedAfterDelay() throws Exception {
String groupId = "test";
mockLeaderRequest(false);
// Simulate running elections.
leader = null;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
leader = NODES.get(0);
}
}, 500);
RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, false, DELAY, executor).get(3, TimeUnit.SECONDS);
assertNull(service.leader());
service.refreshLeader().get();
assertEquals(NODES.get(0), service.leader());
}
Aggregations