eolivelli commented on a change in pull request #850: ZOOKEEPER-3309: Add sync 
processor metrics
URL: https://github.com/apache/zookeeper/pull/850#discussion_r264893822
 
 

 ##########
 File path: 
zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/SyncRequestProcessorMetricTest.java
 ##########
 @@ -0,0 +1,82 @@
+package org.apache.zookeeper.server.quorum;
+
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.server.*;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+
+import static org.hamcrest.number.OrderingComparison.greaterThan;
+import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
+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 SyncRequestProcessorMetricTest {
+    ZooKeeperServer zks;
+
+
+    @Before
+    public void setup() throws Exception {
+        ZKDatabase db = mock(ZKDatabase.class);
+        when(db.append(any(Request.class))).thenReturn(true);
+        doAnswer(invocation->{
+            Thread.sleep(100);
+            return null;
+        }).when(db).commit();
+        zks = mock(ZooKeeperServer.class);
+        when(zks.getZKDatabase()).thenReturn(db);
+    }
+
+    @After
+    public void tearDown() {
+
+    }
+
+    private Request createRquest(long sessionId, int xid) {
+        return new Request(null, sessionId, xid, ZooDefs.OpCode.setData,
+                ByteBuffer.wrap(new byte[10]), null);
+    }
+
+    @Test
+    public void testSyncProcessorMetrics() {
+        SyncRequestProcessor syncProcessor = new SyncRequestProcessor(zks, 
null);
+        for (int i=0; i<500; i++) {
+            syncProcessor.processRequest(createRquest(1, i));
+        }
+
+        Map<String, Object> values = ServerMetrics.getAllValues();
+        Assert.assertEquals(500L, values.get("sync_processor_request_queued"));
+
+        syncProcessor.start();
+
+        try {
+            Thread.sleep(500);
+        } catch (Exception e){
 
 Review comment:
   Why?
   If you get an IE the test will fail, not a big deal

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

Reply via email to