HBASE-23723 Ensure MOB compaction works in optimized mode after snapshot clone (...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / util / TestJSONMetricUtil.java
blobdbf54bbe1fb32ae8a4480423e753c6db3d4daf31
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.util;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertNull;
24 import java.lang.management.GarbageCollectorMXBean;
25 import java.lang.management.ManagementFactory;
26 import java.util.Hashtable;
27 import java.util.List;
28 import java.util.Map;
29 import javax.management.MalformedObjectNameException;
30 import javax.management.ObjectName;
31 import javax.management.openmbean.CompositeData;
32 import org.apache.hadoop.hbase.HBaseClassTestRule;
33 import org.apache.hadoop.hbase.testclassification.MiscTests;
34 import org.apache.hadoop.hbase.testclassification.SmallTests;
35 import org.junit.ClassRule;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 @Category({ MiscTests.class, SmallTests.class })
42 public class TestJSONMetricUtil {
44 @ClassRule
45 public static final HBaseClassTestRule CLASS_RULE =
46 HBaseClassTestRule.forClass(TestJSONMetricUtil.class);
48 private static final Logger LOG = LoggerFactory.getLogger(TestJSONMetricUtil.class);
50 @Test
51 public void testBuildHashtable() {
52 String[] keys = { "type", "name" };
53 String[] emptyKey = {};
54 String[] values = { "MemoryPool", "Par Eden Space" };
55 String[] values2 = { "MemoryPool", "Par Eden Space", "Test" };
56 String[] emptyValue = {};
57 Map<String, String> properties = JSONMetricUtil.buldKeyValueTable(keys, values);
58 assertEquals(values[0], properties.get("type"));
59 assertEquals(values[1], properties.get("name"));
61 assertNull(JSONMetricUtil.buldKeyValueTable(keys, values2));
62 assertNull(JSONMetricUtil.buldKeyValueTable(keys, emptyValue));
63 assertNull(JSONMetricUtil.buldKeyValueTable(emptyKey, values2));
64 assertNull(JSONMetricUtil.buldKeyValueTable(emptyKey, emptyValue));
67 @Test
68 public void testBuildObjectName() throws MalformedObjectNameException {
69 String[] keys = { "type", "name" };
70 String[] values = { "MemoryPool", "Par Eden Space" };
71 Hashtable<String, String> properties = JSONMetricUtil.buldKeyValueTable(keys, values);
72 ObjectName testObject =
73 JSONMetricUtil.buildObjectName(JSONMetricUtil.JAVA_LANG_DOMAIN, properties);
74 assertEquals(JSONMetricUtil.JAVA_LANG_DOMAIN, testObject.getDomain());
75 assertEquals(testObject.getKeyPropertyList(), properties);
78 @Test
79 public void testGetLastGCInfo() {
80 List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
81 for (GarbageCollectorMXBean bean : gcBeans) {
82 ObjectName on = bean.getObjectName();
83 Object value = JSONMetricUtil.getValueFromMBean(on, "LastGcInfo");
84 LOG.info("Collector Info: " + value);
85 if (value != null && value instanceof CompositeData) {
86 CompositeData cds = (CompositeData) value;
87 assertNotNull(cds.get("duration"));