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

项目:fuck_zookeeper    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:https-github.com-apache-zookeeper    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(1L).electionAddr, 5000);
    long begin = Time.currentElapsedTime();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = Time.currentElapsedTime();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
    cnxManager.halt();
    Assert.assertFalse(cnxManager.listener.isAlive());
}
项目:ZooKeeper    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:StreamProcessingInfrastructure    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:bigstreams    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:bigstreams    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:bigstreams    文件:FLELostMessageTest.java   
void mockServer() throws InterruptedException, IOException {
    /*
     * Create an instance of the connection manager
     */
    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 2, 2, 2);
    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(1), createMsg(ServerState.LOOKING.ordinal(), 0, 0, 1));
    cnxManager.recvQueue.take();
    cnxManager.toSend(new Long(1), createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 1));  
}
项目:zookeeper    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:SecureKeeper    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(1L).electionAddr, 5000);
    long begin = Time.currentElapsedTime();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = Time.currentElapsedTime();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
    cnxManager.halt();
    Assert.assertFalse(cnxManager.listener.isAlive());
}
项目:SecureKeeper    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(1L).electionAddr, 5000);
    long begin = Time.currentElapsedTime();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = Time.currentElapsedTime();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
    cnxManager.halt();
    Assert.assertFalse(cnxManager.listener.isAlive());
}
项目:StreamBench    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:LoadBalanced_zk    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:LoadBalanced_zk    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:zookeeper.dsc    文件:FLELostMessageTest.java   
void mockServer() throws InterruptedException, IOException {
    /*
     * Create an instance of the connection manager
     */
    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    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(1), createMsg(ServerState.LOOKING.ordinal(), 0, 0, 1));
    cnxManager.recvQueue.take();
    cnxManager.toSend(new Long(1), createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 1));  
}
项目:zookeeper-pkg    文件:CnxManagerTest.java   
@Test
public void testSocketTimeout() throws Exception {
    QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 2000, 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");
    }
    int port = peers.get(peer.getId()).electionAddr.getPort();
    LOG.info("Election port: " + port);
    InetSocketAddress addr = new InetSocketAddress(port);
    Thread.sleep(1000);

    Socket sock = new Socket();
    sock.connect(peers.get(new Long(1)).electionAddr, 5000);
    long begin = System.currentTimeMillis();
    // Read without sending data. Verify timeout.
    cnxManager.receiveConnection(sock);
    long end = System.currentTimeMillis();
    if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
}
项目:fuck_zookeeper    文件:FLEBackwardElectionRoundTest.java   
@Before
public void setUp() throws Exception {
    count = 3;

    peers = new HashMap<Long,QuorumServer>(count);
    tmpdir = new File[count];
    port = new int[count];
    cnxManagers = new QuorumCnxManager[count - 1];
}
项目: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    文件:CnxManagerTest.java   
@Test
public void testCnxManagerTimeout() throws Exception {
    Random rand = new Random();
    byte b = (byte) rand.nextInt();
    int finalOctet = b & 0xFF;
    int deadPort = PortAssignment.unique();
    String deadAddress = new String("192.0.2." + finalOctet);

    LOG.info("This is the dead address I'm trying: " + deadAddress);

    peers.put(Long.valueOf(2),
              new QuorumServer(2, deadAddress, deadPort, PortAssignment.unique(), null));
    peerTmpdir[2] = ClientBase.createTmpDir();

    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");
    }

    long begin = System.currentTimeMillis();
    cnxManager.toSend(new Long(2), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
    long end = System.currentTimeMillis();

    if((end - begin) > 6000) Assert.fail("Waited more than necessary");

}
项目:fuck_zookeeper    文件:CnxManagerTest.java   
public String _verifyThreadCount(ArrayList<QuorumPeer> peerList, long ecnt) {
    for (int myid = 0; myid < peerList.size(); myid++) {
        QuorumPeer peer = peerList.get(myid);
        QuorumCnxManager cnxManager = peer.getQuorumCnxManager();
        long cnt = cnxManager.getThreadCount();
        if (cnt != ecnt) {
            return new String(new Date()
                + " Incorrect number of Worker threads for sid=" + myid
                + " expected " + ecnt + " found " + cnt);
        }
    }
    return null;
}
项目:fuck_zookeeper    文件:FLELostMessageTest.java   
void mockServer() throws InterruptedException, IOException {
    /*
     * Create an instance of the connection manager
     */
    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    listener.start();


    cnxManager.toSend(1l, FLETestUtils.createMsg(ServerState.LOOKING.ordinal(), 0, 0, 0));
    cnxManager.recvQueue.take();
    cnxManager.toSend(1L, FLETestUtils.createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 0));
}
项目:https-github.com-apache-zookeeper    文件:FLEBackwardElectionRoundTest.java   
@Before
public void setUp() throws Exception {
    count = 3;

    peers = new HashMap<Long,QuorumServer>(count);
    tmpdir = new File[count];
    port = new int[count];
    cnxManagers = new QuorumCnxManager[count - 1];
}
项目:https-github.com-apache-zookeeper    文件:FLELostMessageTest.java   
void mockServer() throws InterruptedException, IOException {
    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    cnxManager = new QuorumCnxManager(peer);
    cnxManager.listener.start();

    cnxManager.toSend(1l, FLETestUtils.createMsg(ServerState.LOOKING.ordinal(), 0, 0, 0));
    cnxManager.recvQueue.take();
    cnxManager.toSend(1L, FLETestUtils.createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 0));
}
项目: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());
}
项目:https-github.com-apache-zookeeper    文件:CnxManagerTest.java   
@Test
public void testCnxManagerTimeout() throws Exception {
    Random rand = new Random();
    byte b = (byte) rand.nextInt();
    int deadPort = PortAssignment.unique();
    String deadAddress = "10.1.1." + b;

    LOG.info("This is the dead address I'm trying: " + deadAddress);

    peers.put(Long.valueOf(2),
            new QuorumServer(2,
                    new InetSocketAddress(deadAddress, deadPort),
                    new InetSocketAddress(deadAddress, PortAssignment.unique()),
                    new InetSocketAddress(deadAddress, PortAssignment.unique())));
    peerTmpdir[2] = ClientBase.createTmpDir();

    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");
    }

    long begin = Time.currentElapsedTime();
    cnxManager.toSend(2L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
    long end = Time.currentElapsedTime();

    if((end - begin) > 6000) Assert.fail("Waited more than necessary");
    cnxManager.halt();
    Assert.assertFalse(cnxManager.listener.isAlive());
}
项目:https-github.com-apache-zookeeper    文件:CnxManagerTest.java   
public String _verifyThreadCount(ArrayList<QuorumPeer> peerList, long ecnt) {
    for (int myid = 0; myid < peerList.size(); myid++) {
        QuorumPeer peer = peerList.get(myid);
        QuorumCnxManager cnxManager = peer.getQuorumCnxManager();
        long cnt = cnxManager.getThreadCount();
        if (cnt != ecnt) {
            return new Date()
                + " Incorrect number of Worker threads for sid=" + myid
                + " expected " + ecnt + " found " + cnt;
        }
    }
    return null;
}
项目:ZooKeeper    文件:FLEBackwardElectionRoundTest.java   
@Before
public void setUp() throws Exception {
    count = 3;

    peers = new HashMap<Long,QuorumServer>(count);
    tmpdir = new File[count];
    port = new int[count];
    cnxManagers = new QuorumCnxManager[count - 1];
}
项目: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    文件:CnxManagerTest.java   
@Test
public void testCnxManagerTimeout() throws Exception {
    Random rand = new Random();
    byte b = (byte) rand.nextInt();
    int finalOctet = b & 0xFF;
    int deadPort = PortAssignment.unique();
    String deadAddress = new String("192.0.2." + finalOctet);

    LOG.info("This is the dead address I'm trying: " + deadAddress);

    peers.put(Long.valueOf(2),
              new QuorumServer(2, deadAddress, deadPort, PortAssignment.unique(), null));
    peerTmpdir[2] = ClientBase.createTmpDir();

    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");
    }

    long begin = System.currentTimeMillis();
    cnxManager.toSend(new Long(2), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
    long end = System.currentTimeMillis();

    if((end - begin) > 6000) Assert.fail("Waited more than necessary");

}
项目:ZooKeeper    文件:CnxManagerTest.java   
public String _verifyThreadCount(ArrayList<QuorumPeer> peerList, long ecnt) {
    for (int myid = 0; myid < peerList.size(); myid++) {
        QuorumPeer peer = peerList.get(myid);
        QuorumCnxManager cnxManager = peer.getQuorumCnxManager();
        long cnt = cnxManager.getThreadCount();
        if (cnt != ecnt) {
            return new String(new Date()
                + " Incorrect number of Worker threads for sid=" + myid
                + " expected " + ecnt + " found " + cnt);
        }
    }
    return null;
}
项目:ZooKeeper    文件:FLELostMessageTest.java   
void mockServer() throws InterruptedException, IOException {
    /*
     * Create an instance of the connection manager
     */
    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    cnxManager = peer.createCnxnManager();
    QuorumCnxManager.Listener listener = cnxManager.listener;
    listener.start();


    cnxManager.toSend(1l, FLETestUtils.createMsg(ServerState.LOOKING.ordinal(), 0, 0, 0));
    cnxManager.recvQueue.take();
    cnxManager.toSend(1L, FLETestUtils.createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 0));
}
项目:StreamProcessingInfrastructure    文件:FLEBackwardElectionRoundTest.java   
@Before
public void setUp() throws Exception {
    count = 3;

    peers = new HashMap<Long,QuorumServer>(count);
    tmpdir = new File[count];
    port = new int[count];
    cnxManagers = new QuorumCnxManager[count - 1];
}
项目: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    文件:CnxManagerTest.java   
@Test
public void testCnxManagerTimeout() throws Exception {
    Random rand = new Random();
    byte b = (byte) rand.nextInt();
    int finalOctet = b & 0xFF;
    int deadPort = PortAssignment.unique();
    String deadAddress = new String("192.0.2." + finalOctet);

    LOG.info("This is the dead address I'm trying: " + deadAddress);

    peers.put(Long.valueOf(2),
              new QuorumServer(2, deadAddress, deadPort, PortAssignment.unique(), null));
    peerTmpdir[2] = ClientBase.createTmpDir();

    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");
    }

    long begin = System.currentTimeMillis();
    cnxManager.toSend(new Long(2), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
    long end = System.currentTimeMillis();

    if((end - begin) > 6000) Assert.fail("Waited more than necessary");

}
项目:StreamProcessingInfrastructure    文件:CnxManagerTest.java   
public String _verifyThreadCount(ArrayList<QuorumPeer> peerList, long ecnt) {
    for (int myid = 0; myid < peerList.size(); myid++) {
        QuorumPeer peer = peerList.get(myid);
        QuorumCnxManager cnxManager = peer.getQuorumCnxManager();
        long cnt = cnxManager.getThreadCount();
        if (cnt != ecnt) {
            return new String(new Date()
                + " Incorrect number of Worker threads for sid=" + myid
                + " expected " + ecnt + " found " + cnt);
        }
    }
    return null;
}
项目:StreamProcessingInfrastructure    文件:FLELostMessageTest.java   
void mockServer() throws InterruptedException, IOException {
    /*
     * Create an instance of the connection manager
     */
    QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
    cnxManager = new QuorumCnxManager(peer);
    QuorumCnxManager.Listener listener = cnxManager.listener;
    listener.start();


    cnxManager.toSend(1l, FLETestUtils.createMsg(ServerState.LOOKING.ordinal(), 0, 0, 0));
    cnxManager.recvQueue.take();
    cnxManager.toSend(1L, FLETestUtils.createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 0));
}
项目:bigstreams    文件:FLEBackwardElectionRoundTest.java   
@Before
public void setUp() throws Exception {
    count = 3;

    peers = new HashMap<Long,QuorumServer>(count);
    tmpdir = new File[count];
    port = new int[count];
    cnxManagers = new QuorumCnxManager[count - 1];
}