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