Search in sources :

Example 51 with QuorumServer

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

the class QuorumMaj method toString.

public String toString() {
    StringBuilder sw = new StringBuilder();
    for (QuorumServer member : getAllMembers().values()) {
        String key = "server." + member.id;
        String value = member.toString();
        sw.append(key);
        sw.append('=');
        sw.append(value);
        sw.append('\n');
    }
    String hexVersion = Long.toHexString(version);
    sw.append("version=");
    sw.append(hexVersion);
    return sw.toString();
}
Also used : QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)

Example 52 with QuorumServer

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

the class Zab1_0Test method testObserverConversation.

public void testObserverConversation(ObserverConversation conversation) throws Exception {
    File tmpDir = File.createTempFile("test", "dir", testData);
    tmpDir.delete();
    tmpDir.mkdir();
    Thread observerThread = null;
    ConversableObserver observer = null;
    QuorumPeer peer = null;
    try {
        peer = createQuorumPeer(tmpDir);
        peer.setSyncEnabled(true);
        observer = createObserver(tmpDir, peer);
        peer.observer = observer;
        ServerSocket ss = new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1"));
        QuorumServer leaderQS = new QuorumServer(1, (InetSocketAddress) ss.getLocalSocketAddress());
        observer.setLeaderQuorumServer(leaderQS);
        final Observer observerForThread = observer;
        observerThread = new Thread() {

            public void run() {
                try {
                    observerForThread.observeLeader();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        observerThread.start();
        Socket leaderSocket = ss.accept();
        InputArchive ia = BinaryInputArchive.getArchive(leaderSocket.getInputStream());
        OutputArchive oa = BinaryOutputArchive.getArchive(leaderSocket.getOutputStream());
        conversation.converseWithObserver(ia, oa, observer);
    } finally {
        if (observer != null) {
            observer.shutdown();
        }
        if (observerThread != null) {
            observerThread.interrupt();
            observerThread.join();
        }
        if (peer != null) {
            peer.shutdown();
        }
        TestUtils.deleteFileRecursively(tmpDir);
    }
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) OutputArchive(org.apache.jute.OutputArchive) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) InputArchive(org.apache.jute.InputArchive) BinaryInputArchive(org.apache.jute.BinaryInputArchive) ZabUtils.createQuorumPeer(org.apache.zookeeper.server.quorum.ZabUtils.createQuorumPeer) ServerSocket(java.net.ServerSocket) File(java.io.File) EOFException(java.io.EOFException) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 53 with QuorumServer

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

the class RemotePeerBeanTest method testGetClientAddressShouldReturnEmptyStringWhenClientAddressIsNull.

/**
 * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2269
 */
@Test
public void testGetClientAddressShouldReturnEmptyStringWhenClientAddressIsNull() {
    InetSocketAddress peerCommunicationAddress = null;
    // Here peerCommunicationAddress is null, also clientAddr is null
    QuorumServer peer = new QuorumServer(1, peerCommunicationAddress);
    RemotePeerBean remotePeerBean = new RemotePeerBean(null, peer);
    String clientAddress = remotePeerBean.getClientAddress();
    assertNotNull(clientAddress);
    assertEquals(0, clientAddress.length());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) Test(org.junit.jupiter.api.Test)

Example 54 with QuorumServer

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

the class CnxManagerTest method testCnxManagerListenerThreadConfigurableRetry.

/**
 * Test for bug described in https://issues.apache.org/jira/browse/ZOOKEEPER-3320.
 * Test create peer with address which contains unresolvable DNS name,
 * leader election listener thread should stop after N errors.
 *
 * @throws Exception
 */
@Test
public void testCnxManagerListenerThreadConfigurableRetry() throws Exception {
    final Map<Long, QuorumServer> unresolvablePeers = new HashMap<>();
    final long myid = 1L;
    unresolvablePeers.put(myid, new QuorumServer(myid, "unresolvable-domain.org:2182:2183;2181"));
    final QuorumPeer peer = new QuorumPeer(unresolvablePeers, ClientBase.createTmpDir(), ClientBase.createTmpDir(), 2181, 3, myid, 1000, 2, 2, 2);
    final QuorumCnxManager cnxManager = peer.createCnxnManager();
    final QuorumCnxManager.Listener listener = cnxManager.listener;
    final AtomicBoolean errorHappend = new AtomicBoolean(false);
    listener.setSocketBindErrorHandler(() -> errorHappend.set(true));
    listener.start();
    // listener thread should stop and throws error which notify QuorumPeer about error.
    // QuorumPeer should start shutdown process
    // set wait time, if listener contains bug and thread not stops.
    listener.join(15000);
    assertFalse(listener.isAlive());
    assertTrue(errorHappend.get());
    assertFalse(listener.isAlive(), QuorumPeer.class.getSimpleName() + " not stopped after " + "listener thread death");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) FLENewEpochTest(org.apache.zookeeper.test.FLENewEpochTest) Test(org.junit.jupiter.api.Test)

Example 55 with QuorumServer

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

the class QuorumBase method setupServer.

public void setupServer(int i) throws IOException {
    int tickTime = 2000;
    int initLimit = 3;
    int syncLimit = 3;
    int connectToLearnerMasterLimit = 3;
    if (peers == null) {
        peers = new HashMap<Long, QuorumServer>();
        peers.put(Long.valueOf(1), new QuorumServer(1, new InetSocketAddress(LOCALADDR, port1), new InetSocketAddress(LOCALADDR, portLE1), new InetSocketAddress(LOCALADDR, portClient1), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(2), new QuorumServer(2, new InetSocketAddress(LOCALADDR, port2), new InetSocketAddress(LOCALADDR, portLE2), new InetSocketAddress(LOCALADDR, portClient2), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(3), new QuorumServer(3, new InetSocketAddress(LOCALADDR, port3), new InetSocketAddress(LOCALADDR, portLE3), new InetSocketAddress(LOCALADDR, portClient3), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(4), new QuorumServer(4, new InetSocketAddress(LOCALADDR, port4), new InetSocketAddress(LOCALADDR, portLE4), new InetSocketAddress(LOCALADDR, portClient4), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(5), new QuorumServer(5, new InetSocketAddress(LOCALADDR, port5), new InetSocketAddress(LOCALADDR, portLE5), new InetSocketAddress(LOCALADDR, portClient5), LearnerType.PARTICIPANT));
    }
    switch(i) {
        case 1:
            LOG.info("creating QuorumPeer 1 port {}", portClient1);
            s1 = new QuorumPeer(peers, s1dir, s1dir, portClient1, 3, 1, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
            assertEquals(portClient1, s1.getClientPort());
            break;
        case 2:
            LOG.info("creating QuorumPeer 2 port {}", portClient2);
            s2 = new QuorumPeer(peers, s2dir, s2dir, portClient2, 3, 2, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
            assertEquals(portClient2, s2.getClientPort());
            break;
        case 3:
            LOG.info("creating QuorumPeer 3 port {}", portClient3);
            s3 = new QuorumPeer(peers, s3dir, s3dir, portClient3, 3, 3, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
            assertEquals(portClient3, s3.getClientPort());
            break;
        case 4:
            LOG.info("creating QuorumPeer 4 port {}", portClient4);
            s4 = new QuorumPeer(peers, s4dir, s4dir, portClient4, 3, 4, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
            assertEquals(portClient4, s4.getClientPort());
            break;
        case 5:
            LOG.info("creating QuorumPeer 5 port {}", portClient5);
            s5 = new QuorumPeer(peers, s5dir, s5dir, portClient5, 3, 5, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
            assertEquals(portClient5, s5.getClientPort());
    }
}
Also used : QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) InetSocketAddress(java.net.InetSocketAddress) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer)

Aggregations

QuorumServer (org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)59 InetSocketAddress (java.net.InetSocketAddress)30 Test (org.junit.jupiter.api.Test)22 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)17 HashMap (java.util.HashMap)13 IOException (java.io.IOException)9 File (java.io.File)8 ArrayList (java.util.ArrayList)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ServerSocket (java.net.ServerSocket)3 Socket (java.net.Socket)3 ByteBuffer (java.nio.ByteBuffer)3 Properties (java.util.Properties)3 KeeperException (org.apache.zookeeper.KeeperException)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 Vote (org.apache.zookeeper.server.quorum.Vote)3 QuorumVerifier (org.apache.zookeeper.server.quorum.flexible.QuorumVerifier)3 Test (org.junit.Test)3 EOFException (java.io.EOFException)2 DatagramPacket (java.net.DatagramPacket)2