Search in sources :

Example 1 with CliService

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);
    }
}
Also used : Configuration(org.apache.ignite.raft.jraft.conf.Configuration) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) CliService(org.apache.ignite.raft.jraft.CliService) Map(java.util.Map) HashMap(java.util.HashMap) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 2 with CliService

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());
    }
}
Also used : Configuration(org.apache.ignite.raft.jraft.conf.Configuration) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) CliService(org.apache.ignite.raft.jraft.CliService) Map(java.util.Map) HashMap(java.util.HashMap) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 3 with CliService

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());
}
Also used : Configuration(org.apache.ignite.raft.jraft.conf.Configuration) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) CliService(org.apache.ignite.raft.jraft.CliService) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 CliService (org.apache.ignite.raft.jraft.CliService)3 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)3 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)3 Test (org.junit.jupiter.api.Test)3 Map (java.util.Map)2