@Override @Test public void testEnforceLeader() throws Exception { super.testEnforceLeader(); MiniRaftClusterWithHadoopRpc.sendServerRequest.clear(); BlockRequestHandlingInjection.getInstance().unblockAll(); } }
@Test public void testEnforceLeader() throws Exception { LOG.info("Running testEnforceLeader"); final int numServer = 5; try(final MiniRaftCluster cluster = newCluster(numServer)) { cluster.start(); final RaftPeerId firstLeader = waitForLeader(cluster).getId(); LOG.info("firstLeader = {}", firstLeader); final int first = MiniRaftCluster.getIdIndex(firstLeader.toString()); final int random = ThreadLocalRandom.current().nextInt(numServer - 1); final String newLeader = "s" + (random < first? random: random + 1); LOG.info("enforce leader to {}", newLeader); enforceLeader(cluster, newLeader, LOG); } }
@Test public void testBasicLeaderElection() throws Exception { LOG.info("Running testBasicLeaderElection"); final MiniRaftCluster cluster = newCluster(5); cluster.start(); RaftTestUtil.waitAndKillLeader(cluster); RaftTestUtil.waitAndKillLeader(cluster); RaftTestUtil.waitAndKillLeader(cluster); testFailureCase("waitForLeader after killed a majority of servers", () -> RaftTestUtil.waitForLeader(cluster, null, false), IllegalStateException.class); cluster.shutdown(); }
@Test public void testLateServerStart() throws Exception { final int numServer = 3; LOG.info("Running testLateServerStart"); final MiniRaftCluster cluster = newCluster(numServer); cluster.initServers(); // start all except one servers final Iterator<RaftServerProxy> i = cluster.getServers().iterator(); for(int j = 1; j < numServer; j++) { i.next().start(); } final RaftServerImpl leader = waitForLeader(cluster); final TimeDuration sleepTime = TimeDuration.valueOf(3, TimeUnit.SECONDS); LOG.info("sleep " + sleepTime); sleepTime.sleep(); // start the last server final RaftServerProxy lastServer = i.next(); lastServer.start(); final RaftPeerId lastServerLeaderId = JavaUtils.attempt( () -> getLeader(lastServer.getImpls().iterator().next().getState()), 10, 1000, "getLeaderId", LOG); LOG.info(cluster.printServers()); Assert.assertEquals(leader.getId(), lastServerLeaderId); }
@Test public void testEnforceLeader() throws Exception { final int numServer = 3; LOG.info("Running testEnforceLeader"); final String leader = "s" + ThreadLocalRandom.current().nextInt(numServer); LOG.info("enforce leader to " + leader); final MiniRaftCluster cluster = newCluster(numServer); cluster.start(); waitForLeader(cluster); waitForLeader(cluster, leader); cluster.shutdown(); }
@Test public void testLateServerStart() throws Exception { final int numServer = 3; LOG.info("Running testLateServerStart"); final MiniRaftCluster cluster = newCluster(numServer); cluster.initServers(); // start all except one servers final Iterator<RaftServerProxy> i = cluster.getServers().iterator(); for(int j = 1; j < numServer; j++) { i.next().start(); } final RaftServerImpl leader = waitForLeader(cluster); final TimeDuration sleepTime = TimeDuration.valueOf(5, TimeUnit.SECONDS); LOG.info("sleep " + sleepTime); sleepTime.sleep(); // start the last server final RaftServerProxy lastServer = i.next(); lastServer.start(); final RaftPeerId lastServerLeaderId = JavaUtils.attempt( () -> getLeader(lastServer.getImpl().getState()), 10, 1000, "getLeaderId", LOG); Assert.assertEquals(leader.getId(), lastServerLeaderId); }
@Test public void testBasicLeaderElection() throws Exception { LOG.info("Running testBasicLeaderElection"); final MiniRaftCluster cluster = newCluster(5); cluster.start(); waitAndKillLeader(cluster, true); waitAndKillLeader(cluster, true); waitAndKillLeader(cluster, true); waitAndKillLeader(cluster, false); cluster.shutdown(); }
@Override @Test public void testEnforceLeader() throws Exception { super.testEnforceLeader(); MiniRaftClusterWithHadoopRpc.sendServerRequest.clear(); BlockRequestHandlingInjection.getInstance().unblockAll(); } }
@Test public void testChangeLeader() throws Exception { RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.TRACE); LOG.info("Running testChangeLeader"); final MiniRaftCluster cluster = newCluster(3); cluster.start(); RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId(); for(int i = 0; i < 10; i++) { leader = RaftTestUtil.changeLeader(cluster, leader); ExitUtils.assertNotTerminated(); } RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.INFO); cluster.shutdown(); }
@Override @Test public void testEnforceLeader() throws Exception { super.testEnforceLeader(); MiniRaftClusterWithGRpc.sendServerRequestInjection.clear(); BlockRequestHandlingInjection.getInstance().unblockAll(); } }
@Test public void testChangeLeader() throws Exception { RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.TRACE); LOG.info("Running testChangeLeader"); final MiniRaftCluster cluster = newCluster(3); cluster.start(); RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId(); for(int i = 0; i < 10; i++) { leader = RaftTestUtil.changeLeader(cluster, leader); ExitUtils.assertNotTerminated(); } RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.INFO); cluster.shutdown(); }
@Override @Test public void testEnforceLeader() throws Exception { super.testEnforceLeader(); MiniRaftClusterWithGrpc.sendServerRequestInjection.clear(); BlockRequestHandlingInjection.getInstance().unblockAll(); } }
@Override @Test public void testEnforceLeader() throws Exception { super.testEnforceLeader(); MiniRaftClusterWithNetty.sendServerRequest.clear(); BlockRequestHandlingInjection.getInstance().unblockAll(); } }