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.Assert.assertEquals; 021 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.HBaseConfiguration; 025import org.apache.hadoop.hbase.io.util.MemorySizeUtil; 026import org.apache.hadoop.hbase.testclassification.SmallTests; 027import org.junit.ClassRule; 028import org.junit.Test; 029import org.junit.experimental.categories.Category; 030 031@Category(SmallTests.class) 032public class TestRegionServerAccounting { 033 034 @ClassRule 035 public static final HBaseClassTestRule CLASS_RULE = 036 HBaseClassTestRule.forClass(TestRegionServerAccounting.class); 037 038 @Test 039 public void testOnheapMemstoreHigherWaterMarkLimits() { 040 Configuration conf = HBaseConfiguration.create(); 041 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); 042 // try for default cases 043 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 044 MemStoreSize memstoreSize = 045 new MemStoreSize((3L * 1024L * 1024L * 1024L), (1L * 1024L * 1024L * 1024L), 0); 046 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 047 assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, 048 regionServerAccounting.isAboveHighWaterMark()); 049 } 050 051 @Test 052 public void testOnheapMemstoreLowerWaterMarkLimits() { 053 Configuration conf = HBaseConfiguration.create(); 054 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); 055 // try for default cases 056 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 057 MemStoreSize memstoreSize = 058 new MemStoreSize((3L * 1024L * 1024L * 1024L), (1L * 1024L * 1024L * 1024L), 0); 059 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 060 assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, 061 regionServerAccounting.isAboveLowWaterMark()); 062 } 063 064 @Test 065 public void testOffheapMemstoreHigherWaterMarkLimitsDueToDataSize() { 066 Configuration conf = HBaseConfiguration.create(); 067 // setting 1G as offheap data size 068 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 069 // try for default cases 070 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 071 // this will breach offheap limit as data size is higher and not due to heap size 072 MemStoreSize memstoreSize = 073 new MemStoreSize((3L * 1024L * 1024L * 1024L), 0, (1L * 1024L * 1024L * 1024L)); 074 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 075 assertEquals(FlushType.ABOVE_OFFHEAP_HIGHER_MARK, 076 regionServerAccounting.isAboveHighWaterMark()); 077 } 078 079 @Test 080 public void testOffheapMemstoreHigherWaterMarkLimitsDueToHeapSize() { 081 Configuration conf = HBaseConfiguration.create(); 082 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); 083 // setting 1G as offheap data size 084 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 085 // try for default cases 086 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 087 // this will breach higher limit as heap size is higher and not due to offheap size 088 MemStoreSize memstoreSize = 089 new MemStoreSize((3L * 1024L * 1024L), (2L * 1024L * 1024L * 1024L), 0); 090 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 091 assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, 092 regionServerAccounting.isAboveHighWaterMark()); 093 } 094 095 @Test 096 public void testOffheapMemstoreLowerWaterMarkLimitsDueToDataSize() { 097 Configuration conf = HBaseConfiguration.create(); 098 // setting 1G as offheap data size 099 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 100 // try for default cases 101 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 102 // this will breach offheap limit as data size is higher and not due to heap size 103 MemStoreSize memstoreSize = 104 new MemStoreSize((3L * 1024L * 1024L * 1024L), 0, (1L * 1024L * 1024L * 1024L)); 105 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 106 assertEquals(FlushType.ABOVE_OFFHEAP_LOWER_MARK, 107 regionServerAccounting.isAboveLowWaterMark()); 108 } 109 110 @Test 111 public void testOffheapMemstoreLowerWaterMarkLimitsDueToHeapSize() { 112 Configuration conf = HBaseConfiguration.create(); 113 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); 114 // setting 1G as offheap data size 115 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 116 // try for default cases 117 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 118 // this will breach higher limit as heap size is higher and not due to offheap size 119 MemStoreSize memstoreSize = 120 new MemStoreSize((3L * 1024L * 1024L), (2L * 1024L * 1024L * 1024L), 0); 121 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 122 assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, 123 regionServerAccounting.isAboveLowWaterMark()); 124 } 125}