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

项目:fuck_zookeeper    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:fuck_zookeeper    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "127.0.0.1", PortAssignment.unique(), 0, null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:ZooKeeper    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:ZooKeeper    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "127.0.0.1", PortAssignment.unique(), 0, null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:StreamProcessingInfrastructure    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:StreamProcessingInfrastructure    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "127.0.0.1", PortAssignment.unique(), 0, null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:bigstreams    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:bigstreams    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:bigstreams    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:bigstreams    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:zookeeper    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:zookeeper    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                  new QuorumServer(i, "127.0.0.1", PortAssignment.unique(), 0, null));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:SecureKeeper    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:SecureKeeper    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:SecureKeeper    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:SecureKeeper    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:StreamBench    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:StreamBench    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:LoadBalanced_zk    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:LoadBalanced_zk    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:LoadBalanced_zk    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:LoadBalanced_zk    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}
项目:zookeeper.dsc    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:zookeeper.dsc    文件:LETest.java   
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            fail("Threads didn't join");
        }
    }
    long id = votes[0].id;
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            fail("Thread " + i + " had a null vote");
        }
        if (votes[i].id != id) {
            if (allowOneBadLeader && votes[i].id == i) {
                allowOneBadLeader = false;
            } else {
                fail("Thread " + i + " got " + votes[i].id + " expected " + id);
            }
        }
    }
}
项目:zookeeper-pkg    文件:LETest.java   
LEThread(LeaderElection le, QuorumPeer peer, int i) {
    this.le = le;
    this.i = i;
    this.peer = peer;
}
项目:zookeeper-pkg    文件:LETest.java   
@Test
public void testLE() throws Exception {
    int count = 30;
    HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>(count);
    ArrayList<LEThread> threads = new ArrayList<LEThread>(count);
    File tmpdir[] = new File[count];
    int port[] = new int[count];
    votes = new Vote[count];
    for(int i = 0; i < count; i++) {
        peers.put(Long.valueOf(i),
                new QuorumServer(i,
                        new InetSocketAddress("127.0.0.1",
                                PortAssignment.unique())));
        tmpdir[i] = ClientBase.createTmpDir();
        port[i] = PortAssignment.unique();
    }
    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);
    }
    for(int i = 0; i < threads.size(); i++) {
        threads.get(i).join(15000);
        if (threads.get(i).isAlive()) {
            Assert.fail("Threads didn't join");
        }
    }
    long id = votes[0].getId();
    for(int i = 1; i < votes.length; i++) {
        if (votes[i] == null) {
            Assert.fail("Thread " + i + " had a null vote");
        }
        if (votes[i].getId() != id) {
            if (allowOneBadLeader && votes[i].getId() == i) {
                allowOneBadLeader = false;
            } else {
                Assert.fail("Thread " + i + " got " + votes[i].getId() + " expected " + id);
            }
        }
    }
}