zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] jhuan31 commented on a change in pull request #849: ZOOKEEPER-3305: Add Quorum Packet metrics
Date Tue, 07 May 2019 22:29:10 GMT
jhuan31 commented on a change in pull request #849: ZOOKEEPER-3305: Add Quorum Packet metrics
URL: https://github.com/apache/zookeeper/pull/849#discussion_r281853779
 
 

 ##########
 File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerMetricsTest.java
 ##########
 @@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.server.quorum;
+
+import org.apache.jute.BinaryOutputArchive;
+import org.apache.zookeeper.metrics.MetricsUtils;
+import org.apache.zookeeper.server.ServerMetrics;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.Map;
+
+import static org.hamcrest.number.OrderingComparison.greaterThan;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class LearnerHandlerMetricsTest {
+    private MockLearnerHandler learnerHandler;
+    private long sid = 5;
+
+    class MockLearnerHandler extends LearnerHandler {
+        MockLearnerHandler(Socket socket, Leader leader) throws IOException {
+            super(socket, null, leader);
+        }
+    }
+
+    @Before
+    public void setup() throws IOException {
+        Leader leader = mock(Leader.class);
+        when(leader.getQuorumAuthServer()).thenReturn(null);
+
+        Socket socket = mock(Socket.class);
+        when(socket.getRemoteSocketAddress()).thenReturn(new InetSocketAddress(32));
+
+        //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());
+
+        learnerHandler = new MockLearnerHandler(socket, leader);
+        learnerHandler.setOutputArchive(oa);
+        learnerHandler.setBufferedOutput(mock(BufferedOutputStream.class));
+        learnerHandler.sid = sid;
+    }
+
+    @Test
+    public void testMetrics() {
+        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());
+        }
+        learnerHandler.startSendingPackets();
+
+        //make sure we have enough time to send all the packets in the queue
+        try {
+            Thread.sleep(8000);
 
 Review comment:
   Thanks Andor! Please see PR #933 for the fix, in which a latch is used instead of sleep.

----------------------------------------------------------------
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