Package org.apache.zookeeper.server.quorum

Examples of org.apache.zookeeper.server.quorum.QuorumPeer


        }
       
        switch(i){
        case 1:
            LOG.info("creating QuorumPeer 1 port " + port1);
            s1 = new QuorumPeer(peers, s1dir, s1dir, port1, 3, 1, tickTime, initLimit, syncLimit);
            assertEquals(port1, s1.getClientPort());
            break;
        case 2:
            LOG.info("creating QuorumPeer 2 port " + port2);
            s2 = new QuorumPeer(peers, s2dir, s2dir, port2, 3, 2, tickTime, initLimit, syncLimit);
            assertEquals(port2, s2.getClientPort());
            break;
        case 3
            LOG.info("creating QuorumPeer 3 port " + port3);
            s3 = new QuorumPeer(peers, s3dir, s3dir, port3, 3, 3, tickTime, initLimit, syncLimit);
            assertEquals(port3, s3.getClientPort());
            break;
        case 4:
            LOG.info("creating QuorumPeer 4 port " + port4);
            s4 = new QuorumPeer(peers, s4dir, s4dir, port4, 3, 4, tickTime, initLimit, syncLimit);
            assertEquals(port4, s4.getClientPort());
            break;
        case 5:
            LOG.info("creating QuorumPeer 5 port " + port5);
            s5 = new QuorumPeer(peers, s5dir, s5dir, port5, 3, 5, tickTime, initLimit, syncLimit);
            assertEquals(port5, s5.getClientPort());
        }
    }
View Full Code Here


        }
        LeaderElection le[] = new LeaderElection[count];
        leaderDies = true;
        boolean allowOneBadLeader = leaderDies;
        for(int i = 0; i < le.length; i++) {
            QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i],
                    port[i], 0, i, 1000, 2, 2);
            peer.startLeaderElection();
            le[i] = new LeaderElection(peer);
            LEThread thread = new LEThread(le[i], peer, i);
            thread.start();
            threads.add(thread);
        }
View Full Code Here

    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 {
View Full Code Here

                new QuorumServer(2,
                        new InetSocketAddress(deadAddress, deadPort),
                        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 {
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testCnxManagerSpinLock() throws Exception {              
        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");
        }
       
        int port = peers.get(peer.getId()).electionAddr.getPort();
        LOG.info("Election port: " + port);
        InetSocketAddress addr = new InetSocketAddress(port);
       
        Thread.sleep(1000);
       
        SocketChannel sc = SocketChannel.open();
        sc.socket().connect(peers.get(new Long(1)).electionAddr, 5000);
       
        /*
         * Write id first then negative length.
         */
        byte[] msgBytes = new byte[8];
        ByteBuffer msgBuffer = ByteBuffer.wrap(msgBytes);
        msgBuffer.putLong(new Long(2));
        msgBuffer.position(0);
        sc.write(msgBuffer);
       
        msgBuffer = ByteBuffer.wrap(new byte[4]);
        msgBuffer.putInt(-20);
        msgBuffer.position(0);
        sc.write(msgBuffer);
       
        Thread.sleep(1000);
       
        try{
            /*
             * Write a number of times until it
             * detects that the socket is broken.
             */
            for(int i = 0; i < 100; i++){
                msgBuffer.position(0);
                sc.write(msgBuffer);
            }
            fail("Socket has not been closed");
        } catch (Exception e) {
            LOG.info("Socket has been closed as expected");
        }
        peer.shutdown();
        cnxManager.halt();
    }  
View Full Code Here

    @Test
    public void testWorkerThreads() throws Exception {
        ArrayList<QuorumPeer> peerList = new ArrayList<QuorumPeer>();

        for (int sid = 0; sid < 3; sid++) {
            QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[sid], peerTmpdir[sid],
                                             peerClientPort[sid], 3, sid, 1000, 2, 2);
            LOG.info("Starting peer " + peer.getId());
            peer.start();
            peerList.add(sid, peer);
        }
        String failure = verifyThreadCount(peerList, 4);
        if (failure != null) {
            Assert.fail(failure);
        }
        for (int myid = 0; myid < 3; myid++) {
            for (int i = 0; i < 5; i++) {
                // halt one of the listeners and verify count
                QuorumPeer peer = peerList.get(myid);
                LOG.info("Round " + i + ", halting peer " + peer.getId());
                peer.shutdown();
                peerList.remove(myid);
                failure = verifyThreadCount(peerList, 2);
                if (failure != null) {
                    Assert.fail(failure);
                }

                // Restart halted node and verify count
                peer = new QuorumPeer(peers, peerTmpdir[myid], peerTmpdir[myid],
                                        peerClientPort[myid], 3, myid, 1000, 2, 2);
                LOG.info("Round " + i + ", restarting peer " + peer.getId());
                peer.start();
                peerList.add(myid, peer);
                failure = verifyThreadCount(peerList, 4);
                if (failure != null) {
                    Assert.fail(failure);
                }
View Full Code Here

        }
        return failure;
    }
    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);
View Full Code Here

            failed = false;
        }
       
        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 {
View Full Code Here

       
        /*
         * Start server 0
         */
           
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 1000, 2, 2);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, 1);
        thread.start();
           
        /*
         * Start mock server 1
View Full Code Here

       
    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 {
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.server.quorum.QuorumPeer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.