View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
25  
26  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertTrue;
31  
32  public class TestMetricsRegionSourceImpl {
33  
34    @Test
35    public void testCompareTo() throws Exception {
36      MetricsRegionServerSourceFactory fact = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
37  
38      MetricsRegionSource one = fact.createRegion(new RegionWrapperStub("TEST"));
39      MetricsRegionSource oneClone = fact.createRegion(new RegionWrapperStub("TEST"));
40      MetricsRegionSource two = fact.createRegion(new RegionWrapperStub("TWO"));
41  
42      assertEquals(0, one.compareTo(oneClone));
43  
44      assertTrue( one.compareTo(two) < 0);
45      assertTrue( two.compareTo(one) > 0);
46    }
47  
48  
49    @Test(expected = RuntimeException.class)
50    public void testNoGetRegionServerMetricsSourceImpl() throws Exception {
51      // This should throw an exception because MetricsRegionSourceImpl should only
52      // be created by a factory.
53      CompatibilitySingletonFactory.getInstance(MetricsRegionSource.class);
54    }
55  
56    static class RegionWrapperStub implements MetricsRegionWrapper {
57  
58      private String regionName;
59  
60      public RegionWrapperStub(String regionName) {
61  
62  
63        this.regionName = regionName;
64      }
65  
66      @Override
67      public String getTableName() {
68        return null;
69      }
70  
71      @Override
72      public String getNamespace() {
73        return null;
74      }
75  
76      @Override
77      public String getRegionName() {
78        return this.regionName;
79      }
80  
81      @Override
82      public long getNumStores() {
83        return 0;
84      }
85  
86      @Override
87      public long getNumStoreFiles() {
88        return 0;
89      }
90  
91      @Override
92      public long getMemstoreSize() {
93        return 0;
94      }
95  
96      @Override
97      public long getStoreFileSize() {
98        return 0;
99      }
100 
101     @Override
102     public long getReadRequestCount() {
103       return 0;
104     }
105 
106     @Override
107     public long getWriteRequestCount() {
108       return 0;
109     }
110 
111     @Override
112     public long getNumFilesCompacted() {
113       return 0;
114     }
115 
116     @Override
117     public long getNumBytesCompacted() {
118       return 0;
119     }
120 
121     @Override
122     public long getNumCompactionsCompleted() {
123       return 0;
124     }
125     @Override
126     public Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics() {
127       return null;
128     }
129   }
130 }