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 #800: ZOOKEEPER-3268: Add commit processor metrics
Date Fri, 19 Apr 2019 15:51:05 GMT
jhuan31 commented on a change in pull request #800: ZOOKEEPER-3268: Add commit processor metrics
URL: https://github.com/apache/zookeeper/pull/800#discussion_r277021017
 
 

 ##########
 File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/CommitProcessorMetricsTest.java
 ##########
 @@ -0,0 +1,483 @@
+/**
+ * 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.zookeeper.ZKTestCase;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.Matchers.*;
+
+public class CommitProcessorMetricsTest extends ZKTestCase {
+    protected static final Logger LOG =
+            LoggerFactory.getLogger(CommitProcessorMetricsTest.class);
+    CommitProcessor commitProcessor;
+    DummyFinalProcessor finalProcessor;
+
+    CountDownLatch requestScheduled = null;
+    CountDownLatch requestSeen = null;
+    CountDownLatch commitSeen = null;
+    CountDownLatch poolEmpytied = null;
+
+    @Before
+    public void setup() {
+        LOG.info("setup");
+        ServerMetrics.resetAll();
+    }
+
+    public void setupProcessors(int commitWorkers, int finalProcTime ) {
+        finalProcessor = new DummyFinalProcessor(finalProcTime);
+        commitProcessor = new TestCommitProcessor(finalProcessor, commitWorkers);
+        commitProcessor.start();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        LOG.info("tearDown starting");
+
+        commitProcessor.shutdown();
+        commitProcessor.join();
+    }
+
+    private class TestCommitProcessor extends CommitProcessor {
+        int numWorkerThreads;
+
+        public TestCommitProcessor(RequestProcessor finalProcessor, int numWorkerThreads)
{
+            super(finalProcessor, "1", true, null);
+            this.numWorkerThreads = numWorkerThreads;
+        }
+
+        @Override
+        public void start() {
+            super.workerPool = new TestWorkerService(numWorkerThreads);
+            super.start();
+            // the sleep is needed to make sure that the thread is in the wait status
+            // and it won't start to process a request before the required countdown latch
+            // is set
 
 Review comment:
   Sorry about the confusing comments. What I meant is that I want to enforce the order of
things:
   processor thread gets into WAITING -> test thread sets requestProcessed latch ->
test thread puts a request into the queue (which wakes up the processor thread in the WAITING
state) and waits for the requestProcessed latch -> the processor thread wakes up and removes
the request from the queue and processes it and opens the requestProcessed latch -> the
test thread continues onto the next request
   
   If the processor thread is not in the WAITING state when the (first) request is put in
the queue, it would miss the wakeup signal and wouldn't process the request or open the latch
and the test thread waiting on the latch would be stuck.
   
   I've changed the code. It still uses a sleep, but in a loop, and the exit condition is
that the thread gets in WAITING. That should make the tests flaky-proof.

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