hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r802187 - in /hadoop/zookeeper/branches/branch-3.2: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
Date Fri, 07 Aug 2009 20:57:09 GMT
Author: mahadev
Date: Fri Aug  7 20:57:09 2009
New Revision: 802187

URL: http://svn.apache.org/viewvc?rev=802187&view=rev
Log:
ZOOKEEPER-501. CnxManagerTest failed on hudson. (flavio via mahadev)

Modified:
    hadoop/zookeeper/branches/branch-3.2/CHANGES.txt
    hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
    hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java

Modified: hadoop/zookeeper/branches/branch-3.2/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/CHANGES.txt?rev=802187&r1=802186&r2=802187&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/CHANGES.txt (original)
+++ hadoop/zookeeper/branches/branch-3.2/CHANGES.txt Fri Aug  7 20:57:09 2009
@@ -51,6 +51,8 @@
   ZOOKEEPER-490. the java docs for session creation are misleading/incomplete
   (phunt)
 
+  ZOOKEEPER-501. CnxManagerTest failed on hudson. (flavio via mahadev) 
+
 IMPROVEMENTS:
 
 NEW FEATURES:

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java?rev=802187&r1=802186&r2=802187&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
Fri Aug  7 20:57:09 2009
@@ -96,7 +96,7 @@
      */
     public Listener listener;
 
-    static class Message {
+    static public class Message {
         Message(ByteBuffer buffer, long sid) {
             this.buffer = buffer;
             this.sid = sid;
@@ -339,7 +339,7 @@
      * doesn't exist.
      */
     
-    void connectAll(){
+    public void connectAll(){
         long sid;
         for(Enumeration<Long> en = queueSendMap.keys();
             en.hasMoreElements();){

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java?rev=802187&r1=802186&r2=802187&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
Fri Aug  7 20:57:09 2009
@@ -26,12 +26,14 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
 
 import junit.framework.TestCase;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.server.quorum.FastLeaderElection;
 import org.apache.zookeeper.server.quorum.QuorumCnxManager;
+import org.apache.zookeeper.server.quorum.QuorumCnxManager.Message;
 import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.Vote;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
@@ -52,6 +54,7 @@
  */
 public class CnxManagerTest extends TestCase {
     protected static final Logger LOG = Logger.getLogger(FLENewEpochTest.class);
+    protected static final int THRESHOLD = 4;
     
     int baseport;
     int baseLEport;
@@ -102,7 +105,10 @@
     
     class CnxManagerThread extends Thread {
         
-        CnxManagerThread(){}
+        boolean failed;
+        CnxManagerThread(){
+            failed = false;
+        }
         
         public void run(){
             try {
@@ -117,10 +123,26 @@
                 
                 long sid = 1;
                 cnxManager.toSend(sid, createMsg(ServerState.LOOKING.ordinal(), 0, -1, 1));
-                cnxManager.recvQueue.take();
+                
+                Message m = null;
+                int numRetries = 1;
+                while((m == null) && (numRetries++ <= THRESHOLD)){
+                    m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
+                    if(m == null) cnxManager.connectAll();
+                }
+                
+                if(numRetries > THRESHOLD){
+                    failed = true;
+                    return;
+                }
+                
                 cnxManager.testInitiateConnection(sid);
             
-                cnxManager.recvQueue.take();
+                m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
+                if(m == null){
+                    failed = true;
+                    return;
+                }
             } catch (Exception e) {
                 LOG.error("Exception while running mock thread", e);
                 fail("Unexpected exception");
@@ -130,7 +152,7 @@
     
     @Test
     public void testCnxManager() throws Exception {
-        Thread thread = new CnxManagerThread();
+        CnxManagerThread thread = new CnxManagerThread();
         
         thread.start();
         
@@ -144,11 +166,22 @@
         }
             
         cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
-        cnxManager.recvQueue.take();
         
+        Message m = null;
+        int numRetries = 1;
+        while((m == null) && (numRetries++ <= THRESHOLD)){
+            m = cnxManager.recvQueue.poll(3000, TimeUnit.MILLISECONDS);
+            if(m == null) cnxManager.connectAll();
+        }
+        
+        assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
+
         thread.join(5000);
         if (thread.isAlive()) {
-            fail("Threads didn't join");
+            fail("Thread didn't join");
+        } else {
+            if(thread.failed)
+                fail("Did not receive expected message");
         }
     }
     



Mime
View raw message