zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] lvfangmin commented on a change in pull request #933: ZOOKEEPER-3379: De-flaky test in Quorum Packet Metrics
Date Fri, 10 May 2019 23:16:22 GMT
lvfangmin commented on a change in pull request #933: ZOOKEEPER-3379: De-flaky test in Quorum
Packet Metrics
URL: https://github.com/apache/zookeeper/pull/933#discussion_r283066904
 
 

 ##########
 File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerMetricsTest.java
 ##########
 @@ -60,36 +61,40 @@ public void setup() throws IOException {
 
         //adding 5ms artificial delay when sending each packet
         BinaryOutputArchive oa = mock(BinaryOutputArchive.class);
-        doAnswer(new Answer() {
-            @Override
-            public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
-                Thread.sleep(5);
-                return  null;
-            }
-        }).when(oa).writeRecord(any(QuorumPacket.class), Matchers.anyString());
+        doAnswer(invocationOnMock -> {Thread.sleep(5); return null;})
+                .when(oa).writeRecord(any(QuorumPacket.class), Matchers.anyString());
+
+        BufferedOutputStream bos = mock(BufferedOutputStream.class);
+        // flush is called when all packets are sent and the queue is empty
+        doAnswer(invocationOnMock -> {allSentLatch.countDown(); return null;}).when(bos).flush();
 
 Review comment:
   The allSentLatch needs to be initialized in setup, otherwise if the other test case in
this class, and it's not initialize this latch, it will throw NPE.
   
   Also if those test only used in testMetrics method, but not general, for other tests, then
we should move it into testMetrics instead of setup.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message