abstractdog commented on code in PR #5557:
URL: https://github.com/apache/hive/pull/5557#discussion_r1870855491


##########
llap-common/src/test/org/apache/hadoop/hive/llap/TestLlapThreadLocalStatistics.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.hive.llap;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.hadoop.fs.FileSystem;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.lang.management.ThreadMXBean;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public class TestLlapThreadLocalStatistics {
+
+  private static final ThreadMXBean mxBean = LlapUtil.initThreadMxBean();
+
+  @Test
+  public void testEmptyStatistics() {
+    LlapThreadLocalStatistics before = new LlapThreadLocalStatistics(mxBean, 
new ArrayList<>());
+    LlapThreadLocalStatistics after = new LlapThreadLocalStatistics(mxBean, 
new ArrayList<>());
+    Assert.assertEquals(0, 
after.subtract(before).schemeToThreadLocalStats.keySet().size());
+  }
+
+  @Test
+  public void testCpuTimeUserTime() throws Exception {
+    LlapThreadLocalStatistics before = new LlapThreadLocalStatistics(mxBean, 
new ArrayList<>());
+    Assert.assertTrue("cpuTime should be >0", before.cpuTime > 0);
+    Assert.assertTrue("userTime should be >0", before.userTime > 0);
+
+    Thread.sleep(100);
+
+    LlapThreadLocalStatistics after = new LlapThreadLocalStatistics(mxBean, 
new ArrayList<>());
+    Assert.assertTrue("cpuTime should increase", after.cpuTime > 
before.cpuTime);
+    // userTime assertion is flaky, not checked here
+  }
+
+  @Test
+  public void testCountersMergedForTheSameScheme() {
+    LlapThreadLocalStatistics stats = new LlapThreadLocalStatistics(mxBean,
+        createMockStatistics(new String[]{"file", "hdfs", "hdfs"}, new 
Integer[]{1, 1, 1}));

Review Comment:
   I don't think so, I cannot recall if we refactor file system schemes to 
constants in tests, IMO it just leads to more 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.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to