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