1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotEquals;
24
25 import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
26 import org.apache.hadoop.hbase.testclassification.MetricsTests;
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31
32
33
34 @Category({MetricsTests.class, SmallTests.class})
35 public class TestMetricsTableSourceImpl {
36
37 @SuppressWarnings("SelfComparison")
38 @Test
39 public void testCompareToHashCode() throws Exception {
40 MetricsRegionServerSourceFactory metricsFact =
41 CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
42
43 MetricsTableSource one = metricsFact.createTable("ONETABLE", new TableWrapperStub("ONETABLE"));
44 MetricsTableSource oneClone = metricsFact.createTable("ONETABLE", new TableWrapperStub("ONETABLE"));
45 MetricsTableSource two = metricsFact.createTable("TWOTABLE", new TableWrapperStub("TWOTABLE"));
46
47 assertEquals(0, one.compareTo(oneClone));
48 assertEquals(one.hashCode(), oneClone.hashCode());
49 assertNotEquals(one, two);
50
51 assertTrue(one.compareTo(two) != 0);
52 assertTrue(two.compareTo(one) != 0);
53 assertTrue(two.compareTo(one) != one.compareTo(two));
54 assertTrue(two.compareTo(two) == 0);
55 }
56
57 @Test(expected = RuntimeException.class)
58 public void testNoGetTableMetricsSourceImpl() throws Exception {
59
60
61 CompatibilitySingletonFactory.getInstance(MetricsTableSourceImpl.class);
62 }
63
64 @Test
65 public void testGetTableMetrics() throws Exception{
66 MetricsTableSource oneTbl =
67 CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
68 .createTable("ONETABLE", new TableWrapperStub("ONETABLE"));
69 assertEquals("ONETABLE", oneTbl.getTableName());
70 }
71
72 static class TableWrapperStub implements MetricsTableWrapperAggregate {
73
74 private String tableName;
75
76 public TableWrapperStub(String tableName) {
77 this.tableName = tableName;
78 }
79
80 @Override
81 public long getReadRequestsCount(String table) {
82 return 10;
83 }
84
85 @Override
86 public long getWriteRequestsCount(String table) {
87 return 20;
88 }
89
90 @Override
91 public long getTotalRequestsCount(String table) {
92 return 30;
93 }
94
95 @Override
96 public long getMemstoresSize(String table) {
97 return 1000;
98 }
99
100 @Override
101 public long getStoreFilesSize(String table) {
102 return 2000;
103 }
104
105 @Override
106 public long getTableSize(String table) {
107 return 3000;
108 }
109
110 @Override
111 public long getNumRegions(String table) {
112 return 3;
113 }
114
115 @Override
116 public long getAvgRegionSize(String table) {
117 return 3000;
118 }
119
120 public String getTableName() {
121 return tableName;
122 }
123 }
124 }