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.SmallTests;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 import com.google.protobuf.ByteString;
32
33 @Category(SmallTests.class)
34 public class TestServerLoad {
35
36 @Test
37 public void testRegionLoadAggregation() {
38 ServerLoad sl = new ServerLoad(createServerLoadProto());
39 assertEquals(13, sl.getStores());
40 assertEquals(114, sl.getStorefiles());
41 assertEquals(129, sl.getStoreUncompressedSizeMB());
42 assertEquals(504, sl.getRootIndexSizeKB());
43 assertEquals(820, sl.getStorefileSizeInMB());
44 assertEquals(82, sl.getStorefileIndexSizeInMB());
45 assertEquals(0, sl.getReadRequestsCount());
46
47 }
48
49 @Test
50 public void testToString() {
51 ServerLoad sl = new ServerLoad(createServerLoadProto());
52 String slToString = sl.toString();
53 assertTrue(slToString.contains("numberOfStores=13"));
54 assertTrue(slToString.contains("numberOfStorefiles=114"));
55 assertTrue(slToString.contains("storefileUncompressedSizeMB=129"));
56 assertTrue(slToString.contains("storefileSizeMB=820"));
57 assertTrue(slToString.contains("rootIndexSizeKB=504"));
58 assertTrue(slToString.contains("coprocessors=[]"));
59 }
60
61 private ClusterStatusProtos.ServerLoad createServerLoadProto() {
62 HBaseProtos.RegionSpecifier rSpecOne =
63 HBaseProtos.RegionSpecifier.newBuilder()
64 .setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
65 .setValue(ByteString.copyFromUtf8("ASDFGQWERT")).build();
66 HBaseProtos.RegionSpecifier rSpecTwo =
67 HBaseProtos.RegionSpecifier.newBuilder()
68 .setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
69 .setValue(ByteString.copyFromUtf8("QWERTYUIOP")).build();
70
71 ClusterStatusProtos.RegionLoad rlOne =
72 ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecOne).setStores(10)
73 .setStorefiles(101).setStoreUncompressedSizeMB(106).setStorefileSizeMB(520)
74 .setStorefileIndexSizeMB(42).setRootIndexSizeKB(201).build();
75 ClusterStatusProtos.RegionLoad rlTwo =
76 ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecTwo).setStores(3)
77 .setStorefiles(13).setStoreUncompressedSizeMB(23).setStorefileSizeMB(300)
78 .setStorefileIndexSizeMB(40).setRootIndexSizeKB(303).build();
79
80 ClusterStatusProtos.ServerLoad sl =
81 ClusterStatusProtos.ServerLoad.newBuilder().addRegionLoads(rlOne).
82 addRegionLoads(rlTwo).build();
83 return sl;
84 }
85
86 }