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

项目:fuck_zookeeper    文件:FLEDontCareTest.java   
/**
 * Helper method to build notifications and populate outofelection.
 *
 *
 * @param version
 * @param leader
 * @param zxid
 * @param electionEpoch
 * @param state
 * @param sid
 * @param peerEpoch
 * @param outofelection
 * @return
 */
FastLeaderElection.Notification genNotification(int version,
                                                    long leader,
                                                    long zxid,
                                                    long electionEpoch,
                                                    ServerState state,
                                                    long sid,
                                                    long peerEpoch,
                                                    HashMap<Long,Vote> outofelection) {
    FastLeaderElection.Notification n = new FastLeaderElection.Notification();
    n.version = version;
    n.leader = leader;
    n.zxid = zxid;
    n.electionEpoch = electionEpoch;
    n.state = state;
    n.sid = sid;
    n.peerEpoch = peerEpoch;

    outofelection.put(n.sid, new Vote(n.version,
                                        n.leader,
                                        n.zxid,
                                        n.electionEpoch,
                                        n.peerEpoch,
                                        n.state));

    return n;
}
项目:fuck_zookeeper    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", clientport,
                                   PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目: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");
        }
    }
}
项目:fuck_zookeeper    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目:ZooKeeper    文件:FLEDontCareTest.java   
/**
 * Helper method to build notifications and populate outofelection.
 *
 *
 * @param version
 * @param leader
 * @param zxid
 * @param electionEpoch
 * @param state
 * @param sid
 * @param peerEpoch
 * @param outofelection
 * @return
 */
FastLeaderElection.Notification genNotification(int version,
                                                    long leader,
                                                    long zxid,
                                                    long electionEpoch,
                                                    ServerState state,
                                                    long sid,
                                                    long peerEpoch,
                                                    HashMap<Long,Vote> outofelection) {
    FastLeaderElection.Notification n = new FastLeaderElection.Notification();
    n.version = version;
    n.leader = leader;
    n.zxid = zxid;
    n.electionEpoch = electionEpoch;
    n.state = state;
    n.sid = sid;
    n.peerEpoch = peerEpoch;

    outofelection.put(n.sid, new Vote(n.version,
                                        n.leader,
                                        n.zxid,
                                        n.electionEpoch,
                                        n.peerEpoch,
                                        n.state));

    return n;
}
项目:ZooKeeper    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", clientport,
                                   PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目: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");
        }
    }
}
项目:ZooKeeper    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目:StreamProcessingInfrastructure    文件:FLEDontCareTest.java   
/**
 * Helper method to build notifications and populate outofelection.
 *
 *
 * @param version
 * @param leader
 * @param zxid
 * @param electionEpoch
 * @param state
 * @param sid
 * @param peerEpoch
 * @param outofelection
 * @return
 */
FastLeaderElection.Notification genNotification(int version,
                                                    long leader,
                                                    long zxid,
                                                    long electionEpoch,
                                                    ServerState state,
                                                    long sid,
                                                    long peerEpoch,
                                                    HashMap<Long,Vote> outofelection) {
    FastLeaderElection.Notification n = new FastLeaderElection.Notification();
    n.version = version;
    n.leader = leader;
    n.zxid = zxid;
    n.electionEpoch = electionEpoch;
    n.state = state;
    n.sid = sid;
    n.peerEpoch = peerEpoch;

    outofelection.put(n.sid, new Vote(n.version,
                                        n.leader,
                                        n.zxid,
                                        n.electionEpoch,
                                        n.peerEpoch,
                                        n.state));

    return n;
}
项目:StreamProcessingInfrastructure    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", clientport,
                                   PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目: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");
        }
    }
}
项目:StreamProcessingInfrastructure    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目: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    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(clientport),
                        new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目:bigstreams    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目: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");
        }
    }
}
项目:bigstreams    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(clientport),
                        new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目:bigstreams    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < 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 " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目:zookeeper    文件:FLEDontCareTest.java   
/**
 * Helper method to build notifications and populate outofelection.
 *
 *
 * @param version
 * @param leader
 * @param zxid
 * @param electionEpoch
 * @param state
 * @param sid
 * @param peerEpoch
 * @param outofelection
 * @return
 */
