@Test public void testGetElectionTimeout() throws Exception { int confTimeout = cluster.getConf(0).getInt("raft.election.timeout"); Method m = nodes[0].getClass().getDeclaredMethod("getElectionTimeout", new Class[] {}); m.setAccessible(true); for(int i = 0; i < 100; i++) { Object result = m.invoke(nodes[0], null); int resultInt = ((Integer)result).intValue(); assertTrue(resultInt >= confTimeout); assertTrue(resultInt <= confTimeout*2); } }
private int getElectionTimeout() { int confTimeout = conf.getInt("raft.election.timeout"); int r = RandomUtils.nextInt(confTimeout); return confTimeout + r; }
RaftNode { private int getElectionTimeout() { int confTimeout = conf.getInt("raft.election.timeout"); int r = RandomUtils.nextInt(confTimeout); return confTimeout + r; } }
RaftNode { private int getElectionTimeout() { int confTimeout = conf.getInt("raft.election.timeout"); int r = RandomUtils.nextInt(confTimeout); return confTimeout + r; } RaftNode(Configuration conf); }
RaftNode { private int getElectionTimeout() { int confTimeout = conf.getInt("raft.election.timeout"); int r = RandomUtils.nextInt(confTimeout); return confTimeout + r; } RaftNode(Configuration conf); long getCurrentTerm(); ServerInfo getServerInfo(); Set<ServerInfo> getRemoteServers(); ServerInfo getCurrentLeader(); RaftLog getRaftLog(); RaftRpcService getRaftService(); NodeConnectionManager getNodeConnectionManager(); String getName(); int getTotalServerNumbers(); void resetTimer(); boolean isLeader(); State getState(); void kill(); void increaseTerm(); void checkRpcTerm(ServerInfo leader, long term); synchronized void discoverHigherTerm(ServerInfo remoteServer, long newTerm); synchronized void discoverLeader(ServerInfo leader, long term); void voteReceived(ServerInfo server, long term); synchronized boolean voteRequest(ServerInfo candidate, long term, long lastLogIndex, long lastLogTerm); void testHearBeat(); static void main(String[] args); }
RaftNode { private int getElectionTimeout() { int confTimeout = conf.getInt("raft.election.timeout"); int r = RandomUtils.nextInt(confTimeout); return confTimeout + r; } RaftNode(Configuration conf); long getCurrentTerm(); ServerInfo getServerInfo(); Set<ServerInfo> getRemoteServers(); ServerInfo getCurrentLeader(); RaftLog getRaftLog(); RaftRpcService getRaftService(); NodeConnectionManager getNodeConnectionManager(); String getName(); int getTotalServerNumbers(); void resetTimer(); boolean isLeader(); State getState(); void kill(); void increaseTerm(); void checkRpcTerm(ServerInfo leader, long term); synchronized void discoverHigherTerm(ServerInfo remoteServer, long newTerm); synchronized void discoverLeader(ServerInfo leader, long term); void voteReceived(ServerInfo server, long term); synchronized boolean voteRequest(ServerInfo candidate, long term, long lastLogIndex, long lastLogTerm); void testHearBeat(); static void main(String[] args);  }