use of org.apache.ignite.raft.jraft.CliService in project ignite-3 by apache.
the class ItCliServiceTest method testRebalance.
@Test
public void testRebalance() {
Set<String> groupIds = new TreeSet<>();
groupIds.add("group_1");
groupIds.add("group_2");
groupIds.add("group_3");
groupIds.add("group_4");
groupIds.add("group_5");
groupIds.add("group_6");
groupIds.add("group_7");
groupIds.add("group_8");
Configuration conf = new Configuration();
conf.addPeer(new PeerId("host_1", 8080));
conf.addPeer(new PeerId("host_2", 8080));
conf.addPeer(new PeerId("host_3", 8080));
Map<String, PeerId> rebalancedLeaderIds = new HashMap<>();
CliService cliService = new MockCliService(rebalancedLeaderIds, new PeerId("host_1", 8080));
assertTrue(cliService.rebalance(groupIds, conf, rebalancedLeaderIds).isOk());
assertEquals(groupIds.size(), rebalancedLeaderIds.size());
Map<PeerId, Integer> ret = new HashMap<>();
for (Map.Entry<String, PeerId> entry : rebalancedLeaderIds.entrySet()) {
ret.compute(entry.getValue(), (ignored, num) -> num == null ? 1 : num + 1);
}
int expectedAvgLeaderNum = (int) Math.ceil((double) groupIds.size() / conf.size());
for (Map.Entry<PeerId, Integer> entry : ret.entrySet()) {
System.out.println(entry);
assertTrue(entry.getValue() <= expectedAvgLeaderNum);
}
}
use of org.apache.ignite.raft.jraft.CliService in project ignite-3 by apache.
the class ItCliServiceTest method testRelalanceOnTransferLeaderFail.
@Test
public void testRelalanceOnTransferLeaderFail() {
Set<String> groupIds = new TreeSet<>();
groupIds.add("group_1");
groupIds.add("group_2");
groupIds.add("group_3");
groupIds.add("group_4");
groupIds.add("group_5");
groupIds.add("group_6");
groupIds.add("group_7");
Configuration conf = new Configuration();
conf.addPeer(new PeerId("host_1", 8080));
conf.addPeer(new PeerId("host_2", 8080));
conf.addPeer(new PeerId("host_3", 8080));
Map<String, PeerId> rebalancedLeaderIds = new HashMap<>();
CliService cliService = new MockTransferLeaderFailCliService(rebalancedLeaderIds, new PeerId("host_1", 8080));
assertEquals("Fail to transfer leader", cliService.rebalance(groupIds, conf, rebalancedLeaderIds).getErrorMsg());
assertTrue(groupIds.size() >= rebalancedLeaderIds.size());
Map<PeerId, Integer> ret = new HashMap<>();
for (Map.Entry<String, PeerId> entry : rebalancedLeaderIds.entrySet()) {
ret.compute(entry.getValue(), (ignored, num) -> num == null ? 1 : num + 1);
}
for (Map.Entry<PeerId, Integer> entry : ret.entrySet()) {
LOG.info(entry.toString());
assertEquals(new PeerId("host_1", 8080), entry.getKey());
}
}
use of org.apache.ignite.raft.jraft.CliService in project ignite-3 by apache.
the class ItCliServiceTest method testRebalanceOnLeaderFail.
@Test
public void testRebalanceOnLeaderFail() {
Set<String> groupIds = new TreeSet<>();
groupIds.add("group_1");
groupIds.add("group_2");
groupIds.add("group_3");
groupIds.add("group_4");
Configuration conf = new Configuration();
conf.addPeer(new PeerId("host_1", 8080));
conf.addPeer(new PeerId("host_2", 8080));
conf.addPeer(new PeerId("host_3", 8080));
Map<String, PeerId> rebalancedLeaderIds = new HashMap<>();
CliService cliService = new MockLeaderFailCliService();
assertEquals("Fail to get leader", cliService.rebalance(groupIds, conf, rebalancedLeaderIds).getErrorMsg());
}
Aggregations