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