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

项目:fuck_zookeeper    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", PortAssignment.unique(), PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:https-github.com-apache-zookeeper    文件:QuorumPeerConfig.java   
private static QuorumVerifier createQuorumVerifier(Properties dynamicConfigProp, boolean isHierarchical) throws ConfigException{
   if(isHierarchical){
        return new QuorumHierarchical(dynamicConfigProp);
    } else {
       /*
         * The default QuorumVerifier is QuorumMaj
         */        
        //LOG.info("Defaulting to majority quorums");
        return new QuorumMaj(dynamicConfigProp);            
    }          
}
项目:https-github.com-apache-zookeeper    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        InetSocketAddress addr1 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        InetSocketAddress addr2 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        InetSocketAddress addr3 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        port[i] = addr3.getPort();
        qp.setProperty("server."+i, "127.0.0.1:"+addr1.getPort()+":"+addr2.getPort()+";"+port[i]);
        peers.put(Long.valueOf(i), new QuorumServer(i, addr1, addr2, addr3));
        tmpdir[i] = ClientBase.createTmpDir();
    }

    for(int i = 0; i < count; i++) {
        QuorumHierarchical hq = new QuorumHierarchical(qp);
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:ZooKeeper    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", PortAssignment.unique(), PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:StreamProcessingInfrastructure    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", PortAssignment.unique(), PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:bigstreams    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(PortAssignment.unique()),
                new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:bigstreams    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(PortAssignment.unique()),
                new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        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 " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:zookeeper    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", PortAssignment.unique(), PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:SecureKeeper    文件:QuorumPeerConfig.java   
private static QuorumVerifier createQuorumVerifier(Properties dynamicConfigProp, boolean isHierarchical) throws ConfigException{
   if(isHierarchical){
        return new QuorumHierarchical(dynamicConfigProp);
    } else {
       /*
         * The default QuorumVerifier is QuorumMaj
         */        
        //LOG.info("Defaulting to majority quorums");
        return new QuorumMaj(dynamicConfigProp);            
    }          
}
项目:SecureKeeper    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        InetSocketAddress addr1 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        InetSocketAddress addr2 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        InetSocketAddress addr3 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        port[i] = addr3.getPort();
        qp.setProperty("server."+i, "127.0.0.1:"+addr1.getPort()+":"+addr2.getPort()+";"+port[i]);
        peers.put(Long.valueOf(i), new QuorumServer(i, addr1, addr2, addr3));
        tmpdir[i] = ClientBase.createTmpDir();
    }

    for(int i = 0; i < count; i++) {
        QuorumHierarchical hq = new QuorumHierarchical(qp);
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:SecureKeeper    文件:QuorumPeerConfig.java   
private static QuorumVerifier createQuorumVerifier(Properties dynamicConfigProp, boolean isHierarchical) throws ConfigException{
   if(isHierarchical){
        return new QuorumHierarchical(dynamicConfigProp);
    } else {
       /*
         * The default QuorumVerifier is QuorumMaj
         */        
        //LOG.info("Defaulting to majority quorums");
        return new QuorumMaj(dynamicConfigProp);            
    }          
}
项目:SecureKeeper    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        InetSocketAddress addr1 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        InetSocketAddress addr2 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        InetSocketAddress addr3 = new InetSocketAddress("127.0.0.1",PortAssignment.unique());
        port[i] = addr3.getPort();
        qp.setProperty("server."+i, "127.0.0.1:"+addr1.getPort()+":"+addr2.getPort()+";"+port[i]);
        peers.put(Long.valueOf(i), new QuorumServer(i, addr1, addr2, addr3));
        tmpdir[i] = ClientBase.createTmpDir();
    }

    for(int i = 0; i < count; i++) {
        QuorumHierarchical hq = new QuorumHierarchical(qp);
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:StreamBench    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(PortAssignment.unique()),
                new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:LoadBalanced_zk    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(PortAssignment.unique()),
                new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:LoadBalanced_zk    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(PortAssignment.unique()),
                new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:zookeeper.dsc    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(PortAssignment.unique()),
                new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                fail("Elected zero-weight server");
        }
    }
}
项目:zookeeper-pkg    文件:FLEZeroWeightTest.java   
@Test
public void testZeroWeightQuorum() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestZeroWeightQuorum: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(PortAssignment.unique()),
                new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        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, 1000, 2, 2, hq);
        peer.startLeaderElection();
        LEThread thread = new LEThread(peer, i);
        thread.start();
        threads.add(thread);
    }
    LOG.info("Started threads " + getTestName());

    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        } else {
            if(threads.get(i).fail)
                Assert.fail("Elected zero-weight server");
        }
    }
}
项目:https-github.com-apache-zookeeper    文件:ReconfigTest.java   
@Test
public void testQuorumSystemChange() throws Exception {
    qu = new QuorumUtil(3); // create 7 servers
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = createHandles(qu);
    ZooKeeperAdmin[] zkAdminArr = createAdminHandles(qu);

    ArrayList<String> members = new ArrayList<String>();
    members.add("group.1=3:4:5");
    members.add("group.2=1:2");
    members.add("weight.1=0");
    members.add("weight.2=0");
    members.add("weight.3=1");
    members.add("weight.4=1");
    members.add("weight.5=1");

    for (int i = 1; i <= 5; i++) {
        members.add("server." + i + "=127.0.0.1:"
                + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
                + qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
                + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
    }

    reconfig(zkAdminArr[1], null, null, members, -1);

    // this should flush the config to servers 2, 3, 4 and 5
    testNormalOperation(zkArr[2], zkArr[3]);
    testNormalOperation(zkArr[4], zkArr[5]);

    for (int i = 1; i <= 5; i++) {
        if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumHierarchical))
            Assert.fail("peer " + i
                    + " doesn't think the quorum system is Hieararchical!");
    }

    qu.shutdown(1);
    qu.shutdown(2);
    qu.shutdown(3);
    qu.shutdown(7);
    qu.shutdown(6);

    // servers 4 and 5 should be able to work independently
    testNormalOperation(zkArr[4], zkArr[5]);

    qu.restart(1);
    qu.restart(2);

    members.clear();
    for (int i = 1; i <= 3; i++) {
        members.add("server." + i + "=127.0.0.1:"
                + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
                + qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
                + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
    }

    reconfig(zkAdminArr[1], null, null, members, -1);

    // flush the config to server 2
    testNormalOperation(zkArr[1], zkArr[2]);

    qu.shutdown(4);
    qu.shutdown(5);

    // servers 1 and 2 should be able to work independently
    testNormalOperation(zkArr[1], zkArr[2]);

    for (int i = 1; i <= 2; i++) {
        if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumMaj))
            Assert.fail("peer "
                    + i
                    + " doesn't think the quorum system is a majority quorum system!");
    }

    closeAllHandles(zkArr, zkAdminArr);
}
项目:SecureKeeper    文件:ReconfigTest.java   
@Test
public void testQuorumSystemChange() throws Exception {
    qu = new QuorumUtil(3); // create 7 servers
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = createHandles(qu);

    ArrayList<String> members = new ArrayList<String>();
    members.add("group.1=3:4:5");
    members.add("group.2=1:2");
    members.add("weight.1=0");
    members.add("weight.2=0");
    members.add("weight.3=1");
    members.add("weight.4=1");
    members.add("weight.5=1");

    for (int i = 1; i <= 5; i++) {
        members.add("server." + i + "=127.0.0.1:"
                + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
                + qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
                + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
    }

    reconfig(zkArr[1], null, null, members, -1);

    // this should flush the config to servers 2, 3, 4 and 5
    testNormalOperation(zkArr[2], zkArr[3]);
    testNormalOperation(zkArr[4], zkArr[5]);

    for (int i = 1; i <= 5; i++) {
        if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumHierarchical))
            Assert.fail("peer " + i
                    + " doesn't think the quorum system is Hieararchical!");
    }

    qu.shutdown(1);
    qu.shutdown(2);
    qu.shutdown(3);
    qu.shutdown(7);
    qu.shutdown(6);

    // servers 4 and 5 should be able to work independently
    testNormalOperation(zkArr[4], zkArr[5]);

    qu.restart(1);
    qu.restart(2);

    members.clear();
    for (int i = 1; i <= 3; i++) {
        members.add("server." + i + "=127.0.0.1:"
                + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
                + qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
                + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
    }

    reconfig(zkArr[1], null, null, members, -1);

    // flush the config to server 2
    testNormalOperation(zkArr[1], zkArr[2]);

    qu.shutdown(4);
    qu.shutdown(5);

    // servers 1 and 2 should be able to work independently
    testNormalOperation(zkArr[1], zkArr[2]);

    for (int i = 1; i <= 2; i++) {
        if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumMaj))
            Assert.fail("peer "
                    + i
                    + " doesn't think the quorum system is a majority quorum system!");
    }

    closeAllHandles(zkArr);
}
项目:SecureKeeper    文件:ReconfigTest.java   
@Test
public void testQuorumSystemChange() throws Exception {
    qu = new QuorumUtil(3); // create 7 servers
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = createHandles(qu);

    ArrayList<String> members = new ArrayList<String>();
    members.add("group.1=3:4:5");
    members.add("group.2=1:2");
    members.add("weight.1=0");
    members.add("weight.2=0");
    members.add("weight.3=1");
    members.add("weight.4=1");
    members.add("weight.5=1");

    for (int i = 1; i <= 5; i++) {
        members.add("server." + i + "=127.0.0.1:"
                + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
                + qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
                + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
    }

    reconfig(zkArr[1], null, null, members, -1);

    // this should flush the config to servers 2, 3, 4 and 5
    testNormalOperation(zkArr[2], zkArr[3]);
    testNormalOperation(zkArr[4], zkArr[5]);

    for (int i = 1; i <= 5; i++) {
        if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumHierarchical))
            Assert.fail("peer " + i
                    + " doesn't think the quorum system is Hieararchical!");
    }

    qu.shutdown(1);
    qu.shutdown(2);
    qu.shutdown(3);
    qu.shutdown(7);
    qu.shutdown(6);

    // servers 4 and 5 should be able to work independently
    testNormalOperation(zkArr[4], zkArr[5]);

    qu.restart(1);
    qu.restart(2);

    members.clear();
    for (int i = 1; i <= 3; i++) {
        members.add("server." + i + "=127.0.0.1:"
                + qu.getPeer(i).peer.getQuorumAddress().getPort() + ":"
                + qu.getPeer(i).peer.getElectionAddress().getPort() + ";"
                + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
    }

    reconfig(zkArr[1], null, null, members, -1);

    // flush the config to server 2
    testNormalOperation(zkArr[1], zkArr[2]);

    qu.shutdown(4);
    qu.shutdown(5);

    // servers 1 and 2 should be able to work independently
    testNormalOperation(zkArr[1], zkArr[2]);

    for (int i = 1; i <= 2; i++) {
        if (!(qu.getPeer(i).peer.quorumVerifier instanceof QuorumMaj))
            Assert.fail("peer "
                    + i
                    + " doesn't think the quorum system is a majority quorum system!");
    }

    closeAllHandles(zkArr);
}