Java 类org.apache.zookeeper.server.quorum.Vote 实例源码

项目:fuck_zookeeper    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:fuck_zookeeper    文件:FLETestUtils.java   
public void run(){
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:fuck_zookeeper    文件:LENonTerminateTest.java   
public void run(){            
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }                                

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:fuck_zookeeper    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail. 
 */
void mockServer() throws InterruptedException, IOException {          
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:https-github.com-apache-zookeeper    文件:AuthFastLeaderElection.java   
private boolean termPredicate(Map<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:https-github.com-apache-zookeeper    文件:FLETestUtils.java   
public void run() {
    try {
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: {}", i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null) {
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: {}, {}", i, v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:ZooKeeper    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:ZooKeeper    文件:FLETestUtils.java   
public void run(){
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:ZooKeeper    文件:LENonTerminateTest.java   
public void run(){            
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }                                

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:ZooKeeper    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail. 
 */
void mockServer() throws InterruptedException, IOException {          
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:StreamProcessingInfrastructure    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:StreamProcessingInfrastructure    文件:FLETestUtils.java   
public void run(){
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:StreamProcessingInfrastructure    文件:LENonTerminateTest.java   
public void run(){            
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }                                

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:StreamProcessingInfrastructure    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail. 
 */
void mockServer() throws InterruptedException, IOException {          
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:bigstreams    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:bigstreams    文件:LENonTerminateTest.java   
public void run(){            
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }                                

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:bigstreams    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail. 
 */
void mockServer() throws InterruptedException, IOException {          
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:bigstreams    文件:FLETestUtils.java   
public void run(){
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:bigstreams    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:bigstreams    文件:LENonTerminateTest.java   
public void run(){            
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }                                

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:bigstreams    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail. 
 */
void mockServer() throws InterruptedException, IOException {          
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:bigstreams    文件:FLELostMessageTest.java   
public void run(){
    boolean flag = true;
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:zookeeper-src-learning    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:zookeeper    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:zookeeper    文件:FLETestUtils.java   
public void run(){
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:zookeeper    文件:LENonTerminateTest.java   
public void run(){            
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }                                

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:zookeeper    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail. 
 */
void mockServer() throws InterruptedException, IOException {          
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:SecureKeeper    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:SecureKeeper    文件:FLETestUtils.java   
public void run() {
    try {
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: {}", i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null) {
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: {}, {}", i, v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:SecureKeeper    文件:LENonTerminateTest.java   
public void run(){
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:SecureKeeper    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail.
 */
void mockServer() throws InterruptedException, IOException {
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:SecureKeeper    文件:AuthFastLeaderElection.java   
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes,
        long l, long zxid) {


    Collection<Vote> votesCast = votes.values();
    int count = 0;
    /*
     * First make the views consistent. Sometimes peers will have different
     * zxids for a server depending on timing.
     */
    for (Vote v : votesCast) {
        if ((v.getId() == l) && (v.getZxid() == zxid))
            count++;
    }

    if (count > (self.getVotingView().size() / 2))
        return true;
    else
        return false;

}
项目:SecureKeeper    文件:FLETestUtils.java   
public void run() {
    try {
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: {}", i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null) {
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: {}, {}", i, v.getId());

        Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:SecureKeeper    文件:LENonTerminateTest.java   
public void run(){
    try{
        Vote v = null;
        peer.setPeerState(ServerState.LOOKING);
        LOG.info("Going to call leader election: " + i);
        v = peer.getElectionAlg().lookForLeader();

        if (v == null){
            Assert.fail("Thread " + i + " got a null vote");
        }

        /*
         * A real zookeeper would take care of setting the current vote. Here
         * we do it manually.
         */
        peer.setCurrentVote(v);

        LOG.info("Finished election: " + i + ", " + v.getId());
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOG.info("Joining");
}
项目:SecureKeeper    文件:LENonTerminateTest.java   
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail.
 */
void mockServer() throws InterruptedException, IOException {
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);

        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
项目:fuck_zookeeper    文件:FLEDontCareTest.java   
@Test
public void testDontCare() {
    MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));

    HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
    votes.put(0L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 2, ServerState.FOLLOWING));
    votes.put(1L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 2), 1, 2, ServerState.FOLLOWING));
    votes.put(3L, new Vote(0x1, 4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING));
    votes.put(4L, new Vote(0x1, 4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LEADING));

    Assert.assertTrue(fle.termPredicate(votes,
            new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING)));
}
项目:fuck_zookeeper    文件:FLEDontCareTest.java   
@Test
public void testDontCareVersion() {
    MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));

    HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
    votes.put(0L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.FOLLOWING));
    votes.put(1L, new Vote(0x1, 4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.FOLLOWING));
    votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING));
    votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LEADING));

    Assert.assertTrue(fle.termPredicate(votes,
            new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.FOLLOWING)));
}
项目:fuck_zookeeper    文件:FLEDontCareTest.java   
@Test
public void testLookingNormal() {
    MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));

    HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
    votes.put(0L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
    votes.put(1L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
    votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING));
    votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LEADING));

    Assert.assertTrue(fle.termPredicate(votes,
            new Vote(4L, ZxidUtils.makeZxid(2, 1), 1, 1, ServerState.LOOKING)));
}
项目:fuck_zookeeper    文件:FLEDontCareTest.java   
@Test
public void testLookingDiffRounds() {
    MockFLE fle = new MockFLE(peer, new QuorumCnxManager(peer));

    HashMap<Long, Vote> votes = new HashMap<Long, Vote>();
    votes.put(0L, new Vote(4L, ZxidUtils.makeZxid(1, 1), 1, 1, ServerState.LOOKING));
    votes.put(1L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LOOKING));
    votes.put(3L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 3, 2, ServerState.LOOKING));
    votes.put(4L, new Vote(4L, ZxidUtils.makeZxid(2, 1), 3, 2, ServerState.LEADING));

    Assert.assertFalse(fle.termPredicate(votes,
            new Vote(4L, ZxidUtils.makeZxid(2, 1), 2, 2, ServerState.LOOKING)));
}
项目:fuck_zookeeper    文件:FLEDontCareTest.java   
/**
 * Helper method to build notifications and populate outofelection.
 *
 *
 * @param version
 * @param leader
 * @param zxid
 * @param electionEpoch
 * @param state
 * @param sid
 * @param peerEpoch
 * @param outofelection
 * @return
 */
FastLeaderElection.Notification genNotification(int version,
                                                    long leader,
                                                    long zxid,
                                                    long electionEpoch,
                                                    ServerState state,
                                                    long sid,
                                                    long peerEpoch,
                                                    HashMap<Long,Vote> outofelection) {
    FastLeaderElection.Notification n = new FastLeaderElection.Notification();
    n.version = version;
    n.leader = leader;
    n.zxid = zxid;
    n.electionEpoch = electionEpoch;
    n.state = state;
    n.sid = sid;
    n.peerEpoch = peerEpoch;

    outofelection.put(n.sid, new Vote(n.version,
                                        n.leader,
                                        n.zxid,
                                        n.electionEpoch,
                                        n.peerEpoch,
                                        n.state));

    return n;
}