private void runTestReinitializeMultiGroups(int[] idIndex, int chosen) throws Exception { printThreadCount(null, "init"); runTestReinitializeMultiGroups(getCluster(0), idIndex, chosen, NOOP); }
public MiniRaftCluster getCluster(int peerNum) throws IOException { return getClusterFactory().newCluster(peerNum, prop); }
@Test public void testReinitialize7Nodes() throws Exception { final int[] idIndex = {1, 6, 7}; runTestReinitializeMultiGroups(idIndex, 1); }
@Test public void testReinitialize() throws Exception { final MiniRaftCluster cluster = getCluster(0); LOG.info("Start testReinitialize" + cluster.printServers()); // Start server with an empty conf final RaftGroupId groupId = RaftGroupId.randomId(); final RaftGroup group = new RaftGroup(groupId); final List<RaftPeerId> ids = Arrays.stream(MiniRaftCluster.generateIds(3, 0)) .map(RaftPeerId::valueOf).collect(Collectors.toList()); ids.forEach(id -> cluster.putNewServer(id, group, true)); LOG.info("putNewServer: " + cluster.printServers()); cluster.start(); LOG.info("start: " + cluster.printServers()); // Make sure that there are no leaders. TimeUnit.SECONDS.sleep(1); Assert.assertNull(cluster.getLeader()); // Reinitialize servers final RaftGroup newGroup = new RaftGroup(groupId, cluster.getPeers()); final RaftClient client = cluster.createClient(newGroup); for(RaftPeer p : newGroup.getPeers()) { client.reinitialize(newGroup, p.getId()); } Assert.assertNotNull(RaftTestUtil.waitForLeader(cluster, true)); cluster.shutdown(); }
checker.accept(cluster, groups[i]); printThreadCount(type, "start groups"); LOG.info("start groups: " + cluster.printServers()); printThreadCount(type, "close groups"); LOG.info("close groups: " + cluster.printServers()); checker.accept(cluster, groups[chosen]); LOG.info("update groups: " + cluster.printServers()); printThreadCount(type, "update groups"); printThreadCount(type, "shutdown");
@Test public void testReinitialize5Nodes() throws Exception { final int[] idIndex = {3, 4, 5}; runTestReinitializeMultiGroups(idIndex, 0); }
@Test public void testReinitialize9Nodes() throws Exception { final int[] idIndex = {5, 8, 9}; runTestReinitializeMultiGroups(idIndex, 2); }
private void runTestMultiRaftGroup(int[] idIndex, int chosen) throws Exception { final CheckedBiConsumer<MiniRaftCluster, RaftGroup, IOException> checker = (cluster, group) -> { try (final RaftClient client = cluster.createClient(group)) { TestArithmetic.runTestPythagorean(client, start.getAndAdd(2*count), count); } }; ReinitializationBaseTest.runTestReinitializeMultiGroups( cluster, idIndex, chosen, checker); } }