eolivelli 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_r281917462
##########
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();
learnerHandler = new MockLearnerHandler(socket, leader);
learnerHandler.setOutputArchive(oa);
- learnerHandler.setBufferedOutput(mock(BufferedOutputStream.class));
+ learnerHandler.setBufferedOutput(bos);
learnerHandler.sid = sid;
}
@Test
- public void testMetrics() {
+ public void testMetrics() throws InterruptedException {
ServerMetrics.getMetrics().resetAll();
//adding 1001 packets in the queue, two marker packets will be added
since the interval is every 1000 packets
for (int i=0; i<1001; i++) {
learnerHandler.queuePacket(new QuorumPacket());
}
+
+ allSentLatch = new CountDownLatch(1);
+
learnerHandler.startSendingPackets();
+ allSentLatch.await(8, TimeUnit.SECONDS);
+
//make sure we have enough time to send all the packets in the queue
- try {
+ /*try {
Review comment:
Can we remove commented code?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services