Package org.apache.zookeeper.server.quorum

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


    public void testCnxManager() throws Exception {
        CnxManagerThread thread = new CnxManagerThread();
       
        thread.start();
       
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 2, 2, 2);
        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
        QuorumCnxManager.Listener listener = cnxManager.listener;
        if(listener != null){
            listener.start();
        } else {
View Full Code Here


                        new InetSocketAddress(deadAddress, deadPort),
                        new InetSocketAddress(deadAddress, PortAssignment.unique())));
        tmpdir[2] = ClientBase.createTmpDir();
        port[2] = deadPort;
   
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 2, 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, tmpdir[1], tmpdir[1], port[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");
        }
       
        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, tmpdir[sid], tmpdir[sid],
                                             port[sid], 3, sid, 1000, 2, 2);
            LOG.info("Starting peer " + peer.getId());
            peer.start();
            peerList.add(sid, peer);
        }
        Thread.sleep(10000);
        verifyThreadCount(peerList, 4);
        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);
                Thread.sleep((peer.getSyncLimit() * peer.getTickTime()) + 2000);
                verifyThreadCount(peerList, 2);

                // Restart halted node and verify count
                peer = new QuorumPeer(peers, tmpdir[myid], tmpdir[myid],
                                        port[myid], 3, myid, 1000, 2, 2);
                LOG.info("Round " + i + ", restarting peer " + peer.getId());
                peer.start();
                peerList.add(myid, peer);
                Thread.sleep(peer.getInitLimit() * peer.getTickTime() * 2);
                verifyThreadCount(peerList, 4);
            }
        }
    }
View Full Code Here

        }
    }

    public void 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) {
                Assert.fail(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, tmpdir[0], tmpdir[0], port[0], 3, 0, 2, 2, 2);
                QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
                QuorumCnxManager.Listener listener = cnxManager.listener;
                if(listener != null){
                    listener.start();
                } else {
View Full Code Here

            tmpdir[i] = ClientBase.createTmpDir();
            port[i] = PortAssignment.unique();
        }

        for(int i = 0; i < le.length; i++) {
            QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i],
                    port[i], 3, i, 2, 2, 2);
            peer.startLeaderElection();
            LEThread thread = new LEThread(peer, i);
            thread.start();
            threads.add(thread);
        }
        LOG.info("Started threads " + getName());
View Full Code Here

              tmpdir[i] = ClientBase.createTmpDir();
              port[i] = PortAssignment.unique();
          }

          for(int i = 1; i < le.length; i++) {
              QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 2, 2, 2);
              peer.startLeaderElection();
              LEThread thread = new LEThread(peer, i);
              thread.start();
              threads.add(thread);
          }
          if(!start0.tryAcquire(4000, java.util.concurrent.TimeUnit.MILLISECONDS))
              fail("First leader election failed");

          QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 2, 2, 2);
          peer.startLeaderElection();
          LEThread thread = new LEThread(peer, 0);
          thread.start();
          threads.add(thread);

          LOG.info("Started threads " + getName());
View Full Code Here

            port[i] = PortAssignment.unique();
        }

        for(int i = 0; i < le.length; i++) {
            QuorumHierarchical hq = new QuorumHierarchical(qp);
            QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 2, 2, 2, hq);
            peer.startLeaderElection();
            LEThread thread = new LEThread(peer, i);
            thread.start();
            threads.add(thread);
        }
        LOG.info("Started threads " + getName());
View Full Code Here

              tmpdir[i] = ClientBase.createTmpDir();
              port[i] = PortAssignment.unique();
          }

          for(int i = 1; i < le.length; i++) {
              QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
              peer.startLeaderElection();
              LEThread thread = new LEThread(peer, i);
              thread.start();
              threads.add(thread);
          }
          if(!start0.tryAcquire(4000, java.util.concurrent.TimeUnit.MILLISECONDS))
              fail("First leader election failed");

          QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
          peer.startLeaderElection();
          LEThread thread = new LEThread(peer, 0);
          thread.start();
          threads.add(thread);

          LOG.info("Started threads " + getName());
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.