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      assertTrue( two.compareTo(one) != one.compareTo(two));
48      assertTrue( two.compareTo(two) == 0);
49    }
50  
51  
52    @Test(expected = RuntimeException.class)
53    public void testNoGetRegionServerMetricsSourceImpl() throws Exception {
54      // This should throw an exception because MetricsRegionSourceImpl should only
55      // be created by a factory.
56      CompatibilitySingletonFactory.getInstance(MetricsRegionSource.class);
57    }
58  
59    static class RegionWrapperStub implements MetricsRegionWrapper {
60  
61      private String regionName;
62  
63      public RegionWrapperStub(String regionName) {
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 getMaxStoreFileAge() {
109       return 0;
110     }
111 
112     @Override
113     public long getMinStoreFileAge() {
114       return 0;
115     }
116 
117     @Override
118     public long getAvgStoreFileAge() {
119       return 0;
120     }
121 
122     @Override
123     public long getNumReferenceFiles() {
124       return 0;
125     }
126 
127     @Override
128     public long getWriteRequestCount() {
129       return 0;
130     }
131 
132     @Override
133     public long getNumFilesCompacted() {
134       return 0;
135     }
136 
137     @Override
138     public long getNumBytesCompacted() {
139       return 0;
140     }
141 
142     @Override
143     public long getNumCompactionsCompleted() {
144       return 0;
145     }
146 
147     @Override
148     public int getRegionHashCode() {
149       return regionName.hashCode();
150     }
151 
152     /**
153      * Always return 0 for testing
154      */
155     @Override
156     public int getReplicaId() {
157       return 0;
158     }
159 
160     @Override
161     public long getTotalRequestCount() {
162       return 0;
163     }
164   }
165 }