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

项目:fuck_zookeeper    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testBackwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerBackward fle = new MockFLEMessengerBackward(peer, mng);
    ByteBuffer buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);

    /*
     * Check that it sends a notification back to the sender
     */
    peer.setPeerState(ServerState.FOLLOWING);
    peer.setCurrentVote( new Vote(2, 0x1, 1, 1, ServerState.LOOKING) );
    buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 1, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 1));
    ToSend m = fle.internalqueue.take();
    Assert.assertTrue("Wrong state", m.state == ServerState.FOLLOWING);
    Assert.assertTrue("Wrong sid", m.sid == 1);
    Assert.assertTrue("Wrong leader", m.leader == 2);
    Assert.assertTrue("Wrong epoch", m.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", m.peerEpoch == 1);
}
项目:fuck_zookeeper    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testForwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerForward fle = new MockFLEMessengerForward(peer, mng);
    ByteBuffer notBuffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    ByteBuffer buffer = ByteBuffer.allocate( notBuffer.capacity() + 8 );
    notBuffer.flip();
    buffer.put(notBuffer);
    buffer.putLong( Long.MAX_VALUE );
    buffer.flip();

    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
    Assert.assertTrue("Wrong version", n.version == FastLeaderElection.Notification.CURRENTVERSION);
}
项目:ZooKeeper    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testBackwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = peer.createCnxnManager();

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerBackward fle = new MockFLEMessengerBackward(peer, mng);
    ByteBuffer buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);

    /*
     * Check that it sends a notification back to the sender
     */
    peer.setPeerState(ServerState.FOLLOWING);
    peer.setCurrentVote( new Vote(2, 0x1, 1, 1, ServerState.LOOKING) );
    buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 1, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 1));
    ToSend m = fle.internalqueue.take();
    Assert.assertTrue("Wrong state", m.state == ServerState.FOLLOWING);
    Assert.assertTrue("Wrong sid", m.sid == 1);
    Assert.assertTrue("Wrong leader", m.leader == 2);
    Assert.assertTrue("Wrong epoch", m.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", m.peerEpoch == 1);
}
项目:ZooKeeper    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testForwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = peer.createCnxnManager();

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerForward fle = new MockFLEMessengerForward(peer, mng);
    ByteBuffer notBuffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    ByteBuffer buffer = ByteBuffer.allocate( notBuffer.capacity() + 8 );
    notBuffer.flip();
    buffer.put(notBuffer);
    buffer.putLong( Long.MAX_VALUE );
    buffer.flip();

    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
    Assert.assertTrue("Wrong version", n.version == FastLeaderElection.Notification.CURRENTVERSION);
}
项目:StreamProcessingInfrastructure    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testBackwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerBackward fle = new MockFLEMessengerBackward(peer, mng);
    ByteBuffer buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);

    /*
     * Check that it sends a notification back to the sender
     */
    peer.setPeerState(ServerState.FOLLOWING);
    peer.setCurrentVote( new Vote(2, 0x1, 1, 1, ServerState.LOOKING) );
    buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 1, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 1));
    ToSend m = fle.internalqueue.take();
    Assert.assertTrue("Wrong state", m.state == ServerState.FOLLOWING);
    Assert.assertTrue("Wrong sid", m.sid == 1);
    Assert.assertTrue("Wrong leader", m.leader == 2);
    Assert.assertTrue("Wrong epoch", m.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", m.peerEpoch == 1);
}
项目:StreamProcessingInfrastructure    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testForwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerForward fle = new MockFLEMessengerForward(peer, mng);
    ByteBuffer notBuffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    ByteBuffer buffer = ByteBuffer.allocate( notBuffer.capacity() + 8 );
    notBuffer.flip();
    buffer.put(notBuffer);
    buffer.putLong( Long.MAX_VALUE );
    buffer.flip();

    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
    Assert.assertTrue("Wrong version", n.version == FastLeaderElection.Notification.CURRENTVERSION);
}
项目:zookeeper    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testBackwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerBackward fle = new MockFLEMessengerBackward(peer, mng);
    ByteBuffer buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);

    /*
     * Check that it sends a notification back to the sender
     */
    peer.setPeerState(ServerState.FOLLOWING);
    peer.setCurrentVote( new Vote(2, 0x1, 1, 1, ServerState.LOOKING) );
    buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 1, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 1));
    ToSend m = fle.internalqueue.take();
    Assert.assertTrue("Wrong state", m.state == ServerState.FOLLOWING);
    Assert.assertTrue("Wrong sid", m.sid == 1);
    Assert.assertTrue("Wrong leader", m.leader == 2);
    Assert.assertTrue("Wrong epoch", m.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", m.peerEpoch == 1);
}
项目:zookeeper    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testForwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerForward fle = new MockFLEMessengerForward(peer, mng);
    ByteBuffer notBuffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    ByteBuffer buffer = ByteBuffer.allocate( notBuffer.capacity() + 8 );
    notBuffer.flip();
    buffer.put(notBuffer);
    buffer.putLong( Long.MAX_VALUE );
    buffer.flip();

    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
    Assert.assertTrue("Wrong version", n.version == FastLeaderElection.Notification.CURRENTVERSION);
}
项目:StreamBench    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testBackwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerBackward fle = new MockFLEMessengerBackward(peer, mng);
    ByteBuffer buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);

    /*
     * Check that it sends a notification back to the sender
     */
    peer.setPeerState(ServerState.FOLLOWING);
    peer.setCurrentVote( new Vote(2, 0x1, 1, 1, ServerState.LOOKING) );
    buffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 1, 0x1, 1, 1);
    fle.manager.recvQueue.add(new Message(buffer, 1));
    ToSend m = fle.internalqueue.take();
    Assert.assertTrue("Wrong state", m.state == ServerState.FOLLOWING);
    Assert.assertTrue("Wrong sid", m.sid == 1);
    Assert.assertTrue("Wrong leader", m.leader == 2);
    Assert.assertTrue("Wrong epoch", m.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", m.peerEpoch == 1);
}
项目:StreamBench    文件:FLECompatibilityTest.java   
@Test(timeout=20000)
public void testForwardCompatibility() 
throws Exception {
    populate();

    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    peer.setPeerState(ServerState.LOOKING);
    QuorumCnxManager mng = new QuorumCnxManager(peer);

    /*
     * Check that it generates an internal notification correctly
     */
    MockFLEMessengerForward fle = new MockFLEMessengerForward(peer, mng);
    ByteBuffer notBuffer = FastLeaderElection.buildMsg(ServerState.LOOKING.ordinal(), 2, 0x1, 1, 1);
    ByteBuffer buffer = ByteBuffer.allocate( notBuffer.capacity() + 8 );
    notBuffer.flip();
    buffer.put(notBuffer);
    buffer.putLong( Long.MAX_VALUE );
    buffer.flip();

    fle.manager.recvQueue.add(new Message(buffer, 2));
    Notification n = fle.recvqueue.take();
    Assert.assertTrue("Wrong state", n.state == ServerState.LOOKING);
    Assert.assertTrue("Wrong leader", n.leader == 2);
    Assert.assertTrue("Wrong zxid", n.zxid == 0x1);
    Assert.assertTrue("Wrong epoch", n.electionEpoch == 1);
    Assert.assertTrue("Wrong epoch", n.peerEpoch == 1);
    Assert.assertTrue("Wrong version", n.version == FastLeaderElection.Notification.CURRENTVERSION);
}