From d6d209564cc415d63b81613a284725af0409a7e7 Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Mon, 7 May 2018 17:48:15 +0800 Subject: [PATCH] HBASE-20536 Make TestRegionServerAccounting stable and it should not use absolute number --- .../TestRegionServerAccounting.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java index 7bd9e163a0f..fb246d5562a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java @@ -24,6 +24,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.io.util.MemorySizeUtil; import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -35,14 +36,22 @@ public class TestRegionServerAccounting { public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestRegionServerAccounting.class); + private final static float DEFAULT_MEMSTORE_SIZE = 0.2f; + + private static Configuration conf; + + @Before + public void setUpConf() { + conf = HBaseConfiguration.create(); + conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, DEFAULT_MEMSTORE_SIZE); + } + @Test public void testOnheapMemstoreHigherWaterMarkLimits() { - Configuration conf = HBaseConfiguration.create(); - conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); - // try for default cases RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); + long dataSize = regionServerAccounting.getGlobalMemStoreLimit(); MemStoreSize memstoreSize = - new MemStoreSize((3L * 1024L * 1024L * 1024L), (1L * 1024L * 1024L * 1024L), 0); + new MemStoreSize(dataSize, dataSize, 0); regionServerAccounting.incGlobalMemStoreSize(memstoreSize); assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, regionServerAccounting.isAboveHighWaterMark()); @@ -50,12 +59,10 @@ public class TestRegionServerAccounting { @Test public void testOnheapMemstoreLowerWaterMarkLimits() { - Configuration conf = HBaseConfiguration.create(); - conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); - // try for default cases RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); + long dataSize = regionServerAccounting.getGlobalMemStoreLimit(); MemStoreSize memstoreSize = - new MemStoreSize((3L * 1024L * 1024L * 1024L), (1L * 1024L * 1024L * 1024L), 0); + new MemStoreSize(dataSize, dataSize, 0); regionServerAccounting.incGlobalMemStoreSize(memstoreSize); assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark()); @@ -63,7 +70,6 @@ public class TestRegionServerAccounting { @Test public void testOffheapMemstoreHigherWaterMarkLimitsDueToDataSize() { - Configuration conf = HBaseConfiguration.create(); // setting 1G as offheap data size conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); // try for default cases @@ -78,15 +84,14 @@ public class TestRegionServerAccounting { @Test public void testOffheapMemstoreHigherWaterMarkLimitsDueToHeapSize() { - Configuration conf = HBaseConfiguration.create(); - conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); // setting 1G as offheap data size conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); // try for default cases RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); // this will breach higher limit as heap size is higher and not due to offheap size + long dataSize = regionServerAccounting.getGlobalOnHeapMemStoreLimit(); MemStoreSize memstoreSize = - new MemStoreSize((3L * 1024L * 1024L), (2L * 1024L * 1024L * 1024L), 0); + new MemStoreSize(dataSize, dataSize, 0); regionServerAccounting.incGlobalMemStoreSize(memstoreSize); assertEquals(FlushType.ABOVE_ONHEAP_HIGHER_MARK, regionServerAccounting.isAboveHighWaterMark()); @@ -94,7 +99,6 @@ public class TestRegionServerAccounting { @Test public void testOffheapMemstoreLowerWaterMarkLimitsDueToDataSize() { - Configuration conf = HBaseConfiguration.create(); // setting 1G as offheap data size conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); // try for default cases @@ -109,15 +113,14 @@ public class TestRegionServerAccounting { @Test public void testOffheapMemstoreLowerWaterMarkLimitsDueToHeapSize() { - Configuration conf = HBaseConfiguration.create(); - conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, 0.2f); // setting 1G as offheap data size conf.setLong(MemorySizeUtil.OFFHEAP_MEMSTORE_SIZE_KEY, (1L * 1024L)); // try for default cases RegionServerAccounting regionServerAccounting = new RegionServerAccounting(conf); // this will breach higher limit as heap size is higher and not due to offheap size + long dataSize = regionServerAccounting.getGlobalOnHeapMemStoreLimit(); MemStoreSize memstoreSize = - new MemStoreSize((3L * 1024L * 1024L), (2L * 1024L * 1024L * 1024L), 0); + new MemStoreSize(dataSize, dataSize, 0); regionServerAccounting.incGlobalMemStoreSize(memstoreSize); assertEquals(FlushType.ABOVE_ONHEAP_LOWER_MARK, regionServerAccounting.isAboveLowWaterMark());