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(((long)Integer.MAX_VALUE)*2, 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 @Test
62 public void testRegionLoadWrapAroundAggregation() {
63 ServerLoad sl = new ServerLoad(createServerLoadProto());
64 long totalCount = ((long)Integer.MAX_VALUE)*2;
65 assertEquals(totalCount, sl.getReadRequestsCount());
66 assertEquals(totalCount, sl.getWriteRequestsCount());
67 }
68
69 private ClusterStatusProtos.ServerLoad createServerLoadProto() {
70 HBaseProtos.RegionSpecifier rSpecOne =
71 HBaseProtos.RegionSpecifier.newBuilder()
72 .setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
73 .setValue(ByteString.copyFromUtf8("ASDFGQWERT")).build();
74 HBaseProtos.RegionSpecifier rSpecTwo =
75 HBaseProtos.RegionSpecifier.newBuilder()
76 .setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
77 .setValue(ByteString.copyFromUtf8("QWERTYUIOP")).build();
78
79 ClusterStatusProtos.RegionLoad rlOne =
80 ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecOne).setStores(10)
81 .setStorefiles(101).setStoreUncompressedSizeMB(106).setStorefileSizeMB(520)
82 .setStorefileIndexSizeMB(42).setRootIndexSizeKB(201).setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE).build();
83 ClusterStatusProtos.RegionLoad rlTwo =
84 ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecTwo).setStores(3)
85 .setStorefiles(13).setStoreUncompressedSizeMB(23).setStorefileSizeMB(300)
86 .setStorefileIndexSizeMB(40).setRootIndexSizeKB(303).setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE).build();
87
88 ClusterStatusProtos.ServerLoad sl =
89 ClusterStatusProtos.ServerLoad.newBuilder().addRegionLoads(rlOne).
90 addRegionLoads(rlTwo).build();
91 return sl;
92 }
93
94 }