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 static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotEquals;
23  import static org.junit.Assert.assertTrue;
24  
25  import java.util.Map;
26  
27  import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
28  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
29  import org.apache.hadoop.hbase.testclassification.SmallTests;
30  import org.apache.hadoop.hbase.testclassification.MetricsTests;
31  import org.junit.Test;
32  import org.junit.experimental.categories.Category;
33  
34  @Category({MetricsTests.class, SmallTests.class})
35  public class TestMetricsRegionSourceImpl {
36  
37    @SuppressWarnings("SelfComparison")
38    @Test
39    public void testCompareToHashCodeEquals() throws Exception {
40      MetricsRegionServerSourceFactory fact = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
41  
42      MetricsRegionSource one = fact.createRegion(new RegionWrapperStub("TEST"));
43      MetricsRegionSource oneClone = fact.createRegion(new RegionWrapperStub("TEST"));
44      MetricsRegionSource two = fact.createRegion(new RegionWrapperStub("TWO"));
45  
46      assertEquals(0, one.compareTo(oneClone));
47      assertEquals(one.hashCode(), oneClone.hashCode());
48      assertNotEquals(one, two);
49  
50      assertTrue( one.compareTo(two) != 0);
51      assertTrue( two.compareTo(one) != 0);
52      assertTrue( two.compareTo(one) != one.compareTo(two));
53      assertTrue( two.compareTo(two) == 0);
54    }
55  
56  
57    @Test(expected = RuntimeException.class)
58    public void testNoGetRegionServerMetricsSourceImpl() throws Exception {
59      // This should throw an exception because MetricsRegionSourceImpl should only
60      // be created by a factory.
61      CompatibilitySingletonFactory.getInstance(MetricsRegionSource.class);
62    }
63  
64    static class RegionWrapperStub implements MetricsRegionWrapper {
65  
66      private String regionName;
67  
68      public RegionWrapperStub(String regionName) {
69        this.regionName = regionName;
70      }
71  
72      @Override
73      public String getTableName() {
74        return null;
75      }
76  
77      @Override
78      public String getNamespace() {
79        return null;
80      }
81  
82      @Override
83      public String getRegionName() {
84        return this.regionName;
85      }
86  
87      @Override
88      public long getNumStores() {
89        return 0;
90      }
91  
92      @Override
93      public long getNumStoreFiles() {
94        return 0;
95      }
96  
97      @Override
98      public long getMemstoreSize() {
99        return 0;
100     }
101 
102     @Override
103     public long getStoreFileSize() {
104       return 0;
105     }
106 
107     @Override
108     public long getReadRequestCount() {
109       return 0;
110     }
111 
112     @Override
113     public long getMaxStoreFileAge() {
114       return 0;
115     }
116 
117     @Override
118     public long getMinStoreFileAge() {
119       return 0;
120     }
121 
122     @Override
123     public long getAvgStoreFileAge() {
124       return 0;
125     }
126 
127     @Override
128     public long getNumReferenceFiles() {
129       return 0;
130     }
131 
132     @Override
133     public long getWriteRequestCount() {
134       return 0;
135     }
136 
137     @Override
138     public long getNumFilesCompacted() {
139       return 0;
140     }
141 
142     @Override
143     public long getNumBytesCompacted() {
144       return 0;
145     }
146 
147     @Override
148     public long getLastMajorCompactionAge() {
149       return 0;
150     }
151 
152     @Override
153     public long getNumCompactionsCompleted() {
154       return 0;
155     }
156 
157     @Override
158     public long getNumCompactionsFailed() {
159       return 0;
160     }
161 
162     @Override
163     public int getRegionHashCode() {
164       return regionName.hashCode();
165     }
166 
167     /**
168      * Always return 0 for testing
169      */
170     @Override
171     public int getReplicaId() {
172       return 0;
173     }
174 
175     @Override
176     public long getNumCompactionsQueued() {
177       return 0;
178     }
179 
180     @Override
181     public long getNumFlushesQueued() {
182       return 0;
183     }
184 
185     @Override
186     public long getMaxCompactionQueueSize() {
187       return 0;
188     }
189 
190     @Override
191     public long getMaxFlushQueueSize() {
192       return 0;
193     }
194   }
195 }