View Javadoc

1   /**
2    * Copyright The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
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  }