FastLeaderElection.Notification genNotification(int version,
                                                    long leader,
                                                    long zxid,
                                                    long electionEpoch,
                                                    ServerState state,
                                                    long sid,
                                                    long peerEpoch,
                                                    HashMap<Long,Vote> outofelection) {
    FastLeaderElection.Notification n = new FastLeaderElection.Notification();
    n.version = version;
    n.leader = leader;
    n.zxid = zxid;
    n.electionEpoch = electionEpoch;
    n.state = state;
    n.sid = sid;
    n.peerEpoch = peerEpoch;

    outofelection.put(n.sid, new Vote(n.version,
                                        n.leader,
                                        n.zxid,
                                        n.electionEpoch,
                                        n.peerEpoch,
                                        n.state));

    return n;
}
项目:zookeeper    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "0.0.0.0", clientport,
                                   PortAssignment.unique(), null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目: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");
        }
    }
}
项目:zookeeper    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目:StreamBench    文件:FLEDontCareTest.java   
/**
 * Helper method to build notifications and populate outofelection.
 *
 *
 * @param version
 * @param leader
 * @param zxid
 * @param electionEpoch
 * @param state
 * @param sid
 * @param peerEpoch
 * @param outofelection
 * @return
 */
FastLeaderElection.Notification genNotification(int version,
                                                    long leader,
                                                    long zxid,
                                                    long electionEpoch,
                                                    ServerState state,
                                                    long sid,
                                                    long peerEpoch,
                                                    HashMap<Long,Vote> outofelection) {
    FastLeaderElection.Notification n = new FastLeaderElection.Notification();
    n.version = version;
    n.leader = leader;
    n.zxid = zxid;
    n.electionEpoch = electionEpoch;
    n.state = state;
    n.sid = sid;
    n.peerEpoch = peerEpoch;

    outofelection.put(n.sid, new Vote(n.version,
                                        n.leader,
                                        n.zxid,
                                        n.electionEpoch,
                                        n.peerEpoch,
                                        n.state));

    return n;
}
项目:StreamBench    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(clientport),
                        new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目: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");
        }
    }
}
项目:StreamBench    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目: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    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(clientport),
                        new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目:LoadBalanced_zk    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目: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    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(clientport),
                        new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目:LoadBalanced_zk    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}
项目:zookeeper.dsc    文件:FLENewEpochTest.java   
@Override
public void tearDown() throws Exception {
    for(int i = 0; i < threads.size(); i++) {
        ((FastLeaderElection) threads.get(i).peer.getElectionAlg()).shutdown();
    }
    LOG.info("FINISHED " + getName());
}
项目: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.dsc    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(clientport),
                        new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * 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
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        fail("Threads didn't join");
    }
}
项目:zookeeper.dsc    文件:FLERestartTest.java   
@Override
public void tearDown() throws Exception {
    for(int i = 0; i < restartThreads.size(); i++) {
        ((FastLeaderElection) restartThreads.get(i).peer.getElectionAlg()).shutdown();
    }
    LOG.info("FINISHED " + getName());
}
项目:zookeeper.dsc    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            fail("Threads didn't join");
        }

    }
}
项目: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");
        }
    }
}
项目:zookeeper-pkg    文件:FLELostMessageTest.java   
@Test
public void testLostMessage() throws Exception {
    FastLeaderElection le[] = new FastLeaderElection[count];

    LOG.info("TestLE: " + getTestName()+ ", " + count);
    for(int i = 0; i < count; i++) {
        int clientport = PortAssignment.unique();
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress(clientport),
                        new InetSocketAddress(PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = clientport;
    }

    /*
     * Start server 0
     */

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

    /*
     * Start mock server 1
     */
    mockServer();
    thread.join(5000);
    if (thread.isAlive()) {
        Assert.fail("Threads didn't join");
    }
}
项目:zookeeper-pkg    文件:FLERestartTest.java   
@Test
public void testLERestart() throws Exception {

    FastLeaderElection le[] = new FastLeaderElection[count];
    leaderDies = true;
    boolean allowOneBadLeader = leaderDies;

    LOG.info("TestLE: " + 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 < count; i++) {
        QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
        peer.startLeaderElection();
        FLERestartThread thread = new FLERestartThread(peer, i);
        thread.start();
        restartThreads.add(thread);
    }
    LOG.info("Started threads " + getTestName());
    for(int i = 0; i < restartThreads.size(); i++) {
        restartThreads.get(i).join(10000);
        if (restartThreads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }

    }
}