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