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 org.apache.hadoop.hbase.CompatibilitySingletonFactory;
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertTrue;
26  
27  public class TestMetricsRegionSourceImpl {
28  
29    @Test
30    public void testCompareTo() throws Exception {
31      MetricsRegionServerSourceFactory fact = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
32  
33      MetricsRegionSource one = fact.createRegion(new RegionWrapperStub("TEST"));
34      MetricsRegionSource oneClone = fact.createRegion(new RegionWrapperStub("TEST"));
35      MetricsRegionSource two = fact.createRegion(new RegionWrapperStub("TWO"));
36  
37      assertEquals(0, one.compareTo(oneClone));
38  
39      assertTrue( one.compareTo(two) < 0);
40      assertTrue( two.compareTo(one) > 0);
41    }
42  
43  
44    @Test(expected = RuntimeException.class)
45    public void testNoGetRegionServerMetricsSourceImpl() throws Exception {
46      // This should throw an exception because MetricsRegionSourceImpl should only
47      // be created by a factory.
48      CompatibilitySingletonFactory.getInstance(MetricsRegionSource.class);
49    }
50  
51    static class RegionWrapperStub implements MetricsRegionWrapper {
52  
53      private String regionName;
54  
55      public RegionWrapperStub(String regionName) {
56  
57  
58        this.regionName = regionName;
59      }
60  
61      @Override
62      public String getTableName() {
63        return null;
64      }
65  
66      @Override
67      public String getNamespace() {
68        return null;
69      }
70  
71      @Override
72      public String getRegionName() {
73        return this.regionName;
74      }
75  
76      @Override
77      public long getNumStores() {
78        return 0;
79      }
80  
81      @Override
82      public long getNumStoreFiles() {
83        return 0;
84      }
85  
86      @Override
87      public long getMemstoreSize() {
88        return 0;
89      }
90  
91      @Override
92      public long getStoreFileSize() {
93        return 0;
94      }
95  
96      @Override
97      public long getReadRequestCount() {
98        return 0;
99      }
100 
101     @Override
102     public long getWriteRequestCount() {
103       return 0;
104     }
105 
106     @Override
107     public long getNumFilesCompacted() {
108       return 0;
109     }
110 
111     @Override
112     public long getNumBytesCompacted() {
113       return 0;
114     }
115 
116     @Override
117     public long getNumCompactionsCompleted() {
118       return 0;
119     }
120   }
121 }