ndimiduk commented on a change in pull request #754: HBASE-22978 : Online slow 
response log
URL: https://github.com/apache/hbase/pull/754#discussion_r378443986
 
 

 ##########
 File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/slowlog/TestSlowLogRecorder.java
 ##########
 @@ -0,0 +1,266 @@
+/*
+ *
+ * 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.hadoop.hbase.regionserver.slowlog;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.testclassification.MasterTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import 
org.apache.hbase.thirdparty.com.google.common.util.concurrent.Uninterruptibles;
+
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog.SlowLogPayload;
+
+/**
+ * Tests for Online SlowLog Provider Service
+ */
+@Category({MasterTests.class, MediumTests.class})
+public class TestSlowLogRecorder {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestSlowLogRecorder.class);
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(TestSlowLogRecorder.class);
+
+  private static final HBaseTestingUtility HBASE_TESTING_UTILITY = new 
HBaseTestingUtility();
+
+  private SlowLogRecorder slowLogRecorder;
+
+  private static Configuration applySlowLogRecorderConf(int eventSize) {
+    Configuration conf = HBASE_TESTING_UTILITY.getConfiguration();
+    conf.setBoolean(HConstants.SLOW_LOG_BUFFER_ENABLED_KEY, true);
+    conf.setInt(HConstants.SLOW_LOG_RING_BUFFER_SIZE, eventSize);
+    return conf;
+  }
+
+  private SlowLogPayload getSlowLogPayload(int i) {
+    SlowLogPayload slowLogPayload = SlowLogPayload.newBuilder()
+      .setCallDetails("call_" + i)
+      .setClientAddress("client_" + i)
+      .setMethodName("method_" + i)
+      .setUserName("userName_" + i)
+      .setMultiGets(i)
+      .setMultiMutations(i)
+      .setMultiServiceCalls(i)
+      .setProcessingTime(i + 500)
+      .setQueueTime(i + 400)
+      .setResponseSize(i + 200)
+      .setStartTime(EnvironmentEdgeManager.currentTime())
+      .setServerClass("class_" + i)
+      .setParam("param_" + i)
+      .build();
+    return slowLogPayload;
+  }
+
+  /**
+   * confirm that for a ringbuffer of slow logs, payload on given index of 
buffer
+   * has expected elements
+   *
+   * @param i index of ringbuffer logs
+   * @param j data value that was put on index i
+   * @param slowLogPayloads list of payload retrieved from {@link 
SlowLogRecorder}
+   */
+  private void confirmPayloadParams(int i, int j, List<SlowLogPayload> 
slowLogPayloads) {
+    Assert.assertEquals(slowLogPayloads.get(i).getClientAddress(), "client_" + 
j);
+    Assert.assertEquals(slowLogPayloads.get(i).getCallDetails(), "call_" + j);
+    Assert.assertEquals(slowLogPayloads.get(i).getMethodName(), "method_" + j);
+    Assert.assertEquals(slowLogPayloads.get(i).getUserName(), "userName_" + j);
+    Assert.assertEquals(slowLogPayloads.get(i).getProcessingTime(), j + 500);
+    Assert.assertEquals(slowLogPayloads.get(i).getQueueTime(), j + 400);
+    Assert.assertEquals(slowLogPayloads.get(i).getResponseSize(), j + 200);
+    Assert.assertEquals(slowLogPayloads.get(i).getServerClass(), "class_" + j);
+    Assert.assertEquals(slowLogPayloads.get(i).getParam(), "param_" + j);
+  }
+
+  @Test
+  public void testOnlieSlowLogConsumption() throws Exception {
+    Configuration conf = applySlowLogRecorderConf(8);
+    slowLogRecorder = new SlowLogRecorder(conf);
+    Assert.assertEquals(slowLogRecorder.getSlowLogPayloads().size(), 0);
+    LOG.debug("Initially ringbuffer of Slow Log records is empty");
+
+    int i = 0;
+
+    // add 5 records initially
+    for (; i < 5; i++) {
+      SlowLogPayload slowLogPayload = getSlowLogPayload(i + 1);
+      slowLogRecorder.addSlowLogPayload(slowLogPayload);
+    }
+
+    HBASE_TESTING_UTILITY.waitFor(60000,
 
 Review comment:
   When using the `waitFor` helper, you should check whether the condition was 
true or the wait simply timed out. I like to wrap calls to this method in 
`assertNotEqual(-1, waitFor(...))`. See the javadoc of that method for an 
explanation.
   
   Same with the other invocations below.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to