001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import static org.junit.jupiter.api.Assertions.assertNotNull; 021 022import org.apache.hadoop.hbase.CompatibilitySingletonFactory; 023import org.apache.hadoop.hbase.test.MetricsAssertHelper; 024import org.apache.hadoop.hbase.testclassification.RegionServerTests; 025import org.apache.hadoop.hbase.testclassification.SmallTests; 026import org.junit.jupiter.api.BeforeEach; 027import org.junit.jupiter.api.Tag; 028import org.junit.jupiter.api.Test; 029 030/** 031 * Unit test version of rs metrics tests. 032 */ 033@Tag(RegionServerTests.TAG) 034@Tag(SmallTests.TAG) 035public class TestMetricsHeapMemoryManager { 036 037 public static MetricsAssertHelper HELPER = 038 CompatibilitySingletonFactory.getInstance(MetricsAssertHelper.class); 039 040 private MetricsHeapMemoryManager hmm; 041 private MetricsHeapMemoryManagerSource source; 042 043 @BeforeEach 044 public void setUp() { 045 hmm = new MetricsHeapMemoryManager(); 046 source = hmm.getMetricsSource(); 047 } 048 049 @Test 050 public void testConstuctor() { 051 assertNotNull(source, "There should be a hadoop1/hadoop2 metrics source"); 052 } 053 054 @Test 055 public void testCounter() { 056 for (int i = 0; i < 10; i++) { 057 hmm.increaseAboveHeapOccupancyLowWatermarkCounter(); 058 } 059 for (int i = 0; i < 11; i++) { 060 hmm.increaseTunerDoNothingCounter(); 061 } 062 063 HELPER.assertCounter("aboveHeapOccupancyLowWaterMarkCounter", 10L, source); 064 HELPER.assertCounter("tunerDoNothingCounter", 11L, source); 065 } 066 067 @Test 068 public void testGauge() { 069 hmm.updateBlockedFlushCount(200); 070 hmm.updateUnblockedFlushCount(50); 071 hmm.setCurMemStoreSizeGauge(256 * 1024 * 1024); 072 hmm.setCurMemStoreOnHeapSizeGauge(512 * 1024 * 1024); 073 hmm.setCurMemStoreOffHeapSizeGauge(128 * 1024 * 1024); 074 hmm.setCurBlockCacheSizeGauge(100 * 1024 * 1024); 075 076 HELPER.assertGauge("blockedFlushGauge", 200, source); 077 HELPER.assertGauge("unblockedFlushGauge", 50, source); 078 HELPER.assertGauge("memStoreSize", 256 * 1024 * 1024, source); 079 HELPER.assertGauge("memStoreOnHeapSize", 512 * 1024 * 1024, source); 080 HELPER.assertGauge("memStoreOffHeapSize", 128 * 1024 * 1024, source); 081 HELPER.assertGauge("blockCacheSize", 100 * 1024 * 1024, source); 082 } 083}