Search in sources :

Example 31 with QuorumServer

use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.

the class LETest method testLE.

@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);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) LeaderElection(org.apache.zookeeper.server.quorum.LeaderElection) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) File(java.io.File) Test(org.junit.Test)

Example 32 with QuorumServer

use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.

the class CnxManagerTest method setUp.

@Before
public void setUp() throws Exception {
    this.count = 3;
    this.peers = new HashMap<Long, QuorumServer>(count);
    peerTmpdir = new File[count];
    peerQuorumPort = new int[count];
    peerClientPort = new int[count];
    for (int i = 0; i < count; i++) {
        peerQuorumPort[i] = PortAssignment.unique();
        peerClientPort[i] = PortAssignment.unique();
        peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress("127.0.0.1", peerQuorumPort[i]), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", peerClientPort[i])));
        peerTmpdir[i] = ClientBase.createTmpDir();
    }
}
Also used : QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) InetSocketAddress(java.net.InetSocketAddress) Before(org.junit.Before)

Example 33 with QuorumServer

use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.

the class Zab1_0Test method createQuorumPeer.

private QuorumPeer createQuorumPeer(File tmpDir) throws IOException, FileNotFoundException {
    HashMap<Long, QuorumServer> peers = new HashMap<Long, QuorumServer>();
    QuorumPeer peer = new QuorumPeer();
    peer.syncLimit = SYNC_LIMIT;
    peer.initLimit = 2;
    peer.tickTime = 2000;
    peers.put(0L, new QuorumServer(0, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
    peers.put(1L, new QuorumServer(1, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
    peers.put(2L, new QuorumServer(2, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
    peer.setQuorumVerifier(new QuorumMaj(peers), false);
    peer.setCnxnFactory(new NullServerCnxnFactory());
    File version2 = new File(tmpDir, "version-2");
    version2.mkdir();
    ClientBase.createInitializeFile(tmpDir);
    FileOutputStream fos;
    fos = new FileOutputStream(new File(version2, "currentEpoch"));
    fos.write("0\n".getBytes());
    fos.close();
    fos = new FileOutputStream(new File(version2, "acceptedEpoch"));
    fos.write("0\n".getBytes());
    fos.close();
    return peer;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) InetSocketAddress(java.net.InetSocketAddress) QuorumMaj(org.apache.zookeeper.server.quorum.flexible.QuorumMaj) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 34 with QuorumServer

use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.

the class QuorumServerTest method constructionUnderstandsIpv6LiteralsInClientConfig.

@Test
public void constructionUnderstandsIpv6LiteralsInClientConfig() throws ConfigException {
    String config = "127.0.0.1:1234:1236:participant;[::1]:1237";
    QuorumServer qs = new QuorumServer(0, config);
    assertEquals("127.0.0.1:1234:1236:participant;[0:0:0:0:0:0:0:1]:1237", qs.toString());
}
Also used : QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) Test(org.junit.Test)

Example 35 with QuorumServer

use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.

the class QuorumServerTest method constructionUnderstandsIpv6LiteralsInServerConfig.

@Test
public void constructionUnderstandsIpv6LiteralsInServerConfig() throws ConfigException {
    String config = "[::1]:1234:1236:participant";
    QuorumServer qs = new QuorumServer(0, config);
    assertEquals("[0:0:0:0:0:0:0:1]:1234:1236:participant", qs.toString());
}
Also used : QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) Test(org.junit.Test)

Aggregations

QuorumServer (org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)41 InetSocketAddress (java.net.InetSocketAddress)25 Test (org.junit.Test)20 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)19 HashMap (java.util.HashMap)9 IOException (java.io.IOException)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Before (org.junit.Before)4 ByteBuffer (java.nio.ByteBuffer)3 KeeperException (org.apache.zookeeper.KeeperException)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 Vote (org.apache.zookeeper.server.quorum.Vote)3 DatagramPacket (java.net.DatagramPacket)2 DatagramSocket (java.net.DatagramSocket)2 SocketException (java.net.SocketException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Properties (java.util.Properties)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2