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, 0); 046 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 047 assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, regionServerAccounting.isAboveHighWaterMark()); 048 } 049 050 @Test 051 public void testOnheapMemstoreLowerWaterMarkLimits() { 052 Configuration conf = HBaseConfiguration.create(); 053 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); 054 // try for default cases 055 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 056 MemStoreSize memstoreSize = 057 new MemStoreSize((3L * 1024L * 1024L * 1024L), (1L * 1024L * 1024L * 1024L), 0, 0); 058 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 059 assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark()); 060 } 061 062 @Test 063 public void testOffheapMemstoreHigherWaterMarkLimitsDueToDataSize() { 064 Configuration conf = HBaseConfiguration.create(); 065 // setting 1G as offheap data size 066 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 067 // try for default cases 068 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 069 // this will breach offheap limit as data size is higher and not due to heap size 070 MemStoreSize memstoreSize = 071 new MemStoreSize((3L * 1024L * 1024L * 1024L), 0, (1L * 1024L * 1024L * 1024L), 100); 072 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 073 assertEquals(FlushType.ABOVE_OFFHEAP_HIGHER_MARK, 074 regionServerAccounting.isAboveHighWaterMark()); 075 } 076 077 @Test 078 public void testOffheapMemstoreHigherWaterMarkLimitsDueToHeapSize() { 079 Configuration conf = HBaseConfiguration.create(); 080 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); 081 // setting 1G as offheap data size 082 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 083 // try for default cases 084 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 085 // this will breach higher limit as heap size is higher and not due to offheap size 086 MemStoreSize memstoreSize = 087 new MemStoreSize((3L * 1024L * 1024L), (2L * 1024L * 1024L * 1024L), 0, 0); 088 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 089 assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, regionServerAccounting.isAboveHighWaterMark()); 090 } 091 092 @Test 093 public void testOffheapMemstoreLowerWaterMarkLimitsDueToDataSize() { 094 Configuration conf = HBaseConfiguration.create(); 095 // setting 1G as offheap data size 096 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 097 // try for default cases 098 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 099 // this will breach offheap limit as data size is higher and not due to heap size 100 MemStoreSize memstoreSize = 101 new MemStoreSize((3L * 1024L * 1024L * 1024L), 0, (1L * 1024L * 1024L * 1024L), 100); 102 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 103 assertEquals(FlushType.ABOVE_OFFHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark()); 104 } 105 106 @Test 107 public void testOffheapMemstoreLowerWaterMarkLimitsDueToHeapSize() { 108 Configuration conf = HBaseConfiguration.create(); 109 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); 110 // setting 1G as offheap data size 111 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); 112 // try for default cases 113 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); 114 // this will breach higher limit as heap size is higher and not due to offheap size 115 MemStoreSize memstoreSize = 116 new MemStoreSize((3L * 1024L * 1024L), (2L * 1024L * 1024L * 1024L), 0, 0); 117 regionServerAccounting.incGlobalMemStoreSize(memstoreSize); 118 assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark()); 119 } 120}