|
| 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 |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 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. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.regionserver; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertTrue; |
| 22 | + |
| 23 | +import org.apache.hadoop.conf.Configuration; |
| 24 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 25 | +import org.apache.hadoop.hbase.testclassification.RegionServerTests; |
| 26 | +import org.apache.hadoop.hbase.testclassification.SmallTests; |
| 27 | +import org.junit.Before; |
| 28 | +import org.junit.ClassRule; |
| 29 | +import org.junit.Test; |
| 30 | +import org.junit.experimental.categories.Category; |
| 31 | + |
| 32 | +@Category({ RegionServerTests.class, SmallTests.class }) |
| 33 | +public class TestMetricsTableMetricsMap { |
| 34 | + |
| 35 | + @ClassRule |
| 36 | + public static final HBaseClassTestRule CLASS_RULE = |
| 37 | + HBaseClassTestRule.forClass(TestMetricsTableMetricsMap.class); |
| 38 | + |
| 39 | + private String tableName = "testTableMetricsMap"; |
| 40 | + |
| 41 | + private MetricsTableWrapperStub tableWrapper; |
| 42 | + private MetricsTable mt; |
| 43 | + private MetricsRegionServerWrapper rsWrapper; |
| 44 | + private MetricsRegionServer rsm; |
| 45 | + private MetricsTableAggregateSourceImpl agg; |
| 46 | + |
| 47 | + @Before |
| 48 | + public void setUp() { |
| 49 | + Configuration conf = new Configuration(); |
| 50 | + |
| 51 | + tableWrapper = new MetricsTableWrapperStub(tableName); |
| 52 | + mt = new MetricsTable(tableWrapper); |
| 53 | + rsWrapper = new MetricsRegionServerWrapperStub(); |
| 54 | + |
| 55 | + rsm = new MetricsRegionServer(rsWrapper, conf, mt); |
| 56 | + MetricsTableAggregateSource tableSourceAgg = mt.getTableSourceAgg(); |
| 57 | + if (tableSourceAgg instanceof MetricsTableAggregateSourceImpl) { |
| 58 | + agg = (MetricsTableAggregateSourceImpl) tableSourceAgg; |
| 59 | + } else { |
| 60 | + throw new RuntimeException( |
| 61 | + "tableSourceAgg should be the instance of MetricsTableAggregateSourceImpl"); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void testMetricsMap() throws InterruptedException { |
| 67 | + // do major compaction |
| 68 | + rsm.updateCompaction(tableName, true, 100, 200, 300, 400, 500); |
| 69 | + |
| 70 | + int metricsMapSize = agg.getMetricsRegistry().getMetricsMap().size(); |
| 71 | + assertTrue("table metrics added then metricsMapSize should larger than 0", metricsMapSize > 0); |
| 72 | + |
| 73 | + // just for metrics update |
| 74 | + Thread.sleep(1000); |
| 75 | + // delete table all metrics |
| 76 | + agg.deleteTableSource(tableName); |
| 77 | + |
| 78 | + metricsMapSize = agg.getMetricsRegistry().getMetricsMap().size(); |
| 79 | + assertEquals("table metrics all deleted then metricsSize should be 0", 0, metricsMapSize); |
| 80 | + } |
| 81 | +} |
0 commit comments