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

项目:fuck_zookeeper    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:fuck_zookeeper    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目: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);
}
项目:https-github.com-apache-zookeeper    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:https-github.com-apache-zookeeper    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(0L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }
    cnxManager.halt();
    Assert.assertFalse(cnxManager.listener.isAlive());
}
项目:ZooKeeper    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = peer.createCnxnManager();
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:ZooKeeper    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = peer.createCnxnManager();
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目: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    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:StreamProcessingInfrastructure    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目: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);
}
项目:bigstreams    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:bigstreams    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目:bigstreams    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 2, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:bigstreams    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目:zookeeper    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:zookeeper    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目: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);
}
项目:SecureKeeper    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:SecureKeeper    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(0L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }
    cnxManager.halt();
    Assert.assertFalse(cnxManager.listener.isAlive());
}
项目:SecureKeeper    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:SecureKeeper    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(0L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }
    cnxManager.halt();
    Assert.assertFalse(cnxManager.listener.isAlive());
}
项目:StreamBench    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:StreamBench    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目: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);
}
项目:LoadBalanced_zk    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:LoadBalanced_zk    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目:LoadBalanced_zk    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:LoadBalanced_zk    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目:zookeeper.dsc    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        fail("Unexpected exception");
    }
}
项目:zookeeper.dsc    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        fail("Thread didn't join");
    } else {
        if(thread.failed)
            fail("Did not receive expected message");
    }
}
项目:zookeeper-pkg    文件:CnxManagerTest.java   
public void run(){
    try {
        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[0], peerTmpdir[0], peerClientPort[0], 3, 0, 1000, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
            LOG.error("Null listener when initializing cnx manager");
        }

        long sid = 1;
        cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));

        Message m = null;
        int numRetries = 1;
        while((m == null) && (numRetries++ <= THRESHOLD)){
            m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
            if(m == null) cnxManager.connectAll();
        }

        if(numRetries > THRESHOLD){
            failed = true;
            return;
        }

        cnxManager.testInitiateConnection(sid);

        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null){
            failed = true;
            return;
        }
    } catch (Exception e) {
        LOG.error("Exception while running mock thread", e);
        Assert.fail("Unexpected exception");
    }
}
项目:zookeeper-pkg    文件:CnxManagerTest.java   
@Test
public void testCnxManager() throws Exception {
    CnxManagerThread thread = new CnxManagerThread();

    thread.start();

    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
    QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    if(listener != null){
        listener.start();
    } else {
        LOG.error("Null listener when initializing cnx manager");
    }

    cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));

    Message m = null;
    int numRetries = 1;
    while((m == null) && (numRetries++ <= THRESHOLD)){
        m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
        if(m == null) cnxManager.connectAll();
    }

    Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);

    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Thread didn't join");
    } else {
        if(thread.failed)
            Assert.fail("Did not receive expected message");
    }

}
项目:fuck_zookeeper    文件:CnxManagerTest.java   
long getSid(Message m){
    return m.sid;
}
项目:fuck_zookeeper    文件:CnxManagerTest.java   
String getMsgString(Message m){
    return new String(m.buffer.array());
}