1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.metrics;
20
21 import org.apache.hadoop.hbase.testclassification.SmallTests;
22 import org.apache.hadoop.hbase.testclassification.MetricsTests;
23
24 import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
25 import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28 import org.junit.experimental.categories.Category;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNull;
32 import static org.junit.Assert.assertSame;
33
34
35
36
37 @Category({MetricsTests.class, SmallTests.class})
38 public class TestBaseSourceImpl {
39
40 private static BaseSourceImpl bmsi;
41
42 @BeforeClass
43 public static void setUp() throws Exception {
44 bmsi = new BaseSourceImpl("TestName", "test description", "testcontext", "TestContext");
45 }
46
47 @Test
48 public void testSetGauge() throws Exception {
49 String key = "testset";
50 bmsi.setGauge(key, 100);
51 MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
52 assertEquals(key, g.name);
53 bmsi.setGauge(key, 110);
54 assertSame(g, bmsi.metricsRegistry.get(key));
55
56 }
57
58 @Test
59 public void testIncGauge() throws Exception {
60 String key = "testincgauge";
61 bmsi.incGauge(key, 100);
62 MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
63 assertEquals(key, g.name);
64 bmsi.incGauge(key, 10);
65 assertSame(g, bmsi.metricsRegistry.get(key));
66 }
67
68 @Test
69 public void testDecGauge() throws Exception {
70 String key = "testdec";
71 bmsi.decGauge(key, 100);
72 MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
73 assertEquals(key, g.name);
74 bmsi.decGauge(key, 100);
75 assertSame(g, bmsi.metricsRegistry.get(key));
76 }
77
78 @Test
79 public void testIncCounters() throws Exception {
80 String key = "testinccounter";
81 bmsi.incCounters(key, 100);
82 MetricMutableCounterLong c = (MetricMutableCounterLong) bmsi.metricsRegistry.get(key);
83 assertEquals(key, c.name);
84 bmsi.incCounters(key, 100);
85 assertSame(c, bmsi.metricsRegistry.get(key));
86 }
87
88 @Test
89 public void testRemoveMetric() throws Exception {
90 bmsi.setGauge("testrm", 100);
91 bmsi.removeMetric("testrm");
92 assertNull(bmsi.metricsRegistry.get("testrm"));
93
94 }
95
96 }