1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase;
22
23 import static org.junit.Assert.*;
24
25 import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos;
26 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
27 import org.apache.hadoop.hbase.testclassification.MiscTests;
28 import org.apache.hadoop.hbase.testclassification.SmallTests;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32 import com.google.protobuf.ByteString;
33
34 @Category({MiscTests.class, SmallTests.class})
35 public class TestServerLoad {
36
37 @Test
38 public void testRegionLoadAggregation() {
39 ServerLoad sl = new ServerLoad(createServerLoadProto());
40 assertEquals(13, sl.getStores());
41 assertEquals(114, sl.getStorefiles());
42 assertEquals(129, sl.getStoreUncompressedSizeMB());
43 assertEquals(504, sl.getRootIndexSizeKB());
44 assertEquals(820, sl.getStorefileSizeInMB());
45 assertEquals(82, sl.getStorefileIndexSizeInMB());
46 assertEquals(((long)Integer.MAX_VALUE)*2, sl.getReadRequestsCount());
47
48 }
49
50 @Test
51 public void testToString() {
52 ServerLoad sl = new ServerLoad(createServerLoadProto());
53 String slToString = sl.toString();
54 assertTrue(slToString.contains("numberOfStores=13"));
55 assertTrue(slToString.contains("numberOfStorefiles=114"));
56 assertTrue(slToString.contains("storefileUncompressedSizeMB=129"));
57 assertTrue(slToString.contains("storefileSizeMB=820"));
58 assertTrue(slToString.contains("rootIndexSizeKB=504"));
59 assertTrue(slToString.contains("coprocessors=[]"));
60 }
61
62 @Test
63 public void testRegionLoadWrapAroundAggregation() {
64 ServerLoad sl = new ServerLoad(createServerLoadProto());
65 long totalCount = ((long)Integer.MAX_VALUE)*2;
66 assertEquals(totalCount, sl.getReadRequestsCount());
67 assertEquals(totalCount, sl.getWriteRequestsCount());
68 }
69
70 private ClusterStatusProtos.ServerLoad createServerLoadProto() {
71 HBaseProtos.RegionSpecifier rSpecOne =
72 HBaseProtos.RegionSpecifier.newBuilder()
73 .setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
74 .setValue(ByteString.copyFromUtf8("ASDFGQWERT")).build();
75 HBaseProtos.RegionSpecifier rSpecTwo =
76 HBaseProtos.RegionSpecifier.newBuilder()
77 .setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
78 .setValue(ByteString.copyFromUtf8("QWERTYUIOP")).build();
79
80 ClusterStatusProtos.RegionLoad rlOne =
81 ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecOne).setStores(10)
82 .setStorefiles(101).setStoreUncompressedSizeMB(106).setStorefileSizeMB(520)
83 .setStorefileIndexSizeMB(42).setRootIndexSizeKB(201).setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE).build();
84 ClusterStatusProtos.RegionLoad rlTwo =
85 ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecTwo).setStores(3)
86 .setStorefiles(13).setStoreUncompressedSizeMB(23).setStorefileSizeMB(300)
87 .setStorefileIndexSizeMB(40).setRootIndexSizeKB(303).setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE).build();
88
89 ClusterStatusProtos.ServerLoad sl =
90 ClusterStatusProtos.ServerLoad.newBuilder().addRegionLoads(rlOne).
91 addRegionLoads(rlTwo).build();
92 return sl;
93 }
94
95 }