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 @Test
38 public void testCompareToHashCode() throws Exception {
39 MetricsRegionServerSourceFactory metricsFact =
40 CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
41
42 MetricsTableSource one = metricsFact.createTable("ONETABLE", new TableWrapperStub("ONETABLE"));
43 MetricsTableSource oneClone = metricsFact.createTable("ONETABLE", new TableWrapperStub("ONETABLE"));
44 MetricsTableSource two = metricsFact.createTable("TWOTABLE", new TableWrapperStub("TWOTABLE"));
45
46 assertEquals(0, one.compareTo(oneClone));
47 assertEquals(one.hashCode(), oneClone.hashCode());
48 assertNotEquals(one, two);
49
50 assertTrue(one.compareTo(two) != 0);
51 assertTrue(two.compareTo(one) != 0);
52 assertTrue(two.compareTo(one) != one.compareTo(two));
53 assertTrue(two.compareTo(two) == 0);
54 }
55
56 @Test(expected = RuntimeException.class)
57 public void testNoGetTableMetricsSourceImpl() throws Exception {
58
59
60 CompatibilitySingletonFactory.getInstance(MetricsTableSourceImpl.class);
61 }
62
63 @Test
64 public void testGetTableMetrics() throws Exception{
65 MetricsTableSource oneTbl =
66 CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
67 .createTable("ONETABLE", new TableWrapperStub("ONETABLE"));
68 assertEquals("ONETABLE", oneTbl.getTableName());
69 }
70
71 static class TableWrapperStub implements MetricsTableWrapperAggregate {
72
73 private String tableName;
74
75 public TableWrapperStub(String tableName) {
76 this.tableName = tableName;
77 }
78
79 @Override
80 public long getReadRequestsCount(String table) {
81 return 10;
82 }
83
84 @Override
85 public long getWriteRequestsCount(String table) {
86 return 20;
87 }
88
89 @Override
90 public long getTotalRequestsCount(String table) {
91 return 30;
92 }
93
94 @Override
95 public long getMemstoresSize(String table) {
96 return 1000;
97 }
98
99 @Override
100 public long getStoreFilesSize(String table) {
101 return 2000;
102 }
103
104 @Override
105 public long getTableSize(String table) {
106 return 3000;
107 }
108
109 public String getTableName() {
110 return tableName;
111 }
112 }
113 }