zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eribeiro <...@git.apache.org>
Subject [GitHub] zookeeper pull request #257: ZOOKEEPER-2784: Add same `sid` config problem c...
Date Fri, 19 May 2017 17:37:04 GMT
Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/257#discussion_r117527100
  
    --- Diff: src/java/test/org/apache/zookeeper/test/CnxManagerTest.java ---
    @@ -351,15 +351,55 @@ public void testSocketTimeout() throws Exception {
             LOG.info("Election port: " + port);
             Thread.sleep(1000);
     
    -        Socket sock = new Socket();
    -        sock.connect(peers.get(1L).electionAddr, 5000);
    -        long begin = Time.currentElapsedTime();
    -        // Read without sending data. Verify timeout.
    -        cnxManager.receiveConnection(sock);
    -        long end = Time.currentElapsedTime();
    -        if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited
more than necessary");
    -        cnxManager.halt();
    -        Assert.assertFalse(cnxManager.listener.isAlive());
    +        try (Socket sock = new Socket()) {
    +            sock.connect(peers.get(1L).electionAddr, 5000);
    +            long begin = Time.currentElapsedTime();
    +            // Read without sending data. Verify timeout.
    +            cnxManager.receiveConnection(sock);
    +            long end = Time.currentElapsedTime();
    +            if ((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500))
    +                Assert.fail("Waited more than necessary");
    +            cnxManager.halt();
    +            Assert.assertFalse(cnxManager.listener.isAlive());
    +        }
    +    }
    +
    +    /*
    +     * Test if a duplicate SID appears in the cluster
    +     */
    +    @Test
    +    public void testSameSID() throws Exception {
    +        QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[2], peerTmpdir[2], peerClientPort[2],
3, 2, 2000, 2, 2);
    +        QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
    +        QuorumCnxManager.Listener listener = cnxManager.listener;
    +        if (listener != null) {
    +            Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler()
{
    +                @Override
    +                public void uncaughtException(Thread th, Throwable ex) {
    +                    if (ex instanceof RuntimeException) {
    +                        String msg = ex.getMessage();
    +                        LOG.error(msg);
    +                        Assert.assertEquals("org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException:"
+
    +                                " Appearing duplicate SID: 2", msg);
    +                    }
    +                }
    +            };
    +            listener.setUncaughtExceptionHandler(handler);
    +            listener.start();
    +        } else {
    +            LOG.error("Null listener when initializing cnx manager");
    +        }
    +        try (Socket sock = new Socket()) {
    +            InetSocketAddress electionAddr = peers.get(peer.getId()).electionAddr;
    +            LOG.info("Creating socket connection, host: {}, port: {}",
    +                    electionAddr.getHostString(), electionAddr.getPort());
    +            sock.connect(electionAddr, 30000);
    --- End diff --
    
    The timeout here is way to big (30000 ms) with relation to the other tests (5000 ms).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message