@@ -61,19 +61,22 @@ public void testSimpleTestCase() throws Exception {
6161
6262 RegionLocator regionLocator = mockRegionLocator ("region1" , "region2" , "region3" );
6363
64- Admin admin = mockAdmin (mockRegion ("region1" , 123 ), mockRegion ("region3" , 1232 ),
65- mockRegion ("region2" , 54321 ));
64+ Admin admin = mockAdmin (mockRegion ("region1" , 123 , 321 ), mockRegion ("region3" , 1232 , 2321 ),
65+ mockRegion ("region2" , 54321 , 12345 ), mockRegion ("region4" , 6789 , 0 ),
66+ mockRegion ("region5" , 0 , 4567 ));
6667
6768 RegionSizeCalculator calculator = new RegionSizeCalculator (regionLocator , admin );
6869
69- assertEquals (123 * megabyte , calculator .getRegionSize (Bytes .toBytes ("region1" )));
70- assertEquals (54321 * megabyte , calculator .getRegionSize (Bytes .toBytes ("region2" )));
71- assertEquals (1232 * megabyte , calculator .getRegionSize (Bytes .toBytes ("region3" )));
70+ assertEquals ((123 + 321 ) * megabyte , calculator .getRegionSize (Bytes .toBytes ("region1" )));
71+ assertEquals ((54321 + 12345 ) * megabyte , calculator .getRegionSize (Bytes .toBytes ("region2" )));
72+ assertEquals ((1232 + 2321 ) * megabyte , calculator .getRegionSize (Bytes .toBytes ("region3" )));
73+ assertEquals (6789 * megabyte , calculator .getRegionSize (Bytes .toBytes ("region4" )));
74+ assertEquals (4567 * megabyte , calculator .getRegionSize (Bytes .toBytes ("region5" )));
7275
7376 // if regionCalculator does not know about a region, it should return 0
7477 assertEquals (0 , calculator .getRegionSize (Bytes .toBytes ("otherTableRegion" )));
7578
76- assertEquals (3 , calculator .getRegionSizeMap ().size ());
79+ assertEquals (5 , calculator .getRegionSizeMap ().size ());
7780 }
7881
7982 /**
@@ -85,12 +88,12 @@ public void testLargeRegion() throws Exception {
8588
8689 RegionLocator regionLocator = mockRegionLocator ("largeRegion" );
8790
88- Admin admin = mockAdmin (mockRegion ("largeRegion" , Integer .MAX_VALUE ));
91+ Admin admin = mockAdmin (mockRegion ("largeRegion" , Integer .MAX_VALUE , Integer . MAX_VALUE ));
8992
9093 RegionSizeCalculator calculator = new RegionSizeCalculator (regionLocator , admin );
9194
92- assertEquals (((long ) Integer .MAX_VALUE ) * megabyte ,
93- calculator .getRegionSize ("largeRegion" . getBytes ( )));
95+ assertEquals (((long ) Integer .MAX_VALUE ) * 2L * megabyte ,
96+ calculator .getRegionSize (Bytes . toBytes ( "largeRegion" )));
9497 }
9598
9699 /** When calculator is disabled, it should return 0 for each request. */
@@ -99,11 +102,11 @@ public void testDisabled() throws Exception {
99102 String regionName = "cz.goout:/index.html" ;
100103 RegionLocator table = mockRegionLocator (regionName );
101104
102- Admin admin = mockAdmin (mockRegion (regionName , 999 ));
105+ Admin admin = mockAdmin (mockRegion (regionName , 999 , 888 ));
103106
104107 // first request on enabled calculator
105108 RegionSizeCalculator calculator = new RegionSizeCalculator (table , admin );
106- assertEquals (999 * megabyte , calculator .getRegionSize (regionName . getBytes ( )));
109+ assertEquals (( 999 + 888 ) * megabyte , calculator .getRegionSize (Bytes . toBytes ( regionName )));
107110
108111 // then disabled calculator.
109112 configuration .setBoolean (RegionSizeCalculator .ENABLE_REGIONSIZECALCULATOR , false );
@@ -116,7 +119,7 @@ public void testDisabled() throws Exception {
116119 public void testRegionWithNullServerName () throws Exception {
117120 RegionLocator regionLocator =
118121 mockRegionLocator (null , Collections .singletonList ("someBigRegion" ));
119- Admin admin = mockAdmin (mockRegion ("someBigRegion" , Integer .MAX_VALUE ));
122+ Admin admin = mockAdmin (mockRegion ("someBigRegion" , Integer .MAX_VALUE , Integer . MAX_VALUE ));
120123 RegionSizeCalculator calculator = new RegionSizeCalculator (regionLocator , admin );
121124 assertEquals (0 , calculator .getRegionSize (Bytes .toBytes ("someBigRegion" )));
122125 }
@@ -158,13 +161,15 @@ private Admin mockAdmin(RegionMetrics... regionLoadArray) throws Exception {
158161
159162 /**
160163 * Creates mock of region with given name and size.
161- * @param fileSizeMb number of megabytes occupied by region in file store in megabytes
164+ * @param fileSizeMb number of megabytes occupied by region in file store in megabytes
165+ * @param memStoreSize number of megabytes occupied by region in memstore in megabytes
162166 */
163- private RegionMetrics mockRegion (String regionName , int fileSizeMb ) {
167+ private RegionMetrics mockRegion (String regionName , int fileSizeMb , int memStoreSize ) {
164168 RegionMetrics region = Mockito .mock (RegionMetrics .class );
165169 when (region .getRegionName ()).thenReturn (regionName .getBytes ());
166170 when (region .getNameAsString ()).thenReturn (regionName );
167171 when (region .getStoreFileSize ()).thenReturn (new Size (fileSizeMb , Size .Unit .MEGABYTE ));
172+ when (region .getMemStoreSize ()).thenReturn (new Size (memStoreSize , Size .Unit .MEGABYTE ));
168173 return region ;
169174 }
170175}
0 commit comments