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.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  }