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.Map;
22  
23  import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
24  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
25  import org.apache.hadoop.hbase.testclassification.SmallTests;
26  import org.apache.hadoop.hbase.testclassification.MetricsTests;
27  import org.junit.Test;
28  import org.junit.experimental.categories.Category;
29  
30  import static org.junit.Assert.assertEquals;
31  import static org.junit.Assert.assertTrue;
32  
33  @Category({MetricsTests.class, SmallTests.class})
34  public class TestMetricsRegionSourceImpl {
35  
36    @Test
37    public void testCompareTo() throws Exception {
38      MetricsRegionServerSourceFactory fact = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
39  
40      MetricsRegionSource one = fact.createRegion(new RegionWrapperStub("TEST"));
41      MetricsRegionSource oneClone = fact.createRegion(new RegionWrapperStub("TEST"));
42      MetricsRegionSource two = fact.createRegion(new RegionWrapperStub("TWO"));
43  
44      assertEquals(0, one.compareTo(oneClone));
45  
46      assertTrue( one.compareTo(two) < 0);
47      assertTrue( two.compareTo(one) > 0);
48    }
49  
50  
51    @Test(expected = RuntimeException.class)
52    public void testNoGetRegionServerMetricsSourceImpl() throws Exception {
53      // This should throw an exception because MetricsRegionSourceImpl should only
54      // be created by a factory.
55      CompatibilitySingletonFactory.getInstance(MetricsRegionSource.class);
56    }
57  
58    static class RegionWrapperStub implements MetricsRegionWrapper {
59  
60      private String regionName;
61  
62      public RegionWrapperStub(String regionName) {
63  
64  
65        this.regionName = regionName;
66      }
67  
68      @Override
69      public String getTableName() {
70        return null;
71      }
72  
73      @Override
74      public String getNamespace() {
75        return null;
76      }
77  
78      @Override
79      public String getRegionName() {
80        return this.regionName;
81      }
82  
83      @Override
84      public long getNumStores() {
85        return 0;
86      }
87  
88      @Override
89      public long getNumStoreFiles() {
90        return 0;
91      }
92  
93      @Override
94      public long getMemstoreSize() {
95        return 0;
96      }
97  
98      @Override
99      public long getStoreFileSize() {
100       return 0;
101     }
102 
103     @Override
104     public long getMaxStoreFileAge() {
105       return 0;
106     }
107 
108     @Override
109     public long getMinStoreFileAge() {
110       return 0;
111     }
112 
113     @Override
114     public long getAvgStoreFileAge() {
115       return 0;
116     }
117 
118     @Override
119     public long getNumReferenceFiles() {
120       return 0;
121     }
122 
123     @Override
124     public long getReadRequestCount() {
125       return 0;
126     }
127 
128     @Override
129     public long getWriteRequestCount() {
130       return 0;
131     }
132 
133     @Override
134     public long getNumFilesCompacted() {
135       return 0;
136     }
137 
138     @Override
139     public long getNumBytesCompacted() {
140       return 0;
141     }
142 
143     @Override
144     public long getNumCompactionsCompleted() {
145       return 0;
146     }
147     @Override
148     public Map<String, DescriptiveStatistics> getCoprocessorExecutionStatistics() {
149       return null;
150     }
151   }
152 }