Kaynağa Gözat

ZOOKEEPER-1904. WatcherTest#testWatchAutoResetWithPending is failing (Rakesh R via michim)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1582055 13f79535-47bb-0310-9956-ffa450edef68
Michi Mutsuzaki 11 yıl önce
ebeveyn
işleme
183a0c8e52

+ 3 - 0
CHANGES.txt

@@ -585,6 +585,9 @@ BUGFIXES:
   ZOOKEEPER-1263. fix handling of min/max session timeout value initialization
   (Rakesh R via michim)
 
+  ZOOKEEPER-1904. WatcherTest#testWatchAutoResetWithPending is failing
+  (Rakesh R via michim)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

+ 14 - 1
src/java/test/org/apache/zookeeper/TestableZooKeeper.java

@@ -21,6 +21,8 @@ package org.apache.zookeeper;
 import java.io.IOException;
 import java.net.SocketAddress;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.jute.Record;
 import org.apache.zookeeper.proto.ReplyHeader;
@@ -64,8 +66,10 @@ public class TestableZooKeeper extends ZooKeeper {
      * Cause this ZooKeeper object to stop receiving from the ZooKeeperServer
      * for the given number of milliseconds.
      * @param ms the number of milliseconds to pause.
+     * @return true if the connection is paused, otherwise false
      */
-    public void pauseCnxn(final long ms) {
+    public boolean pauseCnxn(final long ms) {
+        final CountDownLatch initiatedPause = new CountDownLatch(1);
         new Thread() {
             public void run() {
                 synchronized(cnxn) {
@@ -74,6 +78,8 @@ public class TestableZooKeeper extends ZooKeeper {
                             cnxn.sendThread.testableCloseSocket();
                         } catch (IOException e) {
                             e.printStackTrace();
+                        } finally {
+                            initiatedPause.countDown();
                         }
                         Thread.sleep(ms);
                     } catch (InterruptedException e) {
@@ -81,6 +87,13 @@ public class TestableZooKeeper extends ZooKeeper {
                 }
             }
         }.start();
+
+        try {
+            return initiatedPause.await(ms, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            return false;
+        }
     }
     
     public boolean testableWaitForShutdown(int wait)

+ 1 - 2
src/java/test/org/apache/zookeeper/test/WatcherTest.java

@@ -194,8 +194,7 @@ public class WatcherTest extends ClientBase {
            zk.exists("/test", watches[i], cbs[i], count);
        }
        zk.exists("/test", false);
-       zk.pauseCnxn(3000);
-       Thread.sleep(50);
+       Assert.assertTrue("Failed to pause the connection!", zk.pauseCnxn(3000));
        zk2.close();
        stopServer();
        watches[0].waitForDisconnected(60000);