Package org.apache.zookeeper.server.quorum

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


        List<String> joiningServers = new ArrayList<String>();

        // assert remotePeerBean.1 of ReplicatedServer_2
        int leavingIndex = 1;
        int replica2 = 2;
        QuorumPeer peer2 = qu.getPeer(replica2).peer;
        QuorumServer leavingQS2 = peer2.getView().get(new Long(leavingIndex));
        String remotePeerBean2 = CommonNames.DOMAIN
                + ":name0=ReplicatedServer_id" + replica2 + ",name1=replica."
                + leavingIndex;
        assertRemotePeerMXBeanAttributes(leavingQS2, remotePeerBean2);

        // assert remotePeerBean.1 of ReplicatedServer_3
        int replica3 = 3;
        QuorumPeer peer3 = qu.getPeer(replica3).peer;
        QuorumServer leavingQS3 = peer3.getView().get(new Long(leavingIndex));
        String remotePeerBean3 = CommonNames.DOMAIN
                + ":name0=ReplicatedServer_id" + replica3 + ",name1=replica."
                + leavingIndex;
        assertRemotePeerMXBeanAttributes(leavingQS3, remotePeerBean3);

        ZooKeeper zk = zkArr[leavingIndex];

        leavingServers.add(Integer.toString(leavingIndex));

        // remember this server so we can add it back later
        joiningServers.add("server." + leavingIndex + "=127.0.0.1:"
                + qu.getPeer(leavingIndex).peer.getQuorumAddress().getPort()
                + ":"
                + qu.getPeer(leavingIndex).peer.getElectionAddress().getPort()
                + ":participant;127.0.0.1:"
                + qu.getPeer(leavingIndex).peer.getClientPort());

        // Remove ReplicatedServer_1 from the ensemble
        reconfig(zk, null, leavingServers, null, -1);

        // localPeerBean.1 of ReplicatedServer_1
        QuorumPeer removedPeer = qu.getPeer(leavingIndex).peer;
        String localPeerBean = CommonNames.DOMAIN
                + ":name0=ReplicatedServer_id" + leavingIndex
                + ",name1=replica." + leavingIndex;
        assertLocalPeerMXBeanAttributes(removedPeer, localPeerBean, false);
View Full Code Here


        List<String> joiningServers = new ArrayList<String>();

        // assert remotePeerBean.1 of ReplicatedServer_2
        int changingIndex = 1;
        int replica2 = 2;
        QuorumPeer peer2 = qu.getPeer(replica2).peer;
        QuorumServer changingQS2 = peer2.getView().get(new Long(changingIndex));
        String remotePeerBean2 = CommonNames.DOMAIN
                + ":name0=ReplicatedServer_id" + replica2 + ",name1=replica."
                + changingIndex;
        assertRemotePeerMXBeanAttributes(changingQS2, remotePeerBean2);

        // assert remotePeerBean.1 of ReplicatedServer_3
        int replica3 = 3;
        QuorumPeer peer3 = qu.getPeer(replica3).peer;
        QuorumServer changingQS3 = peer3.getView().get(new Long(changingIndex));
        String remotePeerBean3 = CommonNames.DOMAIN
                + ":name0=ReplicatedServer_id" + replica3 + ",name1=replica."
                + changingIndex;
        assertRemotePeerMXBeanAttributes(changingQS3, remotePeerBean3);

        String newRole = "observer";

        ZooKeeper zk = zkArr[changingIndex];

        // exactly as it is now, except for role change
        joiningServers.add("server." + changingIndex + "=127.0.0.1:"
                + qu.getPeer(changingIndex).peer.getQuorumAddress().getPort()
                + ":"
                + qu.getPeer(changingIndex).peer.getElectionAddress().getPort()
                + ":" + newRole + ";127.0.0.1:"
                + qu.getPeer(changingIndex).peer.getClientPort());

        reconfig(zk, joiningServers, null, null, -1);
        testNormalOperation(zkArr[changingIndex], zk);

        Assert.assertTrue(qu.getPeer(changingIndex).peer.observer != null
                && qu.getPeer(changingIndex).peer.follower == null
                && qu.getPeer(changingIndex).peer.leader == null);
        Assert.assertTrue(qu.getPeer(changingIndex).peer.getPeerState() == ServerState.OBSERVING);

        QuorumPeer qp = qu.getPeer(changingIndex).peer;
        String localPeerBeanName = CommonNames.DOMAIN
                + ":name0=ReplicatedServer_id" + changingIndex
                + ",name1=replica." + changingIndex;

        // localPeerBean.1 of ReplicatedServer_1
View Full Code Here

        }

        /*
         * peer1 and peer2 are A and B in the above example.
         */
        QuorumPeer peer1 = new MockQuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 0, 0, 2, 2, 2);
        peer1.startLeaderElection();
        LEThread thread1 = new LEThread(peer1, 0);

        QuorumPeer peer2 = new MockQuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 0, 1, 2, 2, 2);
        peer2.startLeaderElection();
        LEThread thread2 = new LEThread(peer2, 1);

        /*
         * Start mock server.
         */
 
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, 2, 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, 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);
       
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 < count; i++) {
            QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 2, 2, 2);
            peer.startLeaderElection();
            FLERestartThread thread = new FLERestartThread(peer, i);
            thread.start();
            restartThreads.add(thread);
        }
        LOG.info("Started threads " + getName());
View Full Code Here

                        if(peerRound == 0){
                            LOG.info("First peer, shutting it down");
                            QuorumBase.shutdown(peer);
                            ((FastLeaderElection) restartThreads.get(i).peer.getElectionAlg()).shutdown();

                            peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 2, 2, 2);
                            peer.startLeaderElection();
                            peerRound++;
                        } else {
                            finish.release(2);
                            return;
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.