• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java QuorumCnxManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumCnxManager的典型用法代码示例。如果您正苦于以下问题:Java QuorumCnxManager类的具体用法?Java QuorumCnxManager怎么用?Java QuorumCnxManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



QuorumCnxManager类属于org.apache.zookeeper.server.quorum包,在下文中一共展示了QuorumCnxManager类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSocketTimeout

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:24,代码来源:CnxManagerTest.java


示例2: testSocketTimeout

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:25,代码来源:CnxManagerTest.java


示例3: testSocketTimeout

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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");
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:24,代码来源:CnxManagerTest.java


示例4: mockServer

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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));  
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:18,代码来源:FLELostMessageTest.java


示例5: mockServer

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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));  
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:18,代码来源:FLELostMessageTest.java


示例6: setUp

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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];
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:10,代码来源:FLEBackwardElectionRoundTest.java


示例7: run

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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");
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:39,代码来源:CnxManagerTest.java


示例8: testCnxManager

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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");
    }
    
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:36,代码来源:CnxManagerTest.java


示例9: testCnxManagerTimeout

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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");
    
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:31,代码来源:CnxManagerTest.java


示例10: _verifyThreadCount

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:CnxManagerTest.java


示例11: mockServer

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:15,代码来源:FLELostMessageTest.java


示例12: mockServer

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:10,代码来源:FLELostMessageTest.java


示例13: testCnxManager

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:37,代码来源:CnxManagerTest.java


示例14: testCnxManagerTimeout

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:34,代码来源:CnxManagerTest.java


示例15: _verifyThreadCount

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:14,代码来源:CnxManagerTest.java


示例16: run

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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");
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:39,代码来源:CnxManagerTest.java


示例17: testCnxManager

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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");
    }
    
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:36,代码来源:CnxManagerTest.java


示例18: testCnxManagerTimeout

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
@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");
    
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:31,代码来源:CnxManagerTest.java


示例19: mockServer

import org.apache.zookeeper.server.quorum.QuorumCnxManager; //导入依赖的package包/类
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));
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:15,代码来源:FLELostMessageTest.java



注:本文中的org.apache.zookeeper.server.quorum.QuorumCnxManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java R类代码示例发布时间:2022-05-22
下一篇:
Java AbstractJavaGenerator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap