HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestRegionServerAccounting.java
blobbf4bca01ca2e3c06dd52243522d0603318cb9f11
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.regionserver;
20 import static org.junit.Assert.assertEquals;
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseConfiguration;
25 import org.apache.hadoop.hbase.io.util.MemorySizeUtil;
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;
32 @Category(SmallTests.class)
33 public class TestRegionServerAccounting {
35 @ClassRule
36 public static final HBaseClassTestRule CLASS_RULE =
37 HBaseClassTestRule.forClass(TestRegionServerAccounting.class);
39 private final static float DEFAULT_MEMSTORE_SIZE = 0.2f;
41 private static Configuration conf;
43 @Before
44 public void setUpConf() {
45 conf = HBaseConfiguration.create();
46 conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, DEFAULT_MEMSTORE_SIZE);
49 @Test
50 public void testOnheapMemstoreHigherWaterMarkLimits() {
51 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf);
52 long dataSize = regionServerAccounting.getGlobalMemStoreLimit();
53 MemStoreSize memstoreSize = new MemStoreSize(dataSize, dataSize, 0, 0);
54 regionServerAccounting.incGlobalMemStoreSize(memstoreSize);
55 assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, regionServerAccounting.isAboveHighWaterMark());
58 @Test
59 public void testOnheapMemstoreLowerWaterMarkLimits() {
60 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf);
61 long dataSize = regionServerAccounting.getGlobalMemStoreLimit();
62 MemStoreSize memstoreSize = new MemStoreSize(dataSize, dataSize, 0, 0);
63 regionServerAccounting.incGlobalMemStoreSize(memstoreSize);
64 assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark());
67 @Test
68 public void testOffheapMemstoreHigherWaterMarkLimitsDueToDataSize() {
69 // setting 1G as offheap data size
70 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L));
71 // try for default cases
72 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf);
73 // this will breach offheap limit as data size is higher and not due to heap size
74 MemStoreSize memstoreSize =
75 new MemStoreSize((3L * 1024L * 1024L * 1024L), 0, (1L * 1024L * 1024L * 1024L), 100);
76 regionServerAccounting.incGlobalMemStoreSize(memstoreSize);
77 assertEquals(FlushType.ABOVE_OFFHEAP_HIGHER_MARK,
78 regionServerAccounting.isAboveHighWaterMark());
81 @Test
82 public void testOffheapMemstoreHigherWaterMarkLimitsDueToHeapSize() {
83 // setting 1G as offheap data size
84 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L));
85 // try for default cases
86 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf);
87 // this will breach higher limit as heap size is higher and not due to offheap size
88 long dataSize = regionServerAccounting.getGlobalOnHeapMemStoreLimit();
89 MemStoreSize memstoreSize = new MemStoreSize(dataSize, dataSize, 0, 100);
90 regionServerAccounting.incGlobalMemStoreSize(memstoreSize);
91 assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, regionServerAccounting.isAboveHighWaterMark());
94 @Test
95 public void testOffheapMemstoreLowerWaterMarkLimitsDueToDataSize() {
96 // setting 1G as offheap data size
97 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L));
98 // try for default cases
99 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf);
100 // this will breach offheap limit as data size is higher and not due to heap size
101 MemStoreSize memstoreSize =
102 new MemStoreSize((3L * 1024L * 1024L * 1024L), 0, (1L * 1024L * 1024L * 1024L), 100);
103 regionServerAccounting.incGlobalMemStoreSize(memstoreSize);
104 assertEquals(FlushType.ABOVE_OFFHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark());
107 @Test
108 public void testOffheapMemstoreLowerWaterMarkLimitsDueToHeapSize() {
109 // setting 1G as offheap data size
110 conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L));
111 // try for default cases
112 RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf);
113 // this will breach higher limit as heap size is higher and not due to offheap size
114 long dataSize = regionServerAccounting.getGlobalOnHeapMemStoreLimit();
115 MemStoreSize memstoreSize = new MemStoreSize(dataSize, dataSize, 0, 100);
116 regionServerAccounting.incGlobalMemStoreSize(memstoreSize);
117 assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark());