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    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;  //To change body of implemented methods use File | Settings | File Templates.
64      }
65  
66      @Override
67      public String getRegionName() {
68        return this.regionName;
69      }
70  
71      @Override
72      public long getNumStores() {
73        return 0;  //To change body of implemented methods use File | Settings | File Templates.
74      }
75  
76      @Override
77      public long getNumStoreFiles() {
78        return 0;  //To change body of implemented methods use File | Settings | File Templates.
79      }
80  
81      @Override
82      public long getMemstoreSize() {
83        return 0;  //To change body of implemented methods use File | Settings | File Templates.
84      }
85  
86      @Override
87      public long getStoreFileSize() {
88        return 0;  //To change body of implemented methods use File | Settings | File Templates.
89      }
90  
91      @Override
92      public long getReadRequestCount() {
93        return 0;  //To change body of implemented methods use File | Settings | File Templates.
94      }
95  
96      @Override
97      public long getWriteRequestCount() {
98        return 0;  //To change body of implemented methods use File | Settings | File Templates.
99      }
100   }
101 